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

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

Merged
merged 6 commits into from
Aug 5, 2022

Conversation

grzesebe
Copy link
Contributor

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

netlify bot commented Jul 26, 2022

Deploy Preview for capacitor-community-stripe ready!

Name Link
🔨 Latest commit 17c0580
🔍 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 grzesebe changed the title Feat/pass return url (new payment methods) Feat(): pass return url (new payment methods) Jul 26, 2022
@grzesebe grzesebe marked this pull request as draft July 26, 2022 10:44
@grzesebe grzesebe marked this pull request as ready for review July 26, 2022 10:45
@grzesebe
Copy link
Contributor Author

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

@@ -22,10 +22,10 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capacitor 3's target & compile sdkVersion is 30. So if you need it, you will have to wait for a Capacitor4-compatible version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new payment methods was added in v19.1.0 of Android Stripe SDK (stripe/stripe-android#4489).
Unfortunately compileSdkVersion was bumped in 18.2.0 (stripe/stripe-android@7053906).

Maybe there is a way to choose a SKD version based on compileSdkVersion of parent project?

call.resolve()
} else {
call.reject("This was not a Stripe url – handle the URL normally as you would")
return
Copy link
Member

@rdlabo rdlabo Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return may not need

@rdlabo
Copy link
Member

rdlabo commented Jul 26, 2022

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

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

rdlabo commented Aug 5, 2022

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 rdlabo merged commit 356bd8f into capacitor-community:master Aug 5, 2022
@rdlabo
Copy link
Member

rdlabo commented Aug 5, 2022

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.

👉 #145

Thanks.

@grzesebe
Copy link
Contributor Author

grzesebe commented Aug 8, 2022

Wow, that was fast :)
As soon as we will go production I'll post in #145

@grzesebe grzesebe deleted the feat/pass_returnURL branch August 8, 2022 09:29
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

Successfully merging this pull request may close these issues.

None yet

2 participants