From ef23bd39c2b37476f5383d7b4ad0b7ceb2c1cf7d Mon Sep 17 00:00:00 2001 From: DS Boyce Date: Fri, 2 Aug 2024 11:12:20 -0700 Subject: [PATCH 1/3] Feature: Add userAction option to showPayPalModule --- README.md | 4 +++- .../reactnativebraintree/RNBraintreeModule.java | 3 +++ index.d.ts | 9 ++++++++- ios/RNBraintree.m | 4 ++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8cb23bd..67aa4fb 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,9 @@ import RNBraintree from '@ekreative/react-native-braintree'; RNBraintree.showPayPalModule({ clientToken: 'CLIENT_TOKEN_GENERATED_ON_SERVER_SIDE', amount: '1.0', - currencyCode: 'EUR' + currencyCode: 'EUR', + // Change button text to “Complete Purchase", optional + userAction: 'commit', }) .then(result => console.log(result)) .catch((error) => console.log(error)); diff --git a/android/src/main/java/com/ekreative/reactnativebraintree/RNBraintreeModule.java b/android/src/main/java/com/ekreative/reactnativebraintree/RNBraintreeModule.java index 48b7bd8..4244b89 100644 --- a/android/src/main/java/com/ekreative/reactnativebraintree/RNBraintreeModule.java +++ b/android/src/main/java/com/ekreative/reactnativebraintree/RNBraintreeModule.java @@ -143,6 +143,9 @@ public void showPayPalModule(final ReadableMap parameters, final Promise promise if (parameters.hasKey("currencyCode")) { currency = parameters.getString("currencyCode"); } + if (parameters.hasKey("userAction") && PayPalCheckoutRequest.USER_ACTION_COMMIT.equals(parameters.getString("userAction"))) { + request.setUserAction(PayPalCheckoutRequest.USER_ACTION_COMMIT); + } if (mCurrentActivity != null) { mPayPalClient = new PayPalClient(mBraintreeClient); PayPalCheckoutRequest request = new PayPalCheckoutRequest( diff --git a/index.d.ts b/index.d.ts index bda9ce2..7602830 100644 --- a/index.d.ts +++ b/index.d.ts @@ -10,6 +10,13 @@ declare module '@ekreative/react-native-braintree' { currencyCode: string; } + export interface PayPalOptions { + clientToken: string; + amount: string; + currencyCode: string; + userAction?: 'commit' | ''; + } + export interface Run3DSecureCheckOptions extends Omit { nonce: string; @@ -50,7 +57,7 @@ declare module '@ekreative/react-native-braintree' { // Export interface RNBraintreeModule { - showPayPalModule(options: BraintreeOptions): Promise; + showPayPalModule(options: PayPalOptions): Promise; runGooglePay(options: BraintreeOptions): Promise; run3DSecureCheck( options: Run3DSecureCheckOptions, diff --git a/ios/RNBraintree.m b/ios/RNBraintree.m index 60e8a86..745dd74 100644 --- a/ios/RNBraintree.m +++ b/ios/RNBraintree.m @@ -50,6 +50,7 @@ @implementation RNBraintree rejecter: (RCTPromiseRejectBlock)reject) { NSString *clientToken = options[@"clientToken"]; NSString *description = options[@"description"]; + NSString *userAction = options[@"userAction"]; self.apiClient = [[BTAPIClient alloc] initWithAuthorization: clientToken]; self.dataCollector = [[BTDataCollector alloc] initWithAPIClient:self.apiClient]; @@ -59,6 +60,9 @@ @implementation RNBraintree if (description) { request.billingAgreementDescription = description; } + if (userAction && [@"commit" isEqualToString:userAction]) { + request.userAction = BTPayPalRequestUserActionCommit; + } [payPalDriver tokenizePayPalAccountWithPayPalRequest:request completion:^(BTPayPalAccountNonce * _Nullable tokenizedPayPalAccount, NSError * _Nullable error) { if (error) { reject(@"REQUEST_BILLING_AGREEMENT_FAILED", error.localizedDescription, nil); From 901732d4781cf0ade77075653147c5e24bc35cae Mon Sep 17 00:00:00 2001 From: DS Boyce Date: Mon, 12 Aug 2024 10:12:19 -0700 Subject: [PATCH 2/3] Improve JS API per code review --- index.d.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/index.d.ts b/index.d.ts index 7602830..a131dea 100644 --- a/index.d.ts +++ b/index.d.ts @@ -10,13 +10,6 @@ declare module '@ekreative/react-native-braintree' { currencyCode: string; } - export interface PayPalOptions { - clientToken: string; - amount: string; - currencyCode: string; - userAction?: 'commit' | ''; - } - export interface Run3DSecureCheckOptions extends Omit { nonce: string; @@ -48,6 +41,10 @@ declare module '@ekreative/react-native-braintree' { companyName: string; } + export interface PayPalOptions extends BraintreeOptions { + userAction?: 'commit' | null; + } + export interface PayPalBillingAgreementOptions { clientToken: string; description?: string; From f76f2edd7bc3109cacf8b0ddfb09de7d0d2245d9 Mon Sep 17 00:00:00 2001 From: DS Boyce Date: Mon, 12 Aug 2024 10:12:56 -0700 Subject: [PATCH 3/3] Simply make userAction optional --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index a131dea..2600cff 100644 --- a/index.d.ts +++ b/index.d.ts @@ -42,7 +42,7 @@ declare module '@ekreative/react-native-braintree' { } export interface PayPalOptions extends BraintreeOptions { - userAction?: 'commit' | null; + userAction?: 'commit'; } export interface PayPalBillingAgreementOptions {