question

Rohit Bhardwaj avatar image
Rohit Bhardwaj asked David Marginian Deactivated edited

Difference in order 'total' in our calculation and clover's orders REST API.

Hi,

We are migrating from Developer Pay V2 API to ECOM API referring to the migration guide. We were in using the hosted iFrame using all the codes provided and also we were able to charge the card using all of the process that was mentioned in the same guide.

The problem happens only when we add additional charges like to the lineItems API. The orders API does not calculate those additional charges except the items which were lined to the order id. Referring to our example, we add these additional charges as a line item to the order, Delivery fee is non taxable and Convenience fee is taxable item. XPN83AY98983Y, this is the order id which we tried doing the payment but got an error response as below;

response after payment

Array
(
[message] => 409 Conflict
[error] => Array
(
[type] => invalid_request_error
[code] => order_over_paid
[message] => Order with id XPN83AY98983Y would be over paid.
)
)

and here is the array which we are passing to https://scl-sandbox.dev.clover.com/v1/orders/$order_id/pay

$fields=array(
"amount"=>round($tot),
"tax_amount"=>round($tax),
"tip_amount"=>intval($tip*100),
"ecomind"=>"ecom",
"currency"=> "usd",
"email"=>"vishal@imerchantech.com",
"source"=> $this->input->post('cloverToken')
);

Where cloverToken refers to the token which is returned by providing card data. If you check the order using order id given above, you get order total as $23.98 which is the total amount after adding two line items but the additional charges that we add should calculate the total to $27.98. If I open the same order using Orders app then the total changes an we can make a payment but the transaction is always less paid or Partially Paid.

Please help!

Orderse-commerce api
10 |2000

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

1 Answer

David Marginian avatar image
David Marginian Deactivated answered David Marginian Deactivated edited

You are making a request to set the total to 23.98, then you add additional line items and never update the total to reflect the new line items:

RequestLog{reqBody={"title":"","state":"open","note":"order_from web&open","total":2398,"orderType":{"id":"redacted"}}, rspBody={"id":"XP.......3Y","currency":"USD","total":2398,"title":"","note":"order_from web&open","orderType":{"id":"redacted"},"taxRemoved":false,"isVat":false,"state":"open","manualTransaction":false,"groupLineItems":true,"testMode":false,"createdTime":1620898796000,"clientCreatedTime":1620898796000,"modifiedTime":1620898795000}

You have 2 options:

1) Properly calculate and set the order total - https://docs.clover.com/docs/calculating-order-totals

2) Don't set the order total, the EComm pay endpoint will calculate and set it for you if you don't set it yourself.

10 |2000

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