Support

Home Forums Event Espresso Premium "The payment total does not match the order total" started appearing

"The payment total does not match the order total" started appearing

Posted: February 8, 2022 at 1:51 pm

Viewing 5 reply threads


careertraining

February 8, 2022 at 1:51 pm

While developing a plugin to add a transaction surcharge, I ran hundreds of successful payments, in live and debug mode.
A day or two after activating it in production, the error “The payment total does not match the order total” has begun appearing.

I’m still able to process transactions of $1, $2, and $3, but anything higher gives me the error.

Previously, I had no trouble with transactions of up to more than $1000. I’ve reconnected the square-onsite gateway several times. What could be happening? rounding error?


careertraining

February 8, 2022 at 4:32 pm

Digging around a bit, I noticed that the error string isn’t even in EE or the square gateway plugins. That’s from Square’s API!

Looking at the requests from the WP server to the square API I see the following which take place on clicking “Pay”:

URL Status
https://connect.squareupsandbox.com/v2/orders/calculate 200
https://connect.squareupsandbox.com/v2/orders/ 200
https://connect.squareupsandbox.com/v2/payments 400

The first two contain the base price of the event
\”base_price_money\”:{\”amount\”:129900,\”currency\”:\”USD\”}

The third contains
\”amount_money\”:{\”amount\”:133797,\”currency\”:\”USD\”}
and responds as status 400 with
{\”code\”: \”BAD_REQUEST\”,\”detail\”: \”The payment total does not match the order total.\”,\”category\”: \”INVALID_REQUEST_ERROR\”}

I appreciate your help!


Tony

  • Support Staff

February 9, 2022 at 6:50 am

Hi there,

So, in short, the problem is you have an order created within Square and then you are creating a payment for that order with a value that does not match the order total Square are rejecting it.

Why this worked for you previously I can’t say as it’s on the Square API rather than within EE but afaik your payment amount must match the order total or Square will error out.

Are you creating a NEW registration when testing this or revisiting checkout?

The reason I ask is once a payment has been initialised and an order created in Square, the order id is then saved within the EE_Transaction’s metadata, the next time you attempt a payment it pulls in the order_id and uses that.


careertraining

February 9, 2022 at 5:16 pm

I’ve tested multiple new & revisited checkouts.

The surcharge is added on AHEE__Single_Page_Checkout__before_payment_options__switch_payment_method

Upon arriving at checkout, the TXN_total in the DB is the base amount, and after switching to squareonsite, TXN_total is updated with the surcharge.

I think I’ve found the issue in the function below. My surcharge is percentage based, and this function is pulling out the price $eventItem->unit_price(), but my line item object only has a total set.

private function addRemainingLineItems(array $eventLineItems, string $currency)
    {
        foreach ($eventLineItems as $eventItem) {
            if ($eventItem instanceof EE_Line_Item && $eventItem->OBJ_type() !== 'Promotion') {
                $itemMoney     = $this->gateway->convertToSubunits($eventItem->unit_price());
                $orderLineItem = [
                    'uid'               => (string)$eventItem->ID(),
                    'name'              => $eventItem->name(),
                    'quantity'          => (string)$eventItem->quantity(),
                    'base_price_money'  => [
                        'amount'   => $itemMoney,
                        'currency' => $currency,
                    ],
                    'applied_discounts' => $this->order_items->discountIDs(),
                ];
                if ($eventItem->is_taxable()) {
                    $orderLineItem['applied_taxes'] = $this->order_items->taxIDs();
                }
                $this->order_items->addItem($orderLineItem);
                // Count the total to double check later.
                $this->order_items->addToTotal($eventItem->total());
                $this->order_items->incrementCount();
            }
        }
    }

I tried setting the total $total_line_item->set_unit_price($total_line_item->total() - $amount_owing_before); but got an error “A Line Item can not have a unit price of (74.97) AND a percent (3)!”

If I’m not supposed to have the unit_price set, then it looks like the bug is in the above function not being compatible with percentage-based line items.


Tony

  • Support Staff

February 16, 2022 at 5:07 am

I opened up a discussion on this with one of our developers:

The reason it doesn’t support percentage line items is the Square API doesn’t accept percentages in their line_items:

“The amount of money, integer”. Line items are not price modifiers, only price modifiers (taxes, surcharges etc. can be a %), and this function should be going through line items with a base/int price amounts.

Square wants to calculate the Order themselves and if the order total calculated by them doesn’t match the mount of the payment that we are trying to create – Error…

Plus, their line items are not as flexible as ours (logic is totally different), thus it is hard to combine the two.


careertraining

February 17, 2022 at 5:07 pm

Thanks. That lead to me switching from EEH_Line_Item::add_percentage_based_item() to EEH_Line_Item::add_unrelated_item() and doing the arithmetic myself.

Viewing 5 reply threads

The support post ‘"The payment total does not match the order total" started appearing’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso