pimcore / ecommerce-framework-bundle

Ecommerce Framework community bundle provides e-commerce functionality such as product listing and filtering, pricing, carts and checkouts for Pimcore.
https://pimcore.com/docs/platform/Ecommerce_Framework/
Other
11 stars 33 forks source link

[Bug]: Error on recreateOrder if one time token is used #103

Closed MercuryKojo closed 1 year ago

MercuryKojo commented 1 year ago

Expected behavior

order is recreated and containing the voucher token which is onetime use

Actual behavior

recreate order reapplies the voucher token to the new order without removing it for the source order and throws an error, that the voucher can not be used anymore

Steps to reproduce

add a onetime use voucher to the cart and start a payment return and change cart so the order will be recreated start payment again -> throws exception and the new order has not order items and no voucher

github-actions[bot] commented 1 year ago

Thanks a lot for reporting the issue. We did not consider the issue as "Priority" or "Backlog", so we're not going to work on that anytime soon. Please create a pull request to fix the issue if this is a bug report. We'll then review it as quickly as possible. If you're interested in contributing a feature, please contact us first here before creating a pull request. We'll then decide whether we'd accept it or not. Thanks for your understanding.

kingjia90 commented 1 year ago

Is it reproducible on the Pimcore demo? I wasn't able to simulate, can you check if usages of the given token is still 0?

image can you also provide the screenshot of the error message (stack trace or any code/error message)?

MercuryKojo commented 1 year ago

Hi @kingjia90 here is the Stacktrace: [2023-03-18T09:57:04.352127+01:00] request.CRITICAL: Uncaught PHP Exception Pimcore\Bundle\EcommerceFrameworkBundle\Exception\VoucherServiceException: "Token has already been used." at /home/.../www/vendor/pimcore/pimcore/bundles/EcommerceFrameworkBundle/VoucherService/TokenManager/Pattern.php line 140 {"exception":"[object] (Pimcore\Bundle\EcommerceFrameworkBundle\Exception\VoucherServiceException(code: 1): Token has already been used. at /home/.../www/vendor/pimcore/pimcore/bundles/EcommerceFrameworkBundle/VoucherService/TokenManager/Pattern.php:140)"} []

[2023-03-18T09:57:04.352301+01:00] app.ERROR: Pimcore\Bundle\EcommerceFrameworkBundle\Exception\VoucherServiceException: Token has already been used. in /home/.../www/vendor/pimcore/pimcore/bundles/EcommerceFrameworkBundle/VoucherService/TokenManager/Pattern.php:140 Stack trace:

0 /home/.../www/vendor/pimcore/pimcore/bundles/EcommerceFrameworkBundle/VoucherService/DefaultService.php(136): Pimcore\Bundle\EcommerceFrameworkBundle\VoucherService\TokenManager\Pattern->applyToken('STUcard-AfWkb', Object(App\Ecommerce\CartManager\SessionCart), Object(App\Model\DataObject\OnlineShopOrder))

1 /home/.../www/vendor/pimcore/pimcore/bundles/EcommerceFrameworkBundle/OrderManager/V7/OrderManager.php(744): Pimcore\Bundle\EcommerceFrameworkBundle\VoucherService\DefaultService->applyToken('STUcard-AfWkb', Object(App\Ecommerce\CartManager\SessionCart), Object(App\Model\DataObject\OnlineShopOrder))

2 /home/.../www/vendor/pimcore/pimcore/bundles/EcommerceFrameworkBundle/OrderManager/V7/OrderManager.php(246): Pimcore\Bundle\EcommerceFrameworkBundle\OrderManager\V7\OrderManager->applyVoucherTokens(Object(App\Model\DataObject\OnlineShopOrder), Object(App\Ecommerce\CartManager\SessionCart)) #3 /home/.../www/vendor/pimcore/pimcore/bundles/EcommerceFrameworkBundle/OrderManager/V7/OrderManager.php(349): Pimcore\Bundle\EcommerceFrameworkBundle\OrderManager\V7\OrderManager->getOrCreateOrderFromCart(Object(App\Ecommerce\CartManager\SessionCart))

4 /home/.../www/vendor/pimcore/pimcore/bundles/EcommerceFrameworkBundle/CheckoutManager/V7/CheckoutManager.php(227): Pimcore\Bundle\EcommerceFrameworkBundle\OrderManager\V7\OrderManager->recreateOrder(Object(App\Ecommerce\CartManager\SessionCart))

5 /home/.../www/vendor/pimcore/pimcore/bundles/EcommerceFrameworkBundle/CheckoutManager/V7/CheckoutManager.php(247): Pimcore\Bundle\EcommerceFrameworkBundle\CheckoutManager\V7\CheckoutManager->checkIfPaymentIsPossible()

6 /home/.../www/src/Controller/PaymentController.php(72): Pimcore\Bundle\EcommerceFrameworkBundle\CheckoutManager\V7\CheckoutManager->initOrderPayment()

7 /home/.../www/vendor/symfony/http-kernel/HttpKernel.php(153): App\Controller\PaymentController->paymentAction(Object(Symfony\Component\HttpFoundation\Request), Object(Pimcore\Log\ApplicationLogger))

8 /home/.../www/vendor/symfony/http-kernel/HttpKernel.php(75): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)

9 /home/.../www/vendor/symfony/http-kernel/Kernel.php(202): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)

10 /home/.../www/public/index.php(35): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))

11 {main} [] []

Pimcore Demo definitely throws an Error with this steps:

Configure Commercial voucher image add commercial car and voucher image Checkout until payment and start creditcard payment (but don't complete the payment) image Go Back to Cart and Change the amount to 2 (so pimcore will recreate the order) image checkout again until Payment select and click on creditcard again and it will throw an error: image

kingjia90 commented 1 year ago

Confirming the problem. When one step into the payment, in the backend it would create the order which logs the payment history and there the price is the already discounted as if it applied the voucher and triggers its usage. From user perspective, going back to change the cart should be naturally possible, but i am having some concern about concurrent same one-time vouchers on these pending orders, if we trigger usage only at successfull payments. 🤔 Need digging some more on how to fix this

fashxp commented 1 year ago

My thoughts on this: Finishing the original and the recreated order is most likely some unwanted scenario. It is possible though, and to make it traceable and also fixable for customer service we decided to do it that way and keeping both orders.

From that perspective, I think most reasonable fix for that would be to remove the voucher from the original order when recreating the order (and place the information in notes or version notes for traceability)?

@kingjia90 WDYT?

kingjia90 commented 1 year ago

@fashxp had some time to look into it and seems that #121 may fix it

dvesh3 commented 1 year ago

Fixed by #121