Billing Accounts

From Opentaps Wiki
Revision as of 16:21, 5 December 2007 by Sichen (talk | contribs) (Using Billing Account)
Jump to navigationJump to search

IMPORTANT: Billing accounts were originally developed in the ofbiz framework. There are currently several problems with them: billing accounts do not have an explicit transactions or authorization records, it is not possible to transact in multiple currencies with a billing account, and only one billing account can be used per order. Therefore, they are maintained at this point for backward compatibility only. We would recommend that you use the Credit Limits feature for accounts receivable and gift cards for store credits. The following information is provided for those who need to work with legacy billing accounts from earlier versions of opentaps.

A billing account can be used to give customers credit so that they can make purchases from you and pay later. A billing account can also be used to track store credits, such as those given to customers for returned orders. Note that it is possible to track customer balances without a billing account, so it is not necessary to set up billing accounts for accounts receivables to work correctly.

A billing account has an accountLimit and can be associated with orders via OrderHeader and invoices and payments via PaymentApplication. The account limit field controls the maximum which can be charged to the billing account and is equivalent to a credit limit for this account. Payments (Invoices) which are associated to billing account via PaymentApplication increase (decrease) the amount which can be charged to the account and decrease (increase) the customer’s outstanding balance on the account.

If a billing account is in the OrderHeader, then it will be the first payment method which will be used to pay for the order. The captureOrderPayments service will try to exhaust the billing account first before using the other order payment methods.

Billing accounts have from and thru dates which control when they are valid. For a billing account to be effective for a customer, the customer needs to be part of BillingAccountRole with role “Bill To Customer”.

There are three balances for billing accounts:

  • Net balance is the sum of all invoices minus the sum of all payments is the amount of the customer’s outstandin balance.
  • “Billing account balance” is net balance minus the total of all outstanding (not completed or canceled) orders for which billing account is limited as a payment method.
  • Available balance is account limit minus billing account balance.

For example, imagined if you had a credit card with a limit of $1,000. You have a revolving balance of $500, and you just used it on a $200 purchase which the merchant has authorized against your card but not charged yet. In that case, your account has an "account limit" of $1,000, a net balance of $500, a billing account balance of $700, and an available balance of $300.

Using Billing Account

  1. orderHeader entity has a billingAccountId field and it is linked to the BillingAccount entity. use orderHeader.getRelatedOne("BillingAccount") to get the billing account for the order.
  2. billsettings.ftl (or its equivalent): take input parameters of checkOutPaymentId = 'EXT_BILLACT' and billingAccountId = '10000'
  3. billingAccount for an order is set with the org.ofbiz.order.shoppingcart.Shoppingcart.setBillingAccount method, setting it to the shopping cart. The billing account is set before the final review and the createOrder methods are called to create the order. there is also a matching ShoppingCart.getBillingAccountId method.
  4. the setBillingAccount org.ofbiz.order.shoppingcart.CheckOutEvents: setCheckOutOptions and setCheckOutPages - these two methods use the request.getParameter("billingAccountId") to set the billing account. They should then somehow call a CheckOutHelper method which calls a setCheckOutPaymentInternal method to set the billing account.
  5. order manager however is using finalizeOrderEntry which does not process the billingAccountId parameter.

How Billing Account Balances are Calculated

  1. BillingAccountWorker.getBillingAccountBalance is used to figure out the amount that can be charged to a billing account.
  2. It is currently doing this calculation:

BillingAccount limit: $10,000 minus All incomplete orders (Not COMPLETED or CANCELED): $334.58 minus All invoices which are unpaid: $60.83 plus Any payments applied to invoices (none in this example) For balance of $9,604.59, which is what the ecommerce application shows.

To “Charge” More to a Billing Account

Create an Invoice to your customer, then create a Payment from your customer, then apply the amount to be charged in one PaymentApplication (under Applications tab) with both invoiceId and billingAccountId. This will cause the invoice to be paid with the billing account and increase its outstanding balance.

To “Pay Down” a Billing Account

Create a Payment from your customer, then create a PaymentApplication (under Applications tab) for the amount with the billingAccountId. This will cause the billing account's outstanding balance to decrease.