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

gateway->authorize without return_url to allow "next_action": {"type": "use_stripe_sdk"} #152

Open
R00118189 opened this issue Sep 11, 2019 · 6 comments

Comments

@R00118189
Copy link

R00118189 commented Sep 11, 2019

I followed example on https://github.com/stripe/stripe-payments-demo and would like to use stripe.handleCardAction(response.data.payment_intent_client_secret) to get a popup not redirect as currently package is offering
at this moment i commented this section

// if ($this->getConfirm()) {
//     $this->validate('returnUrl');
//     $data['return_url'] = $this->getReturnUrl();

to get use_stripe_sdk in the response and use frontend stripe.handleCardAction

also i would add

public function isFurtherActionRequired()
    {
        if ($this->getStatus() === 'requires_action' || $this->getStatus() === 'requires_source_action') {
            return (!empty($this->data['next_action']) && $this->data['next_action']['type'] === 'use_stripe_sdk');
        }
    }

my flow is as follows:

  • Create PM on frontend with Stripe.js
  • Create PI on backend and when PI status requires further action i send to frontend PI secret and ask Stripe.js to do handleCardAction
  • Go back to backend and confirm the PI
  • Get status of the PI as succeeded & Fulfil the order on Backend

All in one page No redirects

@domis86
Copy link

domis86 commented Sep 12, 2019

Yes - i use similar flow which is described here: https://stripe.com/docs/payments/payment-intents/web-manual

I did following workaround to make this flow work:

        $paymentIntentAuthorizeRequest = $paymentIntentGateway->authorize();

        $paymentIntentAuthorizeRequest->setPaymentMethod($paymentMethodId);
        $paymentIntentAuthorizeRequest->setDescription('My Order '.$orderUuid);
        $paymentIntentAuthorizeRequest->setCustomerReference($stripeCustomer->getId());
        $paymentIntentAuthorizeRequest->setAmount($orderPrice);
        $paymentIntentAuthorizeRequest->setCurrency($orderCurrency);
        
        $paymentIntentAuthorizeRequest->setConfirm(true);
        $paymentIntentAuthorizeRequest->setReturnUrl(' ');

        $data = $paymentIntentAuthorizeRequest->getData();

        // Don't send 'return_url' because we want "Stripe SDK" to handle PaymentIntent on frontend side
        // If 'return_url' would be sent then it will be the "redirect way" - read more here: https://stripe.com/docs/payments/3d-secure-iframe
        // Also unset 'capture_method' so it will be default ('automatic') see: https://stripe.com/docs/api/payment_intents/create#create_payment_intent-capture_method
        unset($data['return_url'], $data['capture_method']);

        /** @var \Omnipay\Stripe\Message\PaymentIntents\Response $paymentResponse */
        $paymentResponse = $paymentIntentAuthorizeRequest->sendData($data);

Can you try similarily?
If works for you too then someone should propose PR with changes that add option to enable such flow :)

@R00118189
Copy link
Author

R00118189 commented Sep 13, 2019

Dominik, your flow works however there is one more obstacle with application_fee which shall be upgraded to application_fee_amount as per new Payment Intents API

$data['application_fee_amount'] = $data['application_fee'];
unset($data['application_fee'], $data['return_url'], $data['capture_method']);

does the job until the package is fully upgraded

domis86 referenced this issue Sep 17, 2019
Add support for the SCA-ready Payment Intents API by adding a new gatewa.
@gmoreira
Copy link

I discussed this with Stripe Support today and they informed me that while return_url is only available when confirm=true, it is not mandatory to specify. The documentation is actually not clear about this, if its required or optional when confirm=true, which they confirmed for me today is optional.

What I have found is that when confirm=true and a return_url is specified, this is triggering the Manually handling 3D Secure authentication with redirect workflow, which requires the browser client code to manually handle redirecting the the redirect url provided for the PaymentIntent.

If the return_url is actually not specified and confirm=true, the PaymentIntent response can contain a client_secret that (if applicable) is actually compatible with Dynamic 3D Secure workflow which uses the pre-built modal inside Stripe Elements to handle the process without manual redirects via stripe.handleCardAction.

@gmoreira
Copy link

PR #155 has been introduced to address the issue with the Application Fee Amount field.

@domis86
Copy link

domis86 commented Sep 17, 2019

@gmoreira

If the return_url is actually not specified and confirm=true, the PaymentIntent response can contain a client_secret that (if applicable) is actually compatible with Dynamic 3D Secure workflow which uses the pre-built modal inside Stripe Elements to handle the process without manual redirects via stripe.handleCardAction.

I use it like this with the workaround i specified above #152 (comment) - so i guess something similar should be added as feature to Omnipay Stripe.

@gmoreira
Copy link

Ive extended PR #156 to include helper methods $response->isStripeSDKAction() and $response->getClientSecret().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants