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 #10 from BohdanRybakEk/master
Browse files Browse the repository at this point in the history
Add requestPayPalBillingAgreement method
  • Loading branch information
vasylnahuliak authored Sep 10, 2021
2 parents f381db2 + 6679a32 commit 8891e3e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.braintreepayments.api.PayPalCheckoutRequest;
import com.braintreepayments.api.PayPalClient;
import com.braintreepayments.api.PayPalPaymentIntent;
import com.braintreepayments.api.PayPalVaultRequest;
import com.braintreepayments.api.PaymentMethodNonce;
import com.braintreepayments.api.ThreeDSecureAdditionalInformation;
import com.braintreepayments.api.ThreeDSecureClient;
Expand Down Expand Up @@ -157,6 +158,40 @@ public void showPayPalModule(final ReadableMap parameters, final Promise promise
}
}

@ReactMethod
public void requestPayPalBillingAgreement(
final ReadableMap parameters,
final Promise promise
) {
mPromise = promise;

if (!parameters.hasKey("clientToken")) {
promise.reject("MISSING_CLIENT_TOKEN", "You must provide a clientToken");
}

setup(parameters.getString("clientToken"));

String description = parameters.hasKey("description") ?
parameters.getString("description") :
"";
String localeCode = parameters.hasKey("localeCode") ?
parameters.getString("localeCode") :
"US";

if (mCurrentActivity != null) {
mPayPalClient = new PayPalClient(mBraintreeClient);
PayPalVaultRequest request = new PayPalVaultRequest();
request.setLocaleCode(localeCode);
request.setBillingAgreementDescription(description);

mPayPalClient.tokenizePayPalAccount(
mCurrentActivity,
request,
e -> handlePayPalResult(null, e));
}

}

private void handlePayPalResult(
@Nullable PayPalAccountNonce payPalAccountNonce,
@Nullable Exception error
Expand Down Expand Up @@ -335,7 +370,7 @@ public void run3DSecureCheck(final ReadableMap parameters, final Promise promise
mCurrentActivity,
threeDSecureRequest,
(threeDSecureResult, error) -> {
if(error != null){
if (error != null) {
handleError(error);
return;
}
Expand Down
7 changes: 7 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ declare module '@ekreative/react-native-braintree' {
companyName: string;
}

interface PayPalBillingAgreementOptions {
clientToken: string;
description: string;
localeCode: string;
}

// Export

interface RNBraintreeModule {
Expand All @@ -48,6 +54,7 @@ declare module '@ekreative/react-native-braintree' {
): Promise<BraintreeResponse>;
tokenizeCard(options: TokenizeCardOptions): Promise<BraintreeResponse>;
runApplePay(options: RunApplePayOptions): Promise<BraintreeResponse>;
requestPayPalBillingAgreement(options: PayPalBillingAgreementOptions): Promise<BraintreeResponse>;
}

const RNBraintree: RNBraintreeModule;
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export default {
run3DSecureCheck: RNBraintree.run3DSecureCheck,
tokenizeCard: RNBraintree.tokenizeCard,
runApplePay: RNBraintreeApplePay && RNBraintreeApplePay.runApplePay,
requestPayPalBillingAgreement: RNBraintree.requestPayPalBillingAgreement,
}

0 comments on commit 8891e3e

Please sign in to comment.