From e291d0e5c519c7cc96ce9b5a284c4b18ac35425a Mon Sep 17 00:00:00 2001 From: Grzegorz Ebert Date: Fri, 15 Jul 2022 14:30:04 +0200 Subject: [PATCH 1/4] updated stripe ios sdk version --- CapacitorCommunityStripe.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CapacitorCommunityStripe.podspec b/CapacitorCommunityStripe.podspec index c056c864f..25f8bc245 100644 --- a/CapacitorCommunityStripe.podspec +++ b/CapacitorCommunityStripe.podspec @@ -13,6 +13,6 @@ Pod::Spec.new do |s| s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}' s.ios.deployment_target = '12.0' s.dependency 'Capacitor' - s.dependency 'Stripe', '21.8.1' + s.dependency 'Stripe', '22.4.0' s.swift_version = '5.1' end From 4c873b2ae9bc8791abc5607d2daaad82d0d1a29a Mon Sep 17 00:00:00 2001 From: Grzegorz Ebert Date: Fri, 15 Jul 2022 14:32:45 +0200 Subject: [PATCH 2/4] added returnURL to ios --- README.md | 2 ++ ios/Plugin/PaymentFlow/PaymentFlowExecutor.swift | 5 +++++ ios/Plugin/PaymentSheet/PaymentSheetExecutor.swift | 5 +++++ src/shared/index.ts | 6 ++++++ 4 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 295efe784..bc6328f67 100644 --- a/README.md +++ b/README.md @@ -686,6 +686,7 @@ initialize(opts: StripeInitializationOptions) => Promise | **`GooglePayIsTesting`** | boolean | | false, | | **`countryCode`** | string | use ApplePay and GooglePay. If set enableApplePay and enableGooglePay false, Plugin ignore here. | "US" | | **`merchantDisplayName`** | string | | "App Name" | +| **`returnURL`** | string | | "" | | **`style`** | 'alwaysLight' \| 'alwaysDark' | iOS Only | undefined | | **`withZipCode`** | boolean | Platform: Web only Show ZIP code field. | true | @@ -703,6 +704,7 @@ initialize(opts: StripeInitializationOptions) => Promise | **`GooglePayIsTesting`** | boolean | | false, | | **`countryCode`** | string | use ApplePay and GooglePay. If set enableApplePay and enableGooglePay false, Plugin ignore here. | "US" | | **`merchantDisplayName`** | string | | "App Name" | +| **`returnURL`** | string | | "" | | **`style`** | 'alwaysLight' \| 'alwaysDark' | iOS Only | undefined | | **`withZipCode`** | boolean | Platform: Web only Show ZIP code field. | true | diff --git a/ios/Plugin/PaymentFlow/PaymentFlowExecutor.swift b/ios/Plugin/PaymentFlow/PaymentFlowExecutor.swift index 93a707d5b..2845d4532 100644 --- a/ios/Plugin/PaymentFlow/PaymentFlowExecutor.swift +++ b/ios/Plugin/PaymentFlow/PaymentFlowExecutor.swift @@ -33,6 +33,11 @@ class PaymentFlowExecutor: NSObject { configuration.merchantDisplayName = merchantDisplayName } + let returnURL = call.getString("returnURL") ?? "" + if returnURL != "" { + configuration.returnURL = returnURL + } + if #available(iOS 13.0, *) { let style = call.getString("style") ?? "" if style == "alwaysLight" { diff --git a/ios/Plugin/PaymentSheet/PaymentSheetExecutor.swift b/ios/Plugin/PaymentSheet/PaymentSheetExecutor.swift index 0bbc720f7..023865467 100644 --- a/ios/Plugin/PaymentSheet/PaymentSheetExecutor.swift +++ b/ios/Plugin/PaymentSheet/PaymentSheetExecutor.swift @@ -31,6 +31,11 @@ class PaymentSheetExecutor: NSObject { configuration.merchantDisplayName = merchantDisplayName } + let returnURL = call.getString("returnURL") ?? "" + if returnURL != "" { + configuration.returnURL = returnURL + } + if #available(iOS 13.0, *) { let style = call.getString("style") ?? "" if style == "alwaysLight" { diff --git a/src/shared/index.ts b/src/shared/index.ts index 2db33f6b5..3efcaf5ad 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -74,6 +74,12 @@ export interface BasePaymentOption { */ merchantDisplayName?: string | undefined; + /** + * @url https://stripe.com/docs/payments/accept-a-payment?platform=ios&ui=payment-sheet#ios-set-up-return-url + * @default "" + */ + returnURL?: string | undefined; + /** * iOS Only * @url https://stripe.com/docs/payments/accept-a-payment?platform=ios&ui=payment-sheet#userinterfacestyle From cb7c3a210796a47920e6276fbea93dcd345d2fe9 Mon Sep 17 00:00:00 2001 From: Grzegorz Ebert Date: Fri, 15 Jul 2022 15:25:58 +0200 Subject: [PATCH 3/4] added handleURLCallback method --- README.md | 30 +++++++++++++++++++++++++++--- ios/Plugin/StripePlugin.m | 1 + ios/Plugin/StripePlugin.swift | 26 ++++++++++++++++++++++++++ src/definitions.ts | 9 +++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bc6328f67..c83a0e3b3 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ Learn at [the official @capacitor-community/stripe documentation](https://stripe * [`addListener(PaymentSheetEventsEnum.Canceled, ...)`](#addlistenerpaymentsheeteventsenumcanceled) * [`addListener(PaymentSheetEventsEnum.Failed, ...)`](#addlistenerpaymentsheeteventsenumfailed) * [`initialize(...)`](#initialize) +* [`handleURLCallback(...)`](#handleurlcallback) * [Interfaces](#interfaces) * [Type Aliases](#type-aliases) * [Enums](#enums) @@ -640,6 +641,21 @@ initialize(opts: StripeInitializationOptions) => Promise -------------------- +### handleURLCallback(...) + +```typescript +handleURLCallback(opts: StripeURLHandlingOptions) => Promise +``` + +iOS Only + +| Param | Type | +| ---------- | ----------------------------------------------------------------------------- | +| **`opts`** | StripeURLHandlingOptions | + +-------------------- + + ### Interfaces @@ -717,11 +733,19 @@ initialize(opts: StripeInitializationOptions) => Promise | **`stripeAccount`** | string | Optional. Making API calls for connected accounts | +#### StripeURLHandlingOptions + +| Prop | Type | +| --------- | ------------------- | +| **`url`** | string | + + #### StripePlugin -| Method | Signature | -| -------------- | -------------------------------------------------------------------------------------------------------- | -| **initialize** | (opts: StripeInitializationOptions) => Promise<void> | +| Method | Signature | Description | +| --------------------- | -------------------------------------------------------------------------------------------------------- | ----------- | +| **initialize** | (opts: StripeInitializationOptions) => Promise<void> | | +| **handleURLCallback** | (opts: StripeURLHandlingOptions) => Promise<void> | iOS Only | #### CapacitorStripeContext diff --git a/ios/Plugin/StripePlugin.m b/ios/Plugin/StripePlugin.m index 481f94249..b878bb909 100644 --- a/ios/Plugin/StripePlugin.m +++ b/ios/Plugin/StripePlugin.m @@ -5,6 +5,7 @@ // each method the plugin supports using the CAP_PLUGIN_METHOD macro. CAP_PLUGIN(StripePlugin, "Stripe", CAP_PLUGIN_METHOD(initialize, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(handleURLCallback, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(createPaymentSheet, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(presentPaymentSheet, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(createPaymentFlow, CAPPluginReturnPromise); diff --git a/ios/Plugin/StripePlugin.swift b/ios/Plugin/StripePlugin.swift index 8a0c92b4e..7c22cce61 100644 --- a/ios/Plugin/StripePlugin.swift +++ b/ios/Plugin/StripePlugin.swift @@ -34,6 +34,32 @@ public class StripePlugin: CAPPlugin { call.resolve() } + @objc func handleURLCallback(_ call: CAPPluginCall) { + self.paymentSheetExecutor.plugin = self + self.paymentFlowExecutor.plugin = self + self.applePayExecutor.plugin = self + + let urlString = call.getString("url") ?? "" + + if urlString == "" { + call.reject("you must provide url returned from browser") + return + } + + let url = URL(string: urlString)! + DispatchQueue.main.async { + let stripeHandled = StripeAPI.handleURLCallback(with: url) + if (stripeHandled) { + call.resolve() + } else { + call.reject("This was not a Stripe url – handle the URL normally as you would") + return + } + } + + + } + @objc func createPaymentSheet(_ call: CAPPluginCall) { self.paymentSheetExecutor.createPaymentSheet(call) } diff --git a/src/definitions.ts b/src/definitions.ts index 738fc7f25..d1abaae24 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -13,6 +13,11 @@ type StripeDefinitions = PaymentSheetDefinitions & PaymentFlowDefinitions & Appl export interface StripePlugin extends StripeDefinitions { initialize(opts: StripeInitializationOptions): Promise; + /** + * iOS Only + * @url https://stripe.com/docs/payments/3d-secure#return-url + */ + handleURLCallback?(opts: StripeURLHandlingOptions): Promise; } export interface StripeInitializationOptions { @@ -25,6 +30,10 @@ export interface StripeInitializationOptions { stripeAccount?: string; } +export interface StripeURLHandlingOptions { + url: string; +} + export interface CapacitorStripeContext { stripe: StripePlugin; isApplePayAvailable: boolean; From 17c05804b9a5e73787615ac6a2aa488cf1e3bb44 Mon Sep 17 00:00:00 2001 From: Grzegorz Ebert Date: Tue, 26 Jul 2022 08:28:19 +0200 Subject: [PATCH 4/4] feat(android): update to 20.7.0 --- android/build.gradle | 6 +++--- .../com/getcapacitor/community/stripe/StripePlugin.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 9af2b9ad1..692cfc762 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -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 defaultConfig { minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21 - targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30 + targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 32 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -59,7 +59,7 @@ dependencies { testImplementation "junit:junit:$junitVersion" androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion" androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion" - implementation 'com.stripe:stripe-android:18.2.0' + implementation 'com.stripe:stripe-android:20.7.0' implementation 'com.google.android.gms:play-services-wallet:19.1.0' implementation 'com.google.code.gson:gson:2.8.6' diff --git a/android/src/main/java/com/getcapacitor/community/stripe/StripePlugin.java b/android/src/main/java/com/getcapacitor/community/stripe/StripePlugin.java index f7a3715f8..ba9ae2690 100644 --- a/android/src/main/java/com/getcapacitor/community/stripe/StripePlugin.java +++ b/android/src/main/java/com/getcapacitor/community/stripe/StripePlugin.java @@ -9,9 +9,9 @@ import com.getcapacitor.community.stripe.helper.MetaData; import com.getcapacitor.community.stripe.paymentflow.PaymentFlowExecutor; import com.getcapacitor.community.stripe.paymentsheet.PaymentSheetExecutor; -import com.stripe.android.AppInfo; import com.stripe.android.PaymentConfiguration; import com.stripe.android.Stripe; +import com.stripe.android.core.AppInfo; import com.stripe.android.googlepaylauncher.GooglePayLauncher; import com.stripe.android.paymentsheet.PaymentSheet; import org.jetbrains.annotations.NotNull;