[ http://issues.apache.org/jira/browse/OFBIZ-93?page=all ]
Si Chen updated OFBIZ-93:
-------------------------
Attachment: ofbiz-93.patch
Ok. I've worked through this and fixed BillingAccount so that it could be
split with another payment method on orders and invoices. I'm posting a patch
of what I did so everybody could look through it, as some of these are pretty
fundamental changes. While I feel that they are justified, it'd be nice to get
your opinion on this.
Here's a brief rundown of what has been done:
1. There are now two calculations of billing account balance. I've created a
new "net balance" method which just includes the amounts of settled invoices
and payments. The old "getBillingAccountBalance" method returns net balance
minus the amount of outstanding orders. The reason I did this is so that we
can track what has actually been charged ("net balance") versus what can be
used for future orders (the old balance method.) This is analogous to a
different balance for the "capture" and the "authorize" services for a credit
card.
2. The balance of a billing account is now calculated as exclusively based on
the amountApplied field of PaymentApplication. I am no longer going back to
Invoice to get the total unapplied amount of invoices, because there is no way
to record explicitly how much was applied to a BillingAccount vs another
payment method that way. The net balance of a billing account is the sum of
all PaymentApplications with an invoiceId (which increase the billing account
balance) minus the sum of all PaymentApplications without an invoiceId (which
decrease the billing account balance.) This is similar to how it was done
before.
3. In captureOrderPayments, I've changed the code to check the amount of
capture against the billing account net balance and run the minimum of billing
account net balance and capture amount to the billing account first. The
remaining is run on the credit card. Re-authorization is also changed to
consider how much was charged to billing account, to avoid reauthorizing that
amount.
4. In createPaymentApplication, I removed code which automatically put
Invoice.billingAccountId to PaymentApplication.billingAccountId because that
would have messed up billing account balance calculation per (2). Also there
was a minilang compare which had to be typecast to Double.
Please take a look and let me know if you have any feedback. This seems to
work for me after some reasonable amount of testing.
> Support BillingAcct + PaymentMethod for Payment
> -----------------------------------------------
>
> Key: OFBIZ-93
> URL: http://issues.apache.org/jira/browse/OFBIZ-93
> Project: OFBiz (The Open for Business Project)
> Issue Type: Improvement
> Components: accounting
> Reporter: Si Chen
> Attachments: ofbiz-93.patch
>
>
> The requirement is that a customer be able to use a billing account plus
> another form of payment, such as a credit card, for payment on an order. The
> billing account is to be used first.
> This would require the following changes:
> 1. In PaymentGatewayServices.java captureOrderPayments method, if the
> billing account has a positive balance, then first create a Payment of the
> EXT_BILL_ACT type, then a PaymentApplication of amountApplied = min(billing
> account balance, amount to capture.) This PaymentApplication MUST have an
> invoiceId which is already supplied as a parameter of the service.
> (Otherwise, the billing account balance will go down by the
> PaymentApplication.amountApplied) If there is an amount left over to
> capture, then amountToCapture = amountToCapture - billingAccountBalance. We
> can then loop through the OrderPaymentPreference to try to capture the
> remaining amount.
> 2. In BillingAccountWorker.getBillingAccountBalance, we need to replace
> current code which just loops through all invoices which are not PAID or
> CANCELLED and adds up their unpaid balances with new code which would find
> all PaymentApplication for which there is a billingAccountId and add up the
> amountApplied. This must be done because otherwise, once an invoice has been
> marked PAID, there would be no way to record that a portion of the billing
> account has been used to pay that invoice and hence permanently decrease its
> amount.
> On the mailing list we had discussed making the order of payment capture
> configurable. I can't think of an easy way to do this, however, with the
> current data model. I propose that for now we have PaymentGatewayServices
> basically capture billing account first, then other payment methods, which is
> a standard B2C process. If you have a B2B customer who wants to pay with a
> credit card, then use the accounting module to record a Credit Card payment
> and apply it to the Billing Account to bring down its balance.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira