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..2600cff 100644 --- a/index.d.ts +++ b/index.d.ts @@ -41,6 +41,10 @@ declare module '@ekreative/react-native-braintree' { companyName: string; } + export interface PayPalOptions extends BraintreeOptions { + userAction?: 'commit'; + } + export interface PayPalBillingAgreementOptions { clientToken: string; description?: string; @@ -50,7 +54,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);