Skip to content

Commit

Permalink
PR-37240: add support for 3DSecure billing address and vaultCardDefau…
Browse files Browse the repository at this point in the history
…ltValue for ios and android (#1)
  • Loading branch information
jmarente authored Aug 22, 2024
1 parent a3b7e8a commit 745e39b
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
Expand Down
42 changes: 42 additions & 0 deletions ios/RNBraintreeDropIn.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "RNBraintreeDropIn.h"
#import <React/RCTUtils.h>
#import "BTThreeDSecureRequest.h"
#import "BTThreeDSecurePostalAddress.h"

@implementation RNBraintreeDropIn

Expand Down Expand Up @@ -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;

}
Expand All @@ -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;
}
Expand Down

0 comments on commit 745e39b

Please sign in to comment.