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

Update Demo App to Support App Switch for Checkout #1471

Merged
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
44 changes: 40 additions & 4 deletions Demo/Application/Features/PayPalWebCheckoutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down