Skip to content

Commit

Permalink
update all feature VCs with updated base ViewControllers
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxdesmarais committed Oct 12, 2023
1 parent e0c115f commit 643d64a
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 157 deletions.
1 change: 1 addition & 0 deletions Demo/Application/Base/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import BraintreeCore

@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {

Expand Down
11 changes: 5 additions & 6 deletions Demo/Application/Base/BraintreeDemoContainmentViewController.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#import "BraintreeDemoContainmentViewController.h"
#import "BraintreeDemoBaseViewController.h"
#import "Demo-Swift.h"
@import InAppSettingsKit;
@import BraintreeCore;
Expand All @@ -9,7 +8,7 @@ @interface BraintreeDemoContainmentViewController () <IASKSettingsDelegate>
@property (nonatomic, strong) UIBarButtonItem *statusItem;
@property (nonatomic, strong) BTPaymentMethodNonce *latestTokenizedPayment;
@property (nonatomic, strong) NSString *latestTokenizedPaymentString;
@property (nonatomic, strong) BraintreeDemoBaseViewController *currentDemoViewController;
@property (nonatomic, strong) BaseViewController *currentDemoViewController;

@end

Expand Down Expand Up @@ -190,7 +189,7 @@ - (void)reloadIntegration {
}
}

- (void)setCurrentDemoViewController:(BraintreeDemoBaseViewController *)currentDemoViewController {
- (void)setCurrentDemoViewController:(BaseViewController *)currentDemoViewController {
_currentDemoViewController = currentDemoViewController;

if (!_currentDemoViewController) {
Expand All @@ -208,18 +207,18 @@ - (void)setCurrentDemoViewController:(BraintreeDemoBaseViewController *)currentD
self.title = _currentDemoViewController.title;
}

- (BraintreeDemoBaseViewController *)instantiateCurrentIntegrationViewControllerWithAuthorization:(NSString *)authorization {
- (BaseViewController *)instantiateCurrentIntegrationViewControllerWithAuthorization:(NSString *)authorization {
NSString *integrationName = [[NSUserDefaults standardUserDefaults] stringForKey:@"BraintreeDemoSettingsIntegration"];
NSLog(@"Loading integration: %@", integrationName);

// The prefix "Demo." is required for integration view controllers written in Swift
Class integrationClass = NSClassFromString(integrationName) ?: NSClassFromString([NSString stringWithFormat:@"Demo.%@", integrationName]);
if (![integrationClass isSubclassOfClass:[BraintreeDemoBaseViewController class]]) {
if (![integrationClass isSubclassOfClass:[BaseViewController class]]) {
NSLog(@"%@ is not a valid BraintreeDemoBaseViewController", integrationName);
return nil;
}

return [(BraintreeDemoBaseViewController *)[integrationClass alloc] initWithAuthorization:authorization];
return [(BaseViewController *)[integrationClass alloc] initWithAuthorization:authorization];
}

- (void)containIntegrationViewController:(UIViewController *)viewController {
Expand Down
1 change: 1 addition & 0 deletions Demo/Application/Base/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import BraintreeCore

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

Expand Down
18 changes: 3 additions & 15 deletions Demo/Application/Features/AmexViewController.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation
import UIKit
import BraintreeAmericanExpress
import BraintreeCard

class AmexViewController: BraintreeDemoPaymentButtonBaseViewController {
class AmexViewController: PaymentButtonBaseViewController {

lazy var amexClient = BTAmericanExpressClient(apiClient: apiClient)
lazy var cardClient = BTCardClient(apiClient: apiClient)
Expand All @@ -12,7 +12,7 @@ class AmexViewController: BraintreeDemoPaymentButtonBaseViewController {
title = "Amex"
}

override func createPaymentButton() -> UIView! {
override func createPaymentButton() -> UIView {
let validCardButton = createButton(title: "Valid card", action: #selector(tappedValidCard))
let insufficientPointsCardButton = createButton(title: "Insufficient points card", action: #selector(tappedInsufficientPointsCard))
let ineligibleCardButton = createButton(title: "Ineligible card", action: #selector(tappedIneligibleCard))
Expand Down Expand Up @@ -72,16 +72,4 @@ class AmexViewController: BraintreeDemoPaymentButtonBaseViewController {
}
}
}

// TODO: move this helper into BraintreeDemoPaymentButtonBaseViewController once converted so all buttons share the same characteristics
private func createButton(title: String, action: Selector) -> UIButton {
let button = UIButton(type: .system)
button.setTitle(title, for: .normal)
button.setTitleColor(.blue, for: .normal)
button.setTitleColor(.lightGray, for: .highlighted)
button.setTitleColor(.lightGray, for: .disabled)
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, action: action, for: .touchUpInside)
return button
}
}
6 changes: 3 additions & 3 deletions Demo/Application/Features/ApplePayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import BraintreeApplePay
import PassKit

class ApplePayViewController: BraintreeDemoPaymentButtonBaseViewController {
class ApplePayViewController: PaymentButtonBaseViewController {

lazy var applePayClient = BTApplePayClient(apiClient: apiClient)

Expand All @@ -12,13 +12,13 @@ class ApplePayViewController: BraintreeDemoPaymentButtonBaseViewController {
title = "Apple Pay"
}

override func createPaymentButton() -> UIView! {
override func createPaymentButton() -> UIView {
if !PKPaymentAuthorizationViewController.canMakePayments() {
progressBlock("canMakePayments returned false, hiding Apple Pay button")
return nil
}

let applePayButton = PKPaymentButton(paymentButtonType: .plain, paymentButtonStyle: .automatic)
applePayButton.translatesAutoresizingMaskIntoConstraints = false
applePayButton.addTarget(self, action: #selector(tappedApplePayButton), for: .touchUpInside)

NSLayoutConstraint.activate([applePayButton.heightAnchor.constraint(equalToConstant: 50)])
Expand Down
20 changes: 5 additions & 15 deletions Demo/Application/Features/CardTokenizationViewController.swift
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import UIKit
import BraintreeCard

class CardTokenizationViewController: BraintreeDemoPaymentButtonBaseViewController {
class CardTokenizationViewController: PaymentButtonBaseViewController {

private let cardFormView = BTCardFormView()
private let autofillButton = UIButton(type: .system)
private var autofillButton = UIButton(type: .system)

override func viewDidLoad() {
super.viewDidLoad()
createSubviews()
layoutConstraints()
}

override func createPaymentButton() -> UIView! {
let submitButton = UIButton(type: .system)
submitButton.setTitle("Submit", for: .normal)
submitButton.setTitleColor(.blue, for: .normal)
submitButton.setTitleColor(.lightGray, for: .highlighted)
submitButton.setTitleColor(.lightGray, for: .disabled)
submitButton.addTarget(self, action: #selector(tappedSubmit), for: .touchUpInside)
submitButton.translatesAutoresizingMaskIntoConstraints = false

override func createPaymentButton() -> UIView {
let submitButton = createButton(title: "Submit", action: #selector(tappedSubmit))
return submitButton
}

Expand Down Expand Up @@ -62,10 +55,7 @@ class CardTokenizationViewController: BraintreeDemoPaymentButtonBaseViewControll
cardFormView.hidePostalCodeField = true
setFieldsEnabled(true)

autofillButton.setTitle("Autofill", for: .normal)
autofillButton.setTitleColor(.blue, for: .normal)
autofillButton.addTarget(self, action: #selector(tappedAutofill), for: .touchUpInside)
autofillButton.translatesAutoresizingMaskIntoConstraints = false
autofillButton = createButton(title: "Autofill", action: #selector(tappedAutofill))

view.addSubview(cardFormView)
view.addSubview(autofillButton)
Expand Down
19 changes: 4 additions & 15 deletions Demo/Application/Features/DataCollectorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit
import BraintreeDataCollector
import BraintreeCore

class DataCollectorViewController: BraintreeDemoPaymentButtonBaseViewController {
class DataCollectorViewController: PaymentButtonBaseViewController {

var dataLabel = UILabel()

Expand All @@ -11,15 +11,8 @@ class DataCollectorViewController: BraintreeDemoPaymentButtonBaseViewController
title = "Braintree Data Collector"
}

override func createPaymentButton() -> UIView! {
let dataCollectorButton = UIButton(type: .system)
dataCollectorButton.setTitle("Collect Device Data", for: .normal)
dataCollectorButton.setTitleColor(.blue, for: .normal)
dataCollectorButton.setTitleColor(.lightGray, for: .highlighted)
dataCollectorButton.setTitleColor(.lightGray, for: .disabled)
dataCollectorButton.addTarget(self, action: #selector(tappedCollect), for: .touchUpInside)
dataCollectorButton.translatesAutoresizingMaskIntoConstraints = false

override func createPaymentButton() -> UIView {
let dataCollectorButton = createButton(title: "Collect Device Data", action: #selector(tappedCollect))
let label = UILabel()
label.numberOfLines = 0
label.adjustsFontSizeToFitWidth = true
Expand All @@ -31,13 +24,9 @@ class DataCollectorViewController: BraintreeDemoPaymentButtonBaseViewController
stackView.axis = .vertical
stackView.spacing = 5
stackView.alignment = .center
stackView.distribution = .fillEqually
stackView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
dataCollectorButton.heightAnchor.constraint(equalToConstant: 19.5),
label.heightAnchor.constraint(equalToConstant: 19.5)
])

return stackView
}

Expand Down
14 changes: 3 additions & 11 deletions Demo/Application/Features/IdealViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import BraintreeLocalPayment
import BraintreeCore

class IdealViewController: BraintreeDemoPaymentButtonBaseViewController {
class IdealViewController: PaymentButtonBaseViewController {

var localPaymentClient: BTLocalPaymentClient!
var paymentIDLabel: UILabel = UILabel()
Expand All @@ -11,20 +11,12 @@ class IdealViewController: BraintreeDemoPaymentButtonBaseViewController {
super.viewDidLoad()

progressBlock("Loading iDEAL Merchant Account...")
paymentButton.isHidden = false
progressBlock("Ready!")
title = "iDEAL"
}

override func createPaymentButton() -> UIView! {
let iDEALButton = UIButton(type: .custom)
iDEALButton.setTitle("Pay with iDEAL", for: .normal)
iDEALButton.setTitleColor(.blue, for: .normal)
iDEALButton.setTitleColor(.lightGray, for: .highlighted)
iDEALButton.setTitleColor(.lightGray, for: .disabled)
iDEALButton.addTarget(self, action: #selector(tappedIDEAL), for: .touchUpInside)
iDEALButton.translatesAutoresizingMaskIntoConstraints = false

override func createPaymentButton() -> UIView {
let iDEALButton = createButton(title: "Pay with iDEAL", action: #selector(tappedIDEAL))
let label = UILabel()
label.numberOfLines = 0
label.translatesAutoresizingMaskIntoConstraints = false
Expand Down
25 changes: 7 additions & 18 deletions Demo/Application/Features/PayPalNativeCheckoutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,19 @@ import Foundation
import UIKit
import BraintreePayPalNativeCheckout

class PayPalNativeCheckoutViewController: BraintreeDemoPaymentButtonBaseViewController {
class PayPalNativeCheckoutViewController: PaymentButtonBaseViewController {
lazy var payPalNativeCheckoutClient = BTPayPalNativeCheckoutClient(apiClient: apiClient)

func checkoutPaymentButton(title: String, action: Selector) -> UIButton {
let button = UIButton(type: .system)
button.setTitle(title, for: .normal)
button.setTitleColor(.blue, for: .normal)
button.setTitleColor(.lightGray, for: .highlighted)
button.setTitleColor(.lightGray, for: .disabled)
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, action: action, for: .touchUpInside)
return button
}

override func createPaymentButton() -> UIView! {
let payPalCheckoutButton = checkoutPaymentButton(title: "One Time Checkout", action: #selector(tappedPayPalCheckout))
override func createPaymentButton() -> UIView {
let payPalCheckoutButton = createButton(title: "One Time Checkout", action: #selector(tappedPayPalCheckout))

// Buyers are shown a billing agreement without purchase
// For more information: https://developer.paypal.com/braintree/docs/guides/paypal/vault/ios/v5
let vaultCheckoutButton = checkoutPaymentButton(title: "Vault Checkout", action: #selector(tappedVaultCheckout))
// For more information: https://developer.paypal.com/braintree/docs/guides/paypal/vault/ios/v6
let vaultCheckoutButton = createButton(title: "Vault Checkout", action: #selector(tappedVaultCheckout))

// Buyers are shown a billing agreement with purchase
// For more information: https://developer.paypal.com/braintree/docs/guides/paypal/checkout-with-vault/ios/v5
let checkoutWithVaultButton = checkoutPaymentButton(title: "Checkout With Vault", action: #selector(tappedCheckoutWithVault))
// For more information: https://developer.paypal.com/braintree/docs/guides/paypal/checkout-with-vault/ios/v6
let checkoutWithVaultButton = createButton(title: "Checkout With Vault", action: #selector(tappedCheckoutWithVault))

let stackView = UIStackView(arrangedSubviews: [payPalCheckoutButton, vaultCheckoutButton, checkoutWithVaultButton])
stackView.axis = .vertical
Expand Down
22 changes: 5 additions & 17 deletions Demo/Application/Features/PayPalWebCheckoutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import Foundation
import UIKit
import BraintreePayPal

class PayPalWebCheckoutViewController: BraintreeDemoPaymentButtonBaseViewController {
class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {

lazy var payPalClient = BTPayPalClient(apiClient: apiClient)

override func createPaymentButton() -> UIView! {
let payPalCheckoutButton = paymentButton(title: "PayPal Checkout", action: #selector(tappedPayPalCheckout))
let payPalVaultButton = paymentButton(title: "PayPal Vault", action: #selector(tappedPayPalVault))
let payPalPayLaterButton = paymentButton(title: "PayPal with Pay Later Offered", action: #selector(tappedPayPalPayLater))
override func createPaymentButton() -> UIView {
let payPalCheckoutButton = createButton(title: "PayPal Checkout", action: #selector(tappedPayPalCheckout))
let payPalVaultButton = createButton(title: "PayPal Vault", action: #selector(tappedPayPalVault))
let payPalPayLaterButton = createButton(title: "PayPal with Pay Later Offered", action: #selector(tappedPayPalPayLater))

let buttons = [payPalCheckoutButton, payPalVaultButton, payPalPayLaterButton]
let stackView = UIStackView(arrangedSubviews: buttons)
Expand Down Expand Up @@ -78,16 +78,4 @@ class PayPalWebCheckoutViewController: BraintreeDemoPaymentButtonBaseViewControl
self.completionBlock(nonce)
}
}

// TODO: move into a shared class once the base ViewControllers are converted to Swift
func paymentButton(title: String, action: Selector) -> UIButton {
let button = UIButton(type: .system)
button.setTitle(title, for: .normal)
button.setTitleColor(.blue, for: .normal)
button.setTitleColor(.lightGray, for: .highlighted)
button.setTitleColor(.lightGray, for: .disabled)
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, action: action, for: .touchUpInside)
return button
}
}
35 changes: 10 additions & 25 deletions Demo/Application/Features/SEPADirectDebitViewController.swift
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
import UIKit
import AuthenticationServices
import BraintreeCore
import BraintreeSEPADirectDebit

class SEPADirectDebitViewController: BraintreeDemoBaseViewController {
private let sepaDirectDebitClient: BTSEPADirectDebitClient
private let sepaDirectDebitButton = UIButton(type: .system)

override init?(authorization: String!) {
guard let apiClient = BTAPIClient(authorization: authorization) else { return nil }

sepaDirectDebitClient = BTSEPADirectDebitClient(apiClient: apiClient)
class SEPADirectDebitViewController: PaymentButtonBaseViewController {

lazy var sepaDirectDebitClient = BTSEPADirectDebitClient(apiClient: apiClient)

super.init(authorization: authorization)

override func viewDidLoad() {
super.viewDidLoad()
title = "SEPA Direct Debit"

sepaDirectDebitButton.setTitle("SEPA Direct Debit", for: .normal)
sepaDirectDebitButton.translatesAutoresizingMaskIntoConstraints = false
sepaDirectDebitButton.addTarget(self, action: #selector(sepaDirectDebitButtonTapped), for: .touchUpInside)
view.addSubview(sepaDirectDebitButton)

NSLayoutConstraint.activate(
[
sepaDirectDebitButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
sepaDirectDebitButton.centerYAnchor.constraint(equalTo: view.centerYAnchor)
]
)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")

override func createPaymentButton() -> UIView {
let sepaDirectDebitButton = createButton(title: "SEPA Direct Debit", action: #selector(sepaDirectDebitButtonTapped))
return sepaDirectDebitButton
}

// MARK: - SEPA Direct Debit implementation
Expand Down
12 changes: 3 additions & 9 deletions Demo/Application/Features/ThreeDSecureViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import BraintreeCard
import BraintreeThreeDSecure

class ThreeDSecureViewController: BraintreeDemoPaymentButtonBaseViewController {
class ThreeDSecureViewController: PaymentButtonBaseViewController {

private let cardFormView = BTCardFormView()
private let autofillButton = UIButton(type: .system)
Expand All @@ -20,14 +20,8 @@ class ThreeDSecureViewController: BraintreeDemoPaymentButtonBaseViewController {
layoutConstraints()
}

override func createPaymentButton() -> UIView! {
let verifyNewCardButton = UIButton(type: .system)
verifyNewCardButton.setTitle("Tokenize and Verify New Card", for: .normal)
verifyNewCardButton.setTitleColor(.blue, for: .normal)
verifyNewCardButton.setTitleColor(.lightGray, for: .highlighted)
verifyNewCardButton.setTitleColor(.lightGray, for: .disabled)
verifyNewCardButton.addTarget(self, action: #selector(tappedToVerifyNewCard), for: .touchUpInside)
verifyNewCardButton.translatesAutoresizingMaskIntoConstraints = false
override func createPaymentButton() -> UIView {
let verifyNewCardButton = createButton(title: "Tokenize and Verify New Card", action: #selector(tappedToVerifyNewCard))

callbackCountLabel.translatesAutoresizingMaskIntoConstraints = false
callbackCountLabel.textAlignment = .center
Expand Down
Loading

0 comments on commit 643d64a

Please sign in to comment.