Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MercuryKojo opened this issue Apr 5, 2023 · 7 comments
Closed

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

MercuryKojo opened this issue Apr 5, 2023 · 7 comments
Assignees
Milestone

Comments

@MercuryKojo
Copy link
Contributor

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

@MercuryKojo MercuryKojo added the Bug label Apr 5, 2023
@github-actions
Copy link

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.

@fashxp fashxp transferred this issue from pimcore/pimcore Jun 12, 2023
@dvesh3 dvesh3 added Backlog and removed PR Welcome labels Jun 28, 2023
@kingjia90
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

kingjia90 commented Jul 20, 2023

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
Copy link
Member

fashxp commented Aug 28, 2023

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
Copy link
Contributor

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

@kingjia90 kingjia90 added this to the 1.0.5 milestone Sep 1, 2023
@dvesh3
Copy link
Contributor

dvesh3 commented Sep 5, 2023

Fixed by #121

@dvesh3 dvesh3 closed this as completed Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants