-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate PayPal ViewControllers (#1102)
* Consolidate PayPal Checkout, Vault and Pay Later ViewControllers into a single ViewController with all 3 buttons * Update settings drop down to PayPal - Web Checkout
- Loading branch information
1 parent
8f9e92f
commit 77ca7d8
Showing
8 changed files
with
112 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
Demo/Application/Features/PayPal - Checkout/BraintreeDemoPayPalCheckoutViewController.swift
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
Demo/Application/Features/PayPal - Pay Later/BraintreeDemoPayPalPayLaterViewController.swift
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
Demo/Application/Features/PayPal - Vault/BraintreeDemoPayPalVaultViewController.swift
This file was deleted.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
...ication/Features/PayPal - Web Checkout/BraintreeDemoPayPalWebCheckoutViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.