Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve deviceData nil on BTDropInResult #378

Merged
merged 3 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
Comment on lines +46 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wild. So the test was injecting a definition for PayPalDataCollectorClass? So glad we're moving to Swift lol.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the test was setting a class, but the actual implementation never was - so tests were passing with the mock class being injected and the live code was returning nil for the past year 😢 Swift will certainly help us catch these cases sooner!

}

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