question

John Turnipseed avatar image
John Turnipseed asked John Turnipseed edited

PaymentConnector.sale(), partial payments & incorrect sales tax reporting

When we want to process payment for an Order with using PaymentConnector.sale(), we create the initial SaleRequest using setAmount() with the value from the order's getAmount() call and setTaxAmount() using an OrderCalc's getTax() call result. (See code snippet below)

This works correctly with a full payments, but when we happen to get a partial payment, things sometimes appear to go a bit wonky with the tax information.

NOTE: This example is all being done using the special test card number that only pays 50% of whatever amount is charged.

Here is a simplified bit of code used to create a SaleRequest object for an order. On each successful response, we add the Payment object from the SaleResponse to the "completedPayments" array and call getSaleRequest() again to see if additional payment is required.

private Order order;
private List<Payment> completedPayments;

private SaleRequest getSaleRequest() {

    SaleRequest saleRequest = new SaleRequest();
    saleRequest.setOrderId(order.getId());
    saleRequest.setExternalId(ExternalIdUtils.generateNewID());
    
    OrderCalc calc = new OrderCalc(order);
    long amount = order.getTotal();
    long taxAmount = calc.getTax();

    for (Payment payment : completedPayments) {
        amount -= payment.getAmount();
        taxAmount -= payment.getTaxAmount();
    }

    if (amount <= 0) {
        return null; // fully paid, no further payments necessary
    }

    saleRequest.setAmount(amount);
    saleRequest.setTaxAmount(taxAmount);
    return saleRequest;
}

The above logic seems to work... most of the time.

Typically with the partial payment test card number, calling getTaxAmount() on the Payment object we get back from SaleResponse.getPayment() will return approximately 50% of the tax that was specified in the SaleRequest for that payment. However, sometimes that getTaxAmount() call appears to actually return 100% of the tax amount from the SaleRequest, even tough the order is not yet fully paid.

Order ID: WYCYYM9JT3ENC total: 1519  taxAmount: 129
SaleRequest: Amount: 1519  TaxAmount: 129
Payment: ID: WW84484SQCDFP amount: 759 taxAmount: 129
SaleRequest: Amount: 760  TaxAmount: 0
Payment: ID: AFXDSW97ZAD9C amount: 760 taxAmount: 0

At first glance, I wouldn't think this would be a problem. As long as the full tax amount was recognized as having been collected in some combination of payments, it shouldn't matter which payment/payments it was actually taken from... the problem is that it's not be recognized as fully collected.

When I look up the first Payment in the Clover web portal, it shows only 50% of the total tax, even though the Payment object my app got back reported the full amount as being paid. Further, the subsequent partial payments each show $0.00 for Tax & Fees Collected (this part is expected since we set them to zero).

Web Portal Transactions:
Payment: ID: WW84484SQCDFP Amount: $7.59 Tax or Fees Collected: $0.64
Payment: ID: AFXDSW97ZAD9C Amount: $7.60 Tax or Fees Collected: $0.00

It appears that the Taxes report is incorrect as well, as it is also short $0.65 that was collected.

So, my question is, what are we doing wrong, or what should we be doing differently, in our calculations for the additional payments? Is there some other way to know what value TaxAmount should be set to on each SaleRequest throughout this process?

Thanks

PaymentConnectorSaleTaxes
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community