craftcms / commerce-paypal-checkout

PayPal Checkout gateway for Craft Commerce.
https://plugins.craftcms.com/commerce-paypal-checkout
MIT License
5 stars 10 forks source link

AMOUNT_MISTMATCH error on carts with adjuster that increases the total price #25

Closed j-greig closed 3 years ago

j-greig commented 3 years ago

Description

We have a custom module running that allows additional line items to be added to the cart along with a product.

When these line items increase the price (eg the £45 extras in the basket screenshot), PayPal throws this error:

Error: Should equal item_total + tax_total + shipping + handling + insurance - shipping_discount - discount

The same cart contents can be purchased using the Stripe gateway just fine, and equally if the adjuster items do not increase the price, everything is fine too.

I've put the adjuster code at https://gist.github.com/j-greig/1deefb9150a95c7718563795b9968916 in case helpful.

Thanks!

Additional info

image

nfourtythree commented 3 years ago

Hi @j-greig

This is a prime showcase as to why we have deprecated custom adjuster types in Commerce. PayPal does not have any concept than anything other than things listed above (item total, tax, shipping etc). Therefore we cannot allocate that amount to any portion.

~For now, I have added a new setting sendTotalsBreakdown. By setting this to false in your commerce-paypal-checkout.php config file you can prevent the plugin from sending the breakdown of the total cost to PayPal.~ see comment for solution

This should fix your issue. But it is worth keeping an on the custom adjuster types as they will be removed in a future version, we are looking at other ways developers can make adjustments to prices/line items/orders.

We will get a release out shortly with this new setting.

Thanks!

j-greig commented 3 years ago

Ahh I see, thanks for rolling this out so quickly!

j-greig commented 3 years ago

D'oh there is a different error now...

_Error: If item details are specified (items.unit_amount and items.quantity) corresponding amount.breakdown.itemtotal is required.

Or full version...

{"name":"UNPROCESSABLE_ENTITY","details":[{"field":"\/purchase_units\/0\/amount\/breakdown\/item_total","location":"body","issue":"ITEM_TOTAL_REQUIRED","description":"If item details are specified (items.unit_amount and items.quantity) corresponding amount.breakdown.item_total is required."}],"message":"The requested action could not be performed, semantically incorrect, or failed business validation.","debug_id":"98b4c4f773598","links":[{"href":"https:\/\/developer.paypal.com\/docs\/api\/orders\/v2\/#error-ITEM_TOTAL_REQUIRED","rel":"information_link","method":"GET"}]}

j-greig commented 3 years ago

Update: if I comment out 'items' => $this->_buildItems($order, $transaction), at L535 of the Gateway.php, it works fine though. Seems a shame to lose the item details but if that's the only fix for now I guess it's ok.

nfourtythree commented 3 years ago

Hi @j-greig

Thank you for updating me with this. Will look into it further.

Thanks

nfourtythree commented 3 years ago

Hi @j-greig

Apologies about the above looks like my poor interpretation of their docs.

Have just pushed a release which removes the above setting as it is a bit redundant. The way to get around this for people using custom adjuster types is to turn off the "Send cart information" setting on the gateway. This disables the items and the cost breakdown as they won't match.

I have added a note to the readme for people in the same situation.

As you mentioned it is not ideal but a necessity until there is another solution for price adjusters. You could look at altering the logic and changing the price using the populate line item event, this is a common way for people to adjust the pricing of an item (losing the adjustment features, but better gateway compatibility).

Hope this helps!

j-greig commented 3 years ago

Awesome, thanks again... all working now and deployed to live site :)