aimeos / aimeos-core

Aimeos PHP e-commerce framework for ultra fast online shops, scalable marketplaces, complex B2B applications and #gigacommerce
https://aimeos.org
Other
3.26k stars 112 forks source link

FreeShipping coupon and PayPal express #269

Closed nvindice closed 2 years ago

nvindice commented 2 years ago

I can't get this combination to work. As soon as the FreeShipping coupon is applied, the PayPalExpress payment fails ("Wrong shipping amount"). The following values are sent:

L_SHIPPINGOPTIONAMOUNT0 = 16.90 (regular shipping costs) PAYMENTREQUEST_0_SHIPPINGAMT=0.00

What is the solution here?

aimeos commented 2 years ago

There seems to be a bug in the PayPalExpress shipping cost handling. Can you check what needs to be done to get that work for your conditions?

nvindice commented 2 years ago

Not sure if this is a bug or a design problem. As far as I understand, the FreeShipping coupon does not remove the service costs but adds a new item with the negative sum of all reduced costs. So it might be difficult to tell which service costs were reduced in the PayPal provider. Any ideas on how to fix this?

EDIT: Is there a good reason to not just remove the costs from the service items on the fly by the FreeShipping coupon instead of adding a new price item to the coupon item?

jonaseberle commented 2 years ago

I am having the same problem with PayPalExpress, but in my case with a custom plugin that sets tax rates on services.

In my case I found

https://github.com/aimeos/aimeos-core/blob/94d09cacf6e7973916d9b23c2e75ccca33152712/lib/mshoplib/src/MShop/Service/Provider/Payment/PayPalExpress.php#L731

using ->getCosts() and thus not taking taxes and value into account. Making it use \Aimeos\MShop\Service\Provider\Base::getAmount as is used when setting PAYMENTREQUEST_0_SHIPPINGAMT later https://github.com/aimeos/aimeos-core/blob/94d09cacf6e7973916d9b23c2e75ccca33152712/lib/mshoplib/src/MShop/Service/Provider/Payment/PayPalExpress.php#L754

solves it for me.

So that line 731 reads:

$values['L_SHIPPINGOPTIONAMOUNT' . $lastPos] = number_format( $this->getAmount( $service->getPrice(), true, true, $price->getPrecision() + 2 ), 2, '.', '' );

Does that make sense? I think it would help here, too.

Without that, it would transmit

'L_SHIPPINGOPTIONAMOUNT0' => '0.00',
'PAYMENTREQUEST_0_SHIPPINGAMT' => '7.14',

which trips PayPal. As in my case as well as with FreeShipping the PAYMENTREQUEST_0_SHIPPINGAMT is correct, it should be fine to base the calculation on the method used there.

nvindice commented 2 years ago

Thanks for your suggestion, but I think this will not work here. The shipping service's calculated amount will be different nevertheless because the product costs are not integrated.

@aimeos This bug is worse than I thought, it's not possible to buy items with item shipping costs at all.

aimeos commented 2 years ago

@jonaseberle Does that PR (https://github.com/aimeos/aimeos-core/pull/272) fix your problem too?

jonaseberle commented 2 years ago

@jonaseberle Does that PR (#272) fix your problem too?

I'll comment there.

nvindice commented 2 years ago

Fixed by https://github.com/aimeos/aimeos-core/pull/272