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

Consolidate PayPal ViewControllers #1102

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 2 additions & 6 deletions Demo/Application/Base/Settings/Settings.bundle/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
<key>Titles</key>
<array>
<string>PayPal - Native Checkout</string>
<string>PayPal - Vault</string>
<string>PayPal - Checkout</string>
<string>PayPal - Pay Later</string>
<string>PayPal - Web Checkout</string>
<string>Credit Card Tokenization</string>
<string>Venmo - Custom Button</string>
<string>Apple Pay - PassKit</string>
Expand All @@ -33,9 +31,7 @@
<key>Values</key>
<array>
<string>BraintreeDemoPayPalNativeCheckoutViewController</string>
<string>BraintreeDemoPayPalVaultViewController</string>
<string>BraintreeDemoPayPalCheckoutViewController</string>
<string>BraintreeDemoPayPalPayLaterViewController</string>
<string>BraintreeDemoPayPalWebCheckoutViewController</string>
<string>BraintreeDemoCardTokenizationViewController</string>
<string>BraintreeDemoVenmoViewController</string>
<string>BraintreeDemoApplePayPassKitViewController</string>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import Foundation
import UIKit
import BraintreePayPal

class BraintreeDemoPayPalWebCheckoutViewController: BraintreeDemoPaymentButtonBaseViewController {

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))

let buttons = [payPalCheckoutButton, payPalVaultButton, payPalPayLaterButton]
let stackView = UIStackView(arrangedSubviews: buttons)
stackView.axis = .vertical
stackView.alignment = .center
stackView.distribution = .fillEqually
stackView.translatesAutoresizingMaskIntoConstraints = false

return stackView
}

@objc func tappedPayPalCheckout(_ sender: UIButton) {
progressBlock("Tapped PayPal - Checkout using BTPayPalClient")
sender.setTitle("Processing...", for: .disabled)
sender.isEnabled = false

let request = BTPayPalCheckoutRequest(amount: "4.30")

payPalClient.tokenize(request) { nonce, error in
sender.isEnabled = true

guard let nonce else {
self.progressBlock(error?.localizedDescription)
return
}

self.completionBlock(nonce)
}
}

@objc func tappedPayPalVault(_ sender: UIButton) {
progressBlock("Tapped PayPal - Vault using BTPayPalClient")
sender.setTitle("Processing...", for: .disabled)
sender.isEnabled = false

let request = BTPayPalVaultRequest()

payPalClient.tokenize(request) { nonce, error in
sender.isEnabled = true

guard let nonce else {
self.progressBlock(error?.localizedDescription)
return
}

self.completionBlock(nonce)
}
}

@objc func tappedPayPalPayLater(_ sender: UIButton) {
progressBlock("Tapped PayPal - initiating with Pay Later offered")
sender.setTitle("Processing...", for: .disabled)
sender.isEnabled = false

let request = BTPayPalCheckoutRequest(amount: "4.30")
request.offerPayLater = true

payPalClient.tokenize(request) { nonce, error in
sender.isEnabled = true

guard let nonce else {
self.progressBlock(error?.localizedDescription)
return
}

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
}
}
Loading