craftcms / commerce-stripe

Stripe payment gateway for Craft Commerce
https://plugins.craftcms.com/commerce-stripe
MIT License
31 stars 50 forks source link

Ajax Payment and redirect for 3D Secure #126

Closed jan-thoma closed 3 years ago

jan-thoma commented 4 years ago

Description

I'm Trying to build a headless shop on vue.js. Everything is going fine so far. The only part which i can't find any documentation is how to handle redirects after 3D Secure payments.

If i'm submitting the "/actions/commerce/payments/pay" method with ajax i will get the redirect url for 3D Secure Auth back and can successfully confirm or deny the payment but im always gettting redirected to the root of my Page. Is there a way to submit the desired locations for successful and denied payments with ajax?

mildlygeeky commented 4 years ago

We literally ran into the same object today - ended up adding this to a site module to add in the data on the order, as it seems the Stripe integration wasn't filling in a return URL / cancel URL on its own (you would need to adjust the path).

Screen Shot 2020-09-25 at 5 14 17 PM

jan-thoma commented 4 years ago

For my case the cancelUrl is not working with your example. The returnUrl just works fine

joshangell commented 3 years ago

@mildlygeeky @jan-thoma In case this helps either of you I needed this to work as well, in my Vue app I have an API endpoint that returns my state, and in that I sent the following data:

return $this->asJson([
    // Loads of other stuff
    'checkoutRedirect' => Craft::$app->getSecurity()->hashData('/order?number={number}'),
    'checkoutCancel' => Craft::$app->getSecurity()->hashData('/checkout#pay')
];

Then I used that in my Vue component when posting the payment to Commerce. I had to use stripe.createPaymentMethod() first to get the payment method ID, and then send that in the commerce/payments/pay request in the paymentMethodId param, as well as gatewayId and then redirect and cancelUrl populated from my state API.

r0skar commented 3 years ago

I am having the same issue as OP, but the proposed solution by @mildlygeeky does not seem to work for me. I have added the event listener:

Event::on(
  Order::class,
  Order::EVENT_BEFORE_COMPLETE_ORDER,
  function (Event $event) {
    $order = $event->sender;
    $order->cancelUrl = UrlHelper::url("/payment-complete");
    $order->returnUrl = UrlHelper::url("/payment-complete");
  }
);

But once I confirm the payment in the Stripe iFrame, I still get redirect to /index.php when clicking on Return to merchant. Changing this line manually solves the problem, but obviously is not a solution.