From 745e39b97d8dbf8a014f66da0053b135eb0cbd48 Mon Sep 17 00:00:00 2001 From: Jose Marente Date: Thu, 22 Aug 2024 10:43:57 +0200 Subject: [PATCH] PR-37240: add support for 3DSecure billing address and vaultCardDefaultValue for ios and android (#1) --- .../RNBraintreeDropInModule.java | 50 ++++++++++++++++++- ios/RNBraintreeDropIn.m | 42 ++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/tech/power/RNBraintreeDropIn/RNBraintreeDropInModule.java b/android/src/main/java/tech/power/RNBraintreeDropIn/RNBraintreeDropInModule.java index 9d8a9dd..029b0d9 100644 --- a/android/src/main/java/tech/power/RNBraintreeDropIn/RNBraintreeDropInModule.java +++ b/android/src/main/java/tech/power/RNBraintreeDropIn/RNBraintreeDropInModule.java @@ -25,6 +25,7 @@ import com.braintreepayments.api.PaymentMethodNonce; import com.braintreepayments.api.CardNonce; import com.braintreepayments.api.ThreeDSecureInfo; +import com.braintreepayments.api.ThreeDSecurePostalAddress; import com.braintreepayments.api.GooglePayRequest; import com.google.android.gms.wallet.TransactionInfo; import com.google.android.gms.wallet.WalletConstants; @@ -71,6 +72,10 @@ public void show(final ReadableMap options, final Promise promise) { dropInRequest.setVaultManagerEnabled(options.getBoolean("vaultManager")); } + if(options.hasKey("vaultCardDefaultValue")) { + dropInRequest.setVaultCardDefaultValue(options.getBoolean("vaultCardDefaultValue")); + } + if(options.hasKey("googlePay") && options.getBoolean("googlePay")){ GooglePayRequest googlePayRequest = new GooglePayRequest(); googlePayRequest.setTransactionInfo(TransactionInfo.newBuilder() @@ -99,9 +104,52 @@ public void show(final ReadableMap options, final Promise promise) { } isVerifyingThreeDSecure = true; - ThreeDSecureRequest threeDSecureRequest = new ThreeDSecureRequest(); threeDSecureRequest.setAmount(threeDSecureOptions.getString("amount")); + threeDSecureRequest.setVersionRequested(ThreeDSecureRequest.VERSION_2); + + if (threeDSecureOptions.hasKey("billingAddress")) { + final ReadableMap threeDSecureBillingAddress = threeDSecureOptions.getMap("billingAddress"); + ThreeDSecurePostalAddress billingAddress = new ThreeDSecurePostalAddress(); + + if (threeDSecureBillingAddress.hasKey("givenName")) { + billingAddress.setGivenName(threeDSecureBillingAddress.getString("givenName")); + } + + if (threeDSecureBillingAddress.hasKey("surname")) { + billingAddress.setSurname(threeDSecureBillingAddress.getString("surname")); + } + + if (threeDSecureBillingAddress.hasKey("streetAddress")) { + billingAddress.setStreetAddress(threeDSecureBillingAddress.getString("streetAddress")); + } + + if (threeDSecureBillingAddress.hasKey("extendedAddress")) { + billingAddress.setExtendedAddress(threeDSecureBillingAddress.getString("extendedAddress")); + } + + if (threeDSecureBillingAddress.hasKey("locality")) { + billingAddress.setLocality(threeDSecureBillingAddress.getString("locality")); + } + + if (threeDSecureBillingAddress.hasKey("region")) { + billingAddress.setRegion(threeDSecureBillingAddress.getString("region")); + } + + if (threeDSecureBillingAddress.hasKey("countryCodeAlpha2")) { + billingAddress.setCountryCodeAlpha2(threeDSecureBillingAddress.getString("countryCodeAlpha2")); + } + + if (threeDSecureBillingAddress.hasKey("postalCode")) { + billingAddress.setPostalCode(threeDSecureBillingAddress.getString("postalCode")); + } + + if (threeDSecureBillingAddress.hasKey("phoneNumber")) { + billingAddress.setPhoneNumber(threeDSecureBillingAddress.getString("phoneNumber")); + } + + threeDSecureRequest.setBillingAddress(billingAddress); + } dropInRequest.setThreeDSecureRequest(threeDSecureRequest); } diff --git a/ios/RNBraintreeDropIn.m b/ios/RNBraintreeDropIn.m index 07df5d3..d555392 100644 --- a/ios/RNBraintreeDropIn.m +++ b/ios/RNBraintreeDropIn.m @@ -1,6 +1,7 @@ #import "RNBraintreeDropIn.h" #import #import "BTThreeDSecureRequest.h" +#import "BTThreeDSecurePostalAddress.h" @implementation RNBraintreeDropIn @@ -56,6 +57,42 @@ - (dispatch_queue_t)methodQueue BTThreeDSecureRequest *threeDSecureRequest = [[BTThreeDSecureRequest alloc] init]; threeDSecureRequest.amount = [NSDecimalNumber decimalNumberWithString:threeDSecureAmount.stringValue]; + threeDSecureRequest.versionRequested = BTThreeDSecureVersion2; + + NSDictionary* threeDSecureBillingAddress = threeDSecureOptions[@"billingAddress"]; + if(threeDSecureBillingAddress){ + BTThreeDSecurePostalAddress *billingAddress = [BTThreeDSecurePostalAddress new]; + + if(threeDSecureBillingAddress[@"givenName"]){ + billingAddress.givenName = threeDSecureBillingAddress[@"givenName"]; + } + if(threeDSecureBillingAddress[@"surname"]){ + billingAddress.surname = threeDSecureBillingAddress[@"surname"]; + } + if(threeDSecureBillingAddress[@"streetAddress"]){ + billingAddress.streetAddress = threeDSecureBillingAddress[@"streetAddress"]; + } + if(threeDSecureBillingAddress[@"extendedAddress"]){ + billingAddress.extendedAddress = threeDSecureBillingAddress[@"extendedAddress"]; + } + if(threeDSecureBillingAddress[@"locality"]){ + billingAddress.locality = threeDSecureBillingAddress[@"locality"]; + } + if(threeDSecureBillingAddress[@"region"]){ + billingAddress.region = threeDSecureBillingAddress[@"region"]; + } + if(threeDSecureBillingAddress[@"countryCodeAlpha2"]){ + billingAddress.countryCodeAlpha2 = threeDSecureBillingAddress[@"countryCodeAlpha2"]; + } + if(threeDSecureBillingAddress[@"postalCode"]){ + billingAddress.postalCode = threeDSecureBillingAddress[@"postalCode"]; + } + if(threeDSecureBillingAddress[@"phoneNumber"]){ + billingAddress.phoneNumber = threeDSecureBillingAddress[@"phoneNumber"]; + } + threeDSecureRequest.billingAddress = billingAddress; + } + request.threeDSecureRequest = threeDSecureRequest; } @@ -71,6 +108,11 @@ - (dispatch_queue_t)methodQueue request.vaultManager = YES; } + if (![options[@"vaultCardDefaultValue"] boolValue]) { + request.vaultCard = NO; + } + + if([options[@"cardDisabled"] boolValue]){ request.cardDisabled = YES; }