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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -640,6 +641,21 @@ initialize(opts: StripeInitializationOptions) => Promise<void>
--------------------


### handleURLCallback(...)

```typescript
handleURLCallback(opts: StripeURLHandlingOptions) => Promise<void>
```

iOS Only

| Param | Type |
| ---------- | ----------------------------------------------------------------------------- |
| **`opts`** | <code><a href="#stripeurlhandlingoptions">StripeURLHandlingOptions</a></code> |

--------------------


### Interfaces


Expand Down Expand Up @@ -686,6 +702,7 @@ initialize(opts: StripeInitializationOptions) => Promise<void>
| **`GooglePayIsTesting`** | <code>boolean</code> | | <code>false,</code> |
| **`countryCode`** | <code>string</code> | use ApplePay and GooglePay. If set enableApplePay and enableGooglePay false, Plugin ignore here. | <code>"US"</code> |
| **`merchantDisplayName`** | <code>string</code> | | <code>"App Name"</code> |
| **`returnURL`** | <code>string</code> | | <code>""</code> |
| **`style`** | <code>'alwaysLight' \| 'alwaysDark'</code> | iOS Only | <code>undefined</code> |
| **`withZipCode`** | <code>boolean</code> | Platform: Web only Show ZIP code field. | <code>true</code> |

Expand All @@ -704,6 +721,7 @@ initialize(opts: StripeInitializationOptions) => Promise<void>
| **`GooglePayIsTesting`** | <code>boolean</code> | | <code>false,</code> |
| **`countryCode`** | <code>string</code> | use ApplePay and GooglePay. If set enableApplePay and enableGooglePay false, Plugin ignore here. | <code>"US"</code> |
| **`merchantDisplayName`** | <code>string</code> | | <code>"App Name"</code> |
| **`returnURL`** | <code>string</code> | | <code>""</code> |
| **`style`** | <code>'alwaysLight' \| 'alwaysDark'</code> | iOS Only | <code>undefined</code> |
| **`withZipCode`** | <code>boolean</code> | Platform: Web only Show ZIP code field. | <code>true</code> |

Expand All @@ -716,11 +734,19 @@ initialize(opts: StripeInitializationOptions) => Promise<void>
| **`stripeAccount`** | <code>string</code> | Optional. Making API calls for connected accounts |


#### StripeURLHandlingOptions

| Prop | Type |
| --------- | ------------------- |
| **`url`** | <code>string</code> |


#### StripePlugin

| Method | Signature |
| -------------- | -------------------------------------------------------------------------------------------------------- |
| **initialize** | (opts: <a href="#stripeinitializationoptions">StripeInitializationOptions</a>) =&gt; Promise&lt;void&gt; |
| Method | Signature | Description |
| --------------------- | -------------------------------------------------------------------------------------------------------- | ----------- |
| **initialize** | (opts: <a href="#stripeinitializationoptions">StripeInitializationOptions</a>) =&gt; Promise&lt;void&gt; | |
| **handleURLCallback** | (opts: <a href="#stripeurlhandlingoptions">StripeURLHandlingOptions</a>) =&gt; Promise&lt;void&gt; | iOS Only |


#### CapacitorStripeContext
Expand Down
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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?

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"
Expand Down Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions ios/Plugin/PaymentFlow/PaymentFlowExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
5 changes: 5 additions & 0 deletions ios/Plugin/PaymentSheet/PaymentSheetExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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" {
Expand Down
1 change: 1 addition & 0 deletions ios/Plugin/StripePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions ios/Plugin/StripePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

}
}


}

@objc func createPaymentSheet(_ call: CAPPluginCall) {
self.paymentSheetExecutor.createPaymentSheet(call)
}
Expand Down
9 changes: 9 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ type StripeDefinitions = PaymentSheetDefinitions & PaymentFlowDefinitions & Appl

export interface StripePlugin extends StripeDefinitions {
initialize(opts: StripeInitializationOptions): Promise<void>;
/**
* iOS Only
* @url https://stripe.com/docs/payments/3d-secure#return-url
*/
handleURLCallback?(opts: StripeURLHandlingOptions): Promise<void>;
}

export interface StripeInitializationOptions {
Expand All @@ -25,6 +30,10 @@ export interface StripeInitializationOptions {
stripeAccount?: string;
}

export interface StripeURLHandlingOptions {
url: string;
}

export interface CapacitorStripeContext {
stripe: StripePlugin;
isApplePayAvailable: boolean;
Expand Down
6 changes: 6 additions & 0 deletions src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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
Expand Down