diff --git a/CHANGELOG.md b/CHANGELOG.md index 92b14d2c..c25b7d0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Braintree iOS Drop-in SDK - Release Notes +## unreleased +* Fix bug where `deviceData` on `BTDropInResult` was always returned as `nil` + ## 9.6.0 (2022-05-24) * Require `braintree_ios` 5.9.0 or higher * Update device data collection for environment based on configuration diff --git a/Demo/Application/DemoContainerViewController.swift b/Demo/Application/DemoContainerViewController.swift index 3abe39cf..d5a100b2 100644 --- a/Demo/Application/DemoContainerViewController.swift +++ b/Demo/Application/DemoContainerViewController.swift @@ -92,10 +92,17 @@ class DemoContainerViewController: UIViewController { if let auth = DemoSettings.authorizationOverride { currentViewController = instantiateCurrentViewController(with: auth) - } else if DemoSettings.useTokenizationKey { + } else if DemoSettings.useMockedPayPalFlow { updateStatusItem("Using Tokenization Key") - + let tokenizationKey: String + + tokenizationKey = "sandbox_q7v35n9n_555d2htrfsnnmfb3" + currentViewController = instantiateCurrentViewController(with: tokenizationKey) + } + else if DemoSettings.useTokenizationKey { + let tokenizationKey: String + switch DemoSettings.currentEnvironment { case .sandbox: tokenizationKey = "sandbox_9dbg82cq_dcpspy2brwdjr3qn" diff --git a/Demo/Application/Settings/DemoSettings.swift b/Demo/Application/Settings/DemoSettings.swift index 431adf66..13ed8808 100644 --- a/Demo/Application/Settings/DemoSettings.swift +++ b/Demo/Application/Settings/DemoSettings.swift @@ -25,6 +25,10 @@ class DemoSettings { static let ThreeDSecureRequiredDefaultsKey = "BraintreeDemoSettingsThreeDSecureRequiredDefaultsKey" static let ThreeDSecureVersionDefaultsKey = "BraintreeDemoSettingsThreeDSecureVersionDefaultsKey" + static var useMockedPayPalFlow: Bool { + ProcessInfo.processInfo.arguments.contains("-UseMockedPayPalFlow") + } + static var currentUIFramework: DemoUIFramework { return DemoUIFramework(rawValue: UserDefaults.standard.integer(forKey: UIFrameworkDefaultsKey)) ?? DemoUIFramework.uikit } diff --git a/Demo/UITests/BraintreeDropIn_UITests.swift b/Demo/UITests/BraintreeDropIn_UITests.swift index 33a8dd21..3cbf329e 100644 --- a/Demo/UITests/BraintreeDropIn_UITests.swift +++ b/Demo/UITests/BraintreeDropIn_UITests.swift @@ -558,6 +558,7 @@ class BraintreeDropIn_PayPal_UITests: XCTestCase { app = XCUIApplication() app.launchArguments.append("-EnvironmentSandbox") app.launchArguments.append("-TokenizationKey") + app.launchArguments.append("-UseMockedPayPalFlow") app.launch() sleep(1) waitForElementToBeHittable(app.buttons["Add Payment Method"]) @@ -637,6 +638,7 @@ class BraintreeDropIn_PayPal_OneTime_UITests: XCTestCase { app.launchArguments.append("-EnvironmentSandbox") app.launchArguments.append("-PayPalOneTime") app.launchArguments.append("-TokenizationKey") + app.launchArguments.append("-UseMockedPayPalFlow") app.launch() sleep(1) waitForElementToBeHittable(app.buttons["Add Payment Method"]) diff --git a/Sources/BraintreeDropIn/Models/BTDropInResult.m b/Sources/BraintreeDropIn/Models/BTDropInResult.m index 2fa0587e..521f91fe 100644 --- a/Sources/BraintreeDropIn/Models/BTDropInResult.m +++ b/Sources/BraintreeDropIn/Models/BTDropInResult.m @@ -42,7 +42,13 @@ @implementation BTDropInResult - (instancetype)init { self = [super init]; if (self) { - _deviceData = [PayPalDataCollectorClass collectPayPalDeviceData]; + // If we are testing we want to set PayPalDataCollectorClass to the class passed in `setPayPalDataCollectorClass` + if (PayPalDataCollectorClass != NSClassFromString(PayPalDataCollectorClassString)) { + _deviceData = [PayPalDataCollectorClass collectPayPalDeviceData]; + return self; + } + // Otherwise we should use `PPDataCollector` to collect device data + _deviceData = [PPDataCollector collectPayPalDeviceData]; } return self; @@ -51,8 +57,15 @@ - (instancetype)init { - (instancetype)initWithEnvironment:(NSString *)environment { self = [super init]; if (self) { + // If we are testing we want to set PayPalDataCollectorClass to the class passed in `setPayPalDataCollectorClass` + if (PayPalDataCollectorClass != NSClassFromString(PayPalDataCollectorClassString)) { + BOOL isSandbox = [environment isEqualToString:@"sandbox"]; + _deviceData = [PayPalDataCollectorClass collectPayPalDeviceDataWithIsSandbox:isSandbox]; + return self; + } + // Otherwise we should use `PPDataCollector` to collect device data BOOL isSandbox = [environment isEqualToString:@"sandbox"]; - _deviceData = [PayPalDataCollectorClass collectPayPalDeviceDataWithIsSandbox:isSandbox]; + _deviceData = [PPDataCollector collectPayPalDeviceDataWithIsSandbox:isSandbox]; } return self;