Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #90 from ShortboxedInc/paypal-paramaters
Browse files Browse the repository at this point in the history
Feature: Add userAction option to showPayPalModule
  • Loading branch information
vasylnahuliak authored Aug 14, 2024
2 parents abe2151 + f76f2ed commit b705785
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -50,7 +54,7 @@ declare module '@ekreative/react-native-braintree' {
// Export

interface RNBraintreeModule {
showPayPalModule(options: BraintreeOptions): Promise<BraintreeResponse>;
showPayPalModule(options: PayPalOptions): Promise<BraintreeResponse>;
runGooglePay(options: BraintreeOptions): Promise<BraintreeResponse>;
run3DSecureCheck(
options: Run3DSecureCheckOptions,
Expand Down
4 changes: 4 additions & 0 deletions ios/RNBraintree.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
Expand Down

0 comments on commit b705785

Please sign in to comment.