diff --git a/Demo/Application/Features/PayPalWebCheckoutViewController.swift b/Demo/Application/Features/PayPalWebCheckoutViewController.swift index 91e7158de..99bff5ced 100644 --- a/Demo/Application/Features/PayPalWebCheckoutViewController.swift +++ b/Demo/Application/Features/PayPalWebCheckoutViewController.swift @@ -88,18 +88,26 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController { override func createPaymentButton() -> UIView { let payPalCheckoutButton = createButton(title: "PayPal Checkout", action: #selector(tappedPayPalCheckout)) let payPalVaultButton = createButton(title: "PayPal Vault", action: #selector(tappedPayPalVault)) - let payPalAppSwitchButton = createButton(title: "PayPal App Switch", action: #selector(tappedPayPalAppSwitch)) + let payPalAppSwitchForCheckoutButton = createButton( + title: "PayPal App Switch - Checkout", + action: #selector(tappedPayPalAppSwitchForCheckout) + ) + let payPalAppSwitchForVaultButton = createButton( + title: "PayPal App Switch - Vault", + action: #selector(tappedPayPalAppSwitchForVault) + ) let oneTimeCheckoutStackView = buttonsStackView(label: "1-Time Checkout", views: [ payLaterToggle, newPayPalCheckoutToggle, - payPalCheckoutButton + payPalCheckoutButton, + payPalAppSwitchForCheckoutButton ]) oneTimeCheckoutStackView.spacing = 12 let vaultStackView = buttonsStackView(label: "Vault", views: [ rbaDataToggle, payPalVaultButton, - payPalAppSwitchButton + payPalAppSwitchForVaultButton ]) vaultStackView.spacing = 12 @@ -221,8 +229,36 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController { self.completionBlock(nonce) } } + + @objc func tappedPayPalAppSwitchForCheckout(_ sender: UIButton) { + sender.setTitle("Processing...", for: .disabled) + sender.isEnabled = false + + guard let userEmail = emailTextField.text, !userEmail.isEmpty else { + self.progressBlock("Email cannot be nil for App Switch flow") + sender.isEnabled = true + return + } + + let request = BTPayPalCheckoutRequest( + userAuthenticationEmail: userEmail, + enablePayPalAppSwitch: true, + amount: "10.00" + ) + + payPalClient.tokenize(request) { nonce, error in + sender.isEnabled = true + + guard let nonce else { + self.progressBlock(error?.localizedDescription) + return + } + + self.completionBlock(nonce) + } + } - @objc func tappedPayPalAppSwitch(_ sender: UIButton) { + @objc func tappedPayPalAppSwitchForVault(_ sender: UIButton) { sender.setTitle("Processing...", for: .disabled) sender.isEnabled = false