Skip to content

Commit

Permalink
Resolve deviceData nil on BTDropInResult (#378)
Browse files Browse the repository at this point in the history
* resolve deviceData nil on BTDropInResult and update PayPal tests to use the mocked PayPal flow
  • Loading branch information
jaxdesmarais authored Aug 10, 2022
1 parent a96fd9f commit 55087f9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 9 additions & 2 deletions Demo/Application/DemoContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions Demo/Application/Settings/DemoSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions Demo/UITests/BraintreeDropIn_UITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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"])
Expand Down
17 changes: 15 additions & 2 deletions Sources/BraintreeDropIn/Models/BTDropInResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 55087f9

Please sign in to comment.