Credit/Refund

358 views
Skip to first unread message

Mouhammed Soueidane

unread,
Apr 2, 2014, 4:41:02 PM4/2/14
to killbill...@googlegroups.com
Hello guys,
I have the following scenarios that I'm trying to solve with Kill-Bill.

I need to have the ability to "credit" a customer/account in killbill and apply funds or part thereof to an invoice.

Scenario 1:  Customer sends us a cheque  payment for x quantity of outstanding invoices, and they either underpay or overpay.  The pending credit or balancing owing needs to be considered in the killbill system so that a followup payment can be made to reconcile, or any credit can be applied to a future invoice.

Scenario 2:  Customer negotiates with us a settlement (In the event whereby he/she is closing his/her business) and we fake-credit / write off a partial balance owing and receive a payment for the rest to settle the account.


How do I deal with both scenarios in Kill-Bill?

Thanks =)

Pierre-Alexandre Meyer

unread,
Apr 2, 2014, 4:52:31 PM4/2/14
to Mouhammed Soueidane, killbill...@googlegroups.com
On Wed, Apr 2, 2014 at 4:41 PM, Mouhammed Soueidane <m.sou...@gmail.com> wrote:

Scenario 1:  Customer sends us a cheque  payment for x quantity of outstanding invoices, and they either underpay or overpay.  The pending credit or balancing owing needs to be considered in the killbill system so that a followup payment can be made to reconcile, or any credit can be applied to a future invoice.

If they underpay, there is nothing to do on your end. Kill Bill will see the invoice with a positive balance and start the overdue process (if configured).

If they overpay, when you receive the check, you can create an external payment of the invoice amount and separately create a credit to the account of the difference. Kaui has already support for this as well as the Java client (check createPayment and createCredit calls).

Scenario 2:  Customer negotiates with us a settlement (In the event whereby he/she is closing his/her business) and we fake-credit / write off a partial balance owing and receive a payment for the rest to settle the account.


You can either create such a fake credit with the API (createCredit call) or instead adjust the invoice (adjustInvoiceItem call), just before recording the payment for the remainder.

--
Pierre

Mouhammed Soueidane

unread,
Apr 3, 2014, 5:52:37 PM4/3/14
to killbill...@googlegroups.com, Mouhammed Soueidane
I understood/tested the first part, which is creating an external payment (Using the createPayment method with the isExternal flag set to true.
But concerning crediting, I wrote the following code:

Account account = client.getAccount("msoueidane");

Credit credit = new Credit();
credit.setAccountId(account.getAccountId());
credit.setCreditAmount(new BigDecimal(50));
client.createCredit(credit, "admin", "", "");

account = client.getAccount("msoueidane");
System.out.println("Account balance is now: "+account.getAccountBalance());

The above code runs without any problem, but what I did not get is that "account.getAccountBalance()" always has the value "null".

I expected an account balance to be = Total invoices balances - Total Credits.

Could you please clarify this one for me?

Pierre-Alexandre Meyer

unread,
Apr 4, 2014, 7:56:19 AM4/4/14
to Mouhammed Soueidane, killbill...@googlegroups.com
On Thu, Apr 3, 2014 at 5:52 PM, Mouhammed Soueidane <m.sou...@gmail.com> wrote:
account = client.getAccount("msoueidane");
System.out.println("Account balance is now: "+account.getAccountBalance());

The above code runs without any problem, but what I did not get is that "account.getAccountBalance()" always has the value "null".

For performance reasons, getAccount("msoueidane") will not compute the balance. Try getAccount("msoueidane", true, true) to get the balance and CBA fields populated.

--
Pierre

Mouhammed Soueidane

unread,
Apr 4, 2014, 8:16:27 AM4/4/14
to killbill...@googlegroups.com, Mouhammed Soueidane
Oh I understand. Thanks for the help Pierre.

I tried the createPayment from the Java client, and I have concluded that a payment is always done against a particular invoice. Is there any way that I can create payments but at the account level?
For instance a customer would have 10 invoices with a positive balance, and he/she sends us a cheque. It would be tiresome for us to do the work manually (Creating a payment for each invoice). So we expect kill-bill to allow us to create a payment at the account level, and it'll automatically close invoices for us.

Pierre-Alexandre Meyer

unread,
Apr 4, 2014, 8:32:54 AM4/4/14
to Mouhammed Soueidane, killbill...@googlegroups.com
On Fri, Apr 4, 2014 at 8:16 AM, Mouhammed Soueidane <m.sou...@gmail.com> wrote:
I tried the createPayment from the Java client, and I have concluded that a payment is always done against a particular invoice. Is there any way that I can create payments but at the account level?

Check the payAllInvoices call, which works at the account level.

--
Pierre

Mouhammed Soueidane

unread,
Apr 4, 2014, 12:55:25 PM4/4/14
to killbill...@googlegroups.com, Mouhammed Soueidane
I checked the method before. The problem with it is that it doesn't take an amount. It ends up getting an account's balance down to zero. 
The thing is, the functionality we're after is as follows:
1- 3 invoices are issued for a customer with a positive balance. (invoice 1: $100, invoice 2: $150, invoice 3: $220) 
2- We receive a cheque with an amount that's less than the account's balance.
3- We would like to call a method with the amount, and expect it to work as follows:
     The sum in the cheque is $300, so the method would randomly iterate over the invoices, subtracting the invoice's balance (Invoice 1 would now have a balance of 0, Invoice 2           would now have a balance of 0, and invoice 3 would have a balance of $170)

I think that this model is quite common in businesses that accept cheques. Would it be possible for this feature to be included in a later release of Kill-Bill?

Pierre-Alexandre Meyer

unread,
Apr 4, 2014, 3:37:08 PM4/4/14
to Mouhammed Soueidane, killbill...@googlegroups.com
On Fri, Apr 4, 2014 at 12:55 PM, Mouhammed Soueidane <m.sou...@gmail.com> wrote:
The thing is, the functionality we're after is as follows:
1- 3 invoices are issued for a customer with a positive balance. (invoice 1: $100, invoice 2: $150, invoice 3: $220) 
2- We receive a cheque with an amount that's less than the account's balance.
3- We would like to call a method with the amount, and expect it to work as follows:
     The sum in the cheque is $300, so the method would randomly iterate over the invoices, subtracting the invoice's balance (Invoice 1 would now have a balance of 0, Invoice 2           would now have a balance of 0, and invoice 3 would have a balance of $170)

To support that use-case, you could probably use createPayment against the first invoice, specify the payment amount of $300 and Kill Bill would use the remaining money to pay against the other invoices.

Let me know if it works/solves your use-case.

--
Pierre

Mouhammed Soueidane

unread,
Apr 6, 2014, 12:19:24 PM4/6/14
to killbill...@googlegroups.com, Mouhammed Soueidane
Pierre, I tried what you have suggested and it did not work. I created two invoices with a balance = 70 USD each. I then tried to create a payment for the first one with an amount equal to 120 USD (Expecting one invoice to be closed, and the other to still have 20 USD in its balance), but the following exception was thrown:
com.ning.billing.client.KillBillClientException: Payment amount requested for invoice c4754067-bd73-4f2a-87d7-31c0573e6031 is greater than invoice balance [120.000000/70.000000]
at com.ning.billing.client.KillBillHttpClient.executeAndWait(KillBillHttpClient.java:378)
at com.ning.billing.client.KillBillHttpClient.doPrepareRequestAndMaybeFollowLocation(KillBillHttpClient.java:318)
at com.ning.billing.client.KillBillHttpClient.doPostAndMaybeFollowLocation(KillBillHttpClient.java:138)
at com.ning.billing.client.KillBillHttpClient.doPostAndFollowLocation(KillBillHttpClient.java:133)
at com.ning.billing.client.KillBillHttpClient.doPostAndFollowLocation(KillBillHttpClient.java:125)
at com.ning.billing.client.KillBillHttpClient.doPostAndFollowLocation(KillBillHttpClient.java:121)
at com.ning.billing.client.KillBillClient.createPayment(KillBillClient.java:680) 

Can we request this feature to be added in a future release of Kill-Bill? If you don't see it happening please let us know so we could build a layer on top of Kill-Bill to do this work for us. We just need to know if this is work to be done on your end before developing our own logic.

Thanks Pierre.

Mouhammed Soueidane

unread,
Apr 6, 2014, 1:59:09 PM4/6/14
to killbill...@googlegroups.com, Mouhammed Soueidane
I ended up creating the following method:

public static BigDecimal makeAccountPayment(String userName, BigDecimal amount)
{

try
{
Account account = client.getAccount(userName);
List<Invoice> invoices = client.getInvoicesForAccount(account.getAccountId(), false);
for (Invoice invoice : invoices)
{
if (invoice.getBalance().compareTo(BigDecimal.ZERO) > 0)
{
if (amount.compareTo(invoice.getBalance()) <= 0)
{
Payment payment = new Payment();
payment.setInvoiceId(invoice.getInvoiceId());
payment.setAmount(amount);
payment.setAccountId(account.getAccountId());
payment.setCurrency(account.getCurrency());

client.createPayment(payment, true, "admin", "", "");
amount = amount.subtract(amount);
break;
} else
if (amount.compareTo(invoice.getBalance()) > 0)
{
Payment payment = new Payment();
payment.setInvoiceId(invoice.getInvoiceId());
payment.setAmount(invoice.getBalance());
payment.setAccountId(account.getAccountId());
payment.setCurrency(account.getCurrency());

client.createPayment(payment, true, "admin", "", "");

amount = amount.subtract(invoice.getBalance());
}

}
}

}

catch (KillBillClientException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return amount;
}

If the returned amount is greater than 0, I end up adding the remaining amount as credits for the account. This is the business that I was hoping that Kill-Bill would be able to do on my behalf.

On Friday, 4 April 2014 22:37:08 UTC+3, Pierre-Alexandre Meyer wrote:

Pierre-Alexandre Meyer

unread,
Apr 6, 2014, 2:59:27 PM4/6/14
to Mouhammed Soueidane, killbill...@googlegroups.com
On Sun, Apr 6, 2014 at 12:19 PM, Mouhammed Soueidane <m.sou...@gmail.com> wrote:
Pierre, I tried what you have suggested and it did not work. I created two invoices with a balance = 70 USD each. I then tried to create a payment for the first one with an amount equal to 120 USD (Expecting one invoice to be closed, and the other to still have 20 USD in its balance), but the following exception was thrown:
com.ning.billing.client.KillBillClientException: Payment amount requested for invoice c4754067-bd73-4f2a-87d7-31c0573e6031 is greater than invoice balance [120.000000/70.000000]

Ah, my bad, I forgot we check such boundary conditions for external payments.

Can we request this feature to be added in a future release of Kill-Bill? If you don't see it happening please let us know so we could build a layer on top of Kill-Bill to do this work for us. We just need to know if this is work to be done on your end before developing our own logic.

Can you create a Github issue for that feature request (https://github.com/killbill/killbill/issues)? We need to think it through before implementing it (and update APIs and clients to support it).

For now, given your launch timeframe, I would suggest you work around it.

--
Pierre

Pierre-Alexandre Meyer

unread,
Apr 6, 2014, 3:07:52 PM4/6/14
to Mouhammed Soueidane, killbill...@googlegroups.com
On Sun, Apr 6, 2014 at 1:59 PM, Mouhammed Soueidane <m.sou...@gmail.com> wrote:
This is the business that I was hoping that Kill-Bill would be able to do on my behalf.

This is a use case we never encountered before, as opposed to the model where customers receive their monthly invoice and send a check for it (a lot of the logic Kill Bill has is to allow for alignment of subscriptions, to minimize the amount of invoices the customer has to deal with).

Agreed it's funny business on the client side. Hang on tight, we may have a better solution for you soon.

--
Pierre

stephane brossier

unread,
Apr 13, 2014, 6:25:14 PM4/13/14
to Mouhammed Soueidane, killbill...@googlegroups.com, Pierre-Alexandre Meyer
Mouhammed,

I added a new query parameter to the interface payAllInvoices (POST /1.0/kb/accounts/{accountId}/payments). The additional query parameter is called 'paymentAmount', and it allows to specify a payment amount against all unpaid invoices:
* If amount is not specified -- equivalent to current code-- Kill Bill will attempt to make a payment against all unpaid invoice
* If amount is specified but less than total invoice balances, then  Kill Bill pay up to that amount, starting from older invoices, and potentially making a partial payment, and/or leaving some invoices unpaid
* If amount is specified and is greater than total invoice balances, then  Kill Bill pay all unpaid invoices, and also potentially adds a credit on that account for the remaining piece. Note that the credit will only be applied in case of external payments (e.g checks).


Note that the change has been made in the latest version of Kill Bill (0.10.x), so the easiest would be to upgrade to latest released version. There has been a small changes for the SQL schema, and also a change in the xml of the catalog. We can provide some assistance on how to deal with that if you are interested to upgrade to 0.10.x.

Let us know if that helps,

Stéphane



--
You received this message because you are subscribed to the Google Groups "Kill Bill users mailing-list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to killbilling-us...@googlegroups.com.
To post to this group, send email to killbill...@googlegroups.com.
Visit this group at http://groups.google.com/group/killbilling-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/killbilling-users/CAKXgekqM16YNtEcaUC__eBy5-LOFcTiLZp8g6e81RZzidm2b-Q%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Mouhammed Soueidane

unread,
Apr 15, 2014, 2:50:42 PM4/15/14
to killbill...@googlegroups.com, Mouhammed Soueidane, Pierre-Alexandre Meyer
Thanks for providing the feature that we requested Stephane, we will make sure to deploy the newest release of Kill-Bill and test the new functionality. I will let you know how that goes.
Reply all
Reply to author
Forward
0 new messages