capacitor-community / stripe

Stripe Mobile SDK wrapper for Capacitor
https://capacitor-community-stripe.netlify.app/
MIT License
196 stars 77 forks source link

Feat(): pass return url (new payment methods) #201

Closed grzesebe closed 2 years ago

grzesebe commented 2 years ago

Hi, I was investigating possibility of using different payment methods ex: p24, Klarna... It occurs that we only need to update the SDKs On IOS it's also needed to pass "returnURL" param and handle URL callback after return to app from browser. https://stripe.com/docs/payments/accept-a-payment?platform=ios&ui=payment-sheet#ios-set-up-return-url

I've tested it on IOS and Android Emulator and it seems to work pretty well.

Unfortunately I wasn't able to compile on Android without bumping targetSdkVersion and compileSdkVersion

I'm handling URL like this:

import { App as CapacitorApp } from '@capacitor/app';
import { Stripe } from '@capacitor-community/stripe';

function initUrlHandler(router) {
  CapacitorApp.addListener('appUrlOpen', function (event) {
    console.log('app opened from url', event);
    try {
      const slug = event.url.split('://').pop();
      if (/same-page((\?|#).*)?$/gm.test(slug)) return;
      if (/stripe-callback((\?|#).*)?$/gm.test(slug)) {
        Stripe.handleURLCallback({ url: event.url });
        return;
      }
      const resolved = router.resolve(slug);
      if (slug && (!resolved || resolved.name === '404')) {
        throw new Error('Nieznana ścieżka aplikacji');
      }
      if (slug) router.push(resolved);
    } catch (err) {
      alert(err);
    }
  });
}

export default initUrlHandler;
netlify[bot] commented 2 years ago

Deploy Preview for capacitor-community-stripe ready!

Name Link
Latest commit 17c05804b9a5e73787615ac6a2aa488cf1e3bb44
Latest deploy log https://app.netlify.com/sites/capacitor-community-stripe/deploys/62df8cc8b292d60008c9ee58
Deploy Preview https://deploy-preview-201--capacitor-community-stripe.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

grzesebe commented 2 years ago

I've tested this solution with p24 (https://stripe.com/docs/payments/p24), and 3DSecure card confirmation (https://stripe.com/docs/payments/3d-secure)

rdlabo commented 2 years ago

@grzesebe Thanks for your great work and pull request! I was in a bit of a hurry so I couldn't take a closer look, but I commented. Please let me know if it is mandatory, especially for Android targetVersion.

grzesebe commented 2 years ago

@rdlabo Thanks for your hard work on this plugin. You're the best. The p24 payment is crucial for me before using this library in production. The card payments are not enough. Maybe I should create a temporary NPM package until we are able to update the android SDK version?

rdlabo commented 2 years ago

In fact, we have already pre-released a version that supports Capacitor4, and the android SDK version is already available in the master branch.

Now you no longer have a problem accepting your pull request. Now we'll work on resolving the conflicts and doing the merge!

rdlabo commented 2 years ago

Merged!! Now pre-release.

npm i @capacitor-community/stripe@4.0.0-2

@grzesebe Thanks for great work!! Did you use this plugin for production? If yes, please tell us what app. This help development this plugin.

👉 https://github.com/capacitor-community/stripe/issues/145

Thanks.

grzesebe commented 2 years ago

Wow, that was fast :) As soon as we will go production I'll post in https://github.com/capacitor-community/stripe/issues/145