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

[OPEN DEV] Add Custom Authorization Setting #1426

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions Demo/Application/Base/ContainmentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,21 @@ class ContainmentViewController: UIViewController {
tokenizationKey = "sandbox_9dbg82cq_dcpspy2brwdjr3qn"
case .production:
tokenizationKey = "production_t2wns2y2_dfy45jdj3dxkmz5m"
default:
tokenizationKey = "development_testing_integration_merchant_id"
case .custom:
// swiftlint:disable:next force_unwrapping
tokenizationKey = UserDefaults.standard.string(forKey: "BraintreeDemoSettingsCustomAuthorizationKey")!
}

currentViewController = instantiateViewController(with: tokenizationKey)

case .clientToken:
updateStatus("Fetching Client Token...")

if BraintreeDemoSettings.currentEnvironment == .custom {
updateStatus("Switch the Authorization Type in settings to Tokenization Key to use the custom environment")
return
}

BraintreeDemoMerchantAPIClient.shared.createCustomerAndFetchClientToken { clientToken, error in
if let error {
self.updateStatus(error.localizedDescription)
Expand Down
15 changes: 3 additions & 12 deletions Demo/Application/Base/Settings/BraintreeDemoSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BraintreeDemoSettings: NSObject {

static let EnvironmentDefaultsKey = "BraintreeDemoSettingsEnvironmentDefaultsKey"
static let AuthorizationTypeDefaultsKey = "BraintreeDemoSettingsAuthorizationTypeKey"
static let CustomEnvironmentURLDefaultsKey = "BraintreeDemoSettingsCustomEnvironmentURLDefaultsKey"
static let CustomAuthorizationDefaultsKey = "BraintreeDemoSettingsCustomAuthorizationKey"
static let ThreeDSecureRequiredDefaultsKey = "BraintreeDemoSettingsThreeDSecureRequiredDefaultsKey"

static var currentEnvironment: BraintreeDemoEnvironment {
Expand All @@ -35,28 +35,19 @@ class BraintreeDemoSettings: NSObject {

static var currentEnvironmentName: String {
switch currentEnvironment {
case .sandbox:
case .sandbox, .custom:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now I have this set up to hit sandbox since that seemed like what we would hit the most. Could also consider building logic to parse the first part of the environment from the tokenization key if folks think we may also want to use this for prod testing. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Worth noting on the Braintree Gateway side stage routes through sandbox as well.

return "Sandbox"
case .production:
return "Production"
case .custom:
guard var name = UserDefaults.standard.string(forKey: CustomEnvironmentURLDefaultsKey) else {
return "(invalid)"
}
name = name.replacingOccurrences(of: "http://", with: "")
name = name.replacingOccurrences(of: "https://", with: "")
return name
}
}

static var currentEnvironmentURLString: String {
switch currentEnvironment {
case .sandbox:
case .sandbox, .custom:
return "https://braintree-sample-merchant.herokuapp.com"
case .production:
return "https://executive-sample-merchant.herokuapp.com"
case .custom:
return UserDefaults.standard.string(forKey: EnvironmentDefaultsKey) ?? ""
}
}

Expand Down
8 changes: 4 additions & 4 deletions Demo/Application/Base/Settings/Settings.bundle/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@
<array>
<string>Sandbox</string>
<string>Production</string>
<string>Custom (enter below)</string>
<string>Custom</string>
</array>
<key>Titles</key>
<array>
<string>Sandbox</string>
<string>Production</string>
<string>Custom (URL on previous screen)</string>
<string>Custom</string>
</array>
<key>Values</key>
<array>
Expand All @@ -78,9 +78,9 @@
<key>Type</key>
<string>PSTextFieldSpecifier</string>
<key>Title</key>
<string>Custom Base URL</string>
<string>Custom Authorization</string>
<key>Key</key>
<string>BraintreeDemoSettingsCustomEnvironmentURLDefaultsKey</string>
<string>BraintreeDemoSettingsCustomAuthorizationKey</string>
<key>IASKTextAlignment</key>
<string>IASKUITextAlignmentRight</string>
</dict>
Expand Down
Loading