Posted: 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. 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? |
|
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 The first two contain the base price of the event The third contains I appreciate your help! |
|
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. |
|
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.
I tried setting the total 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. |
|
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. |
|
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. |
|
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.