Skip to content

Commit

Permalink
chore: update Braintree iOS SDK to v5
Browse files Browse the repository at this point in the history
  • Loading branch information
mlazari committed Jan 4, 2023
1 parent 96910b2 commit 0b4977c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ react-native link react-native-braintree-dropin-ui

#### iOS specific

You must have a iOS deployment target \>= 9.0.
You must have a iOS deployment target \>= 12.0.

If you don't have a Podfile or are unsure on how to proceed, see the [CocoaPods][1] usage guide.

Expand Down
12 changes: 6 additions & 6 deletions RNBraintreeDropIn.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Pod::Spec.new do |s|
s.license = "MIT"
# s.license = { :type => "MIT", :file => "./LICENSE" }
s.author = { "author" => "[email protected]" }
s.platform = :ios, "9.0"
s.platform = :ios, "12.0"
s.source = { :git => "https://github.com/BradyShober/react-native-braintree-dropin-ui.git", :tag => "master" }
s.source_files = "ios/**/*.{h,m}"
s.requires_arc = true
s.dependency 'React'
s.dependency 'Braintree'
s.dependency 'BraintreeDropIn'
s.dependency 'Braintree/DataCollector'
s.dependency 'Braintree/Apple-Pay'
s.dependency 'Braintree/Venmo'
s.dependency 'Braintree', '5.17.0'
s.dependency 'BraintreeDropIn', '9.7.0'
s.dependency 'Braintree/DataCollector', '5.17.0'
s.dependency 'Braintree/ApplePay', '5.17.0'
s.dependency 'Braintree/Venmo', '5.17.0'
end
4 changes: 2 additions & 2 deletions ios/RNBraintreeDropIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#import "BraintreeApplePay.h"

@interface RNBraintreeDropIn : NSObject <RCTBridgeModule>
@interface RNBraintreeDropIn : NSObject <RCTBridgeModule, PKPaymentAuthorizationViewControllerDelegate>

@property (nonatomic, strong) UIViewController *_Nonnull reactRoot;

Expand All @@ -33,7 +33,7 @@

@property (nonatomic) RCTPromiseRejectBlock _Nonnull reject;

@property (nonatomic, assign) BOOL *_Nonnull applePayAuthorized;
@property (nonatomic, assign) BOOL applePayAuthorized;

+ (void)resolvePayment:(BTDropInResult* _Nullable)result deviceData:(NSString * _Nonnull)deviceDataCollector resolver:(RCTPromiseResolveBlock _Nonnull)resolve;

Expand Down
29 changes: 16 additions & 13 deletions ios/RNBraintreeDropIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@ - (dispatch_queue_t)methodQueue

RCT_EXPORT_METHOD(show:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{

BTDropInColorScheme colorScheme;

if([options[@"darkTheme"] boolValue]){
if (@available(iOS 13.0, *)) {
BTUIKAppearance.sharedInstance.colorScheme = BTUIKColorSchemeDynamic;
colorScheme = BTDropInColorSchemeDynamic;
} else {
BTUIKAppearance.sharedInstance.colorScheme = BTUIKColorSchemeDark;
colorScheme = BTDropInColorSchemeDark;
}
} else {
BTUIKAppearance.sharedInstance.colorScheme = BTUIKColorSchemeLight;
colorScheme = BTDropInColorSchemeLight;
}

BTDropInUICustomization *uiCustomization = [[BTDropInUICustomization alloc] initWithColorScheme:colorScheme];

if(options[@"fontFamily"]){
[BTUIKAppearance sharedInstance].fontFamily = options[@"fontFamily"];
uiCustomization.fontFamily = options[@"fontFamily"];
}
if(options[@"boldFontFamily"]){
[BTUIKAppearance sharedInstance].boldFontFamily = options[@"boldFontFamily"];
uiCustomization.boldFontFamily = options[@"boldFontFamily"];
}

self.resolve = resolve;
Expand All @@ -41,6 +44,7 @@ - (dispatch_queue_t)methodQueue
}

BTDropInRequest *request = [[BTDropInRequest alloc] init];
request.uiCustomization = uiCustomization;

NSDictionary* threeDSecureOptions = options[@"threeDSecure"];
if (threeDSecureOptions) {
Expand All @@ -50,7 +54,6 @@ - (dispatch_queue_t)methodQueue
return;
}

request.threeDSecureVerification = YES;
BTThreeDSecureRequest *threeDSecureRequest = [[BTThreeDSecureRequest alloc] init];
threeDSecureRequest.amount = [NSDecimalNumber decimalNumberWithString:threeDSecureAmount.stringValue];
request.threeDSecureRequest = threeDSecureRequest;
Expand All @@ -59,7 +62,7 @@ - (dispatch_queue_t)methodQueue

BTAPIClient *apiClient = [[BTAPIClient alloc] initWithAuthorization:clientToken];
self.dataCollector = [[BTDataCollector alloc] initWithAPIClient:apiClient];
[self.dataCollector collectCardFraudData:^(NSString * _Nonnull deviceDataCollector) {
[self.dataCollector collectDeviceData:^(NSString * _Nonnull deviceDataCollector) {
// Save deviceData
self.deviceDataCollector = deviceDataCollector;
}];
Expand Down Expand Up @@ -113,7 +116,7 @@ - (dispatch_queue_t)methodQueue

if (error != nil) {
reject(error.localizedDescription, error.localizedDescription, error);
} else if (result.cancelled) {
} else if (result.canceled) {
reject(@"USER_CANCELLATION", @"The user cancelled", nil);
} else {
if (threeDSecureOptions && [result.paymentMethod isKindOfClass:[BTCardNonce class]]) {
Expand All @@ -125,7 +128,7 @@ - (dispatch_queue_t)methodQueue
} else{
[[self class] resolvePayment:result deviceData:self.deviceDataCollector resolver:resolve];
}
} else if(result.paymentMethod == nil && (result.paymentOptionType == 16 || result.paymentOptionType == 18)){ //Apple Pay
} else if(result.paymentMethod == nil && (result.paymentMethodType == 16 || result.paymentMethodType == 18)){ //Apple Pay
// UIViewController *ctrl = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
// [ctrl presentViewController:self.viewController animated:YES completion:nil];
UIViewController *rootViewController = RCTPresentedViewController();
Expand All @@ -145,7 +148,7 @@ - (dispatch_queue_t)methodQueue

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
didAuthorizePayment:(PKPayment *)payment
completion:(void (^)(PKPaymentAuthorizationStatus))completion
handler:(nonnull void (^)(PKPaymentAuthorizationResult * _Nonnull))completion
{

// Example: Tokenize the Apple Pay payment
Expand All @@ -159,7 +162,7 @@ - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController
// If applicable, address information is accessible in `payment`.
// NSLog(@"description = %@", tokenizedApplePayPayment.localizedDescription);

completion(PKPaymentAuthorizationStatusSuccess);
completion([[PKPaymentAuthorizationResult alloc] initWithStatus:PKPaymentAuthorizationStatusSuccess errors:nil]);
self.applePayAuthorized = YES;


Expand All @@ -176,7 +179,7 @@ - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController
// Tokenization failed. Check `error` for the cause of the failure.

// Indicate failure via the completion callback:
completion(PKPaymentAuthorizationStatusFailure);
completion([[PKPaymentAuthorizationResult alloc] initWithStatus:PKPaymentAuthorizationStatusFailure errors:nil]);
}
}];
}
Expand Down
8 changes: 4 additions & 4 deletions ios/RNBraintreeDropIn.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -207,7 +207,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand All @@ -230,7 +230,7 @@
"$(PODS_ROOT)/Braintree/**",
"$(PODS_ROOT)/BraintreeDropIn/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
PODS_ROOT = "${SRCROOT}/../../../ios/Pods";
Expand All @@ -255,7 +255,7 @@
"$(PODS_ROOT)/Braintree/**",
"$(PODS_ROOT)/BraintreeDropIn/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
PODS_ROOT = "${SRCROOT}/../../../ios/Pods";
Expand Down

0 comments on commit 0b4977c

Please sign in to comment.