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

Cleanup Venmo Demo UI #1437

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions Demo/Application/Features/Helpers/Toggle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import UIKit

class Toggle: UIView {

private let toggle = UISwitch()
private let title: String

var isOn: Bool {
return toggle.isOn
}

init(title: String) {
self.title = title
super.init(frame: .zero)
layoutUI()
}

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

private func layoutUI() {
let label = UILabel()
label.text = title
label.translatesAutoresizingMaskIntoConstraints = false

toggle.translatesAutoresizingMaskIntoConstraints = false

let stackView = UIStackView(arrangedSubviews: [label, toggle])
stackView.alignment = .fill
stackView.distribution = .fill
stackView.translatesAutoresizingMaskIntoConstraints = false
addSubview(stackView)

NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
stackView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor),
stackView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor)
])
}
}
32 changes: 6 additions & 26 deletions Demo/Application/Features/PayPalWebCheckoutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,12 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {
return textField
}()

lazy var payLaterToggleLabel: UILabel = {
let label = UILabel()
label.text = "Offer Pay Later"
label.font = .preferredFont(forTextStyle: .footnote)
return label
}()

let payLaterToggle = UISwitch()

lazy var newPayPalCheckoutToggleLabel: UILabel = {
let label = UILabel()
label.text = "New PayPal Checkout Experience"
label.font = .preferredFont(forTextStyle: .footnote)
return label
}()

let newPayPalCheckoutToggle = UISwitch()
let payLaterToggle = Toggle(title: "Offer Pay Later")

lazy var rbaDataToggleLabel: UILabel = {
let label = UILabel()
label.text = "Recurring Billing (RBA) Data"
label.font = .preferredFont(forTextStyle: .footnote)
return label
}()
let newPayPalCheckoutToggle = Toggle(title: "New PayPal Checkout Experience")

let rbaDataToggle = UISwitch()
let rbaDataToggle = Toggle(title: "Recurring Billing (RBA) Data")

override func viewDidLoad() {
super.heightConstraint = 350
Expand All @@ -90,12 +70,12 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {
let payPalAppSwitchButton = createButton(title: "PayPal App Switch", action: #selector(tappedPayPalAppSwitch))

let oneTimeCheckoutStackView = buttonsStackView(label: "1-Time Checkout", views: [
UIStackView(arrangedSubviews: [payLaterToggleLabel, payLaterToggle]),
UIStackView(arrangedSubviews: [newPayPalCheckoutToggleLabel, newPayPalCheckoutToggle]),
payLaterToggle,
newPayPalCheckoutToggle,
payPalCheckoutButton
])
let vaultStackView = buttonsStackView(label: "Vault", views: [
UIStackView(arrangedSubviews: [rbaDataToggleLabel, rbaDataToggle]),
rbaDataToggle,
payPalVaultButton,
payPalAppSwitchButton
])
Expand Down
51 changes: 13 additions & 38 deletions Demo/Application/Features/VenmoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class VenmoViewController: PaymentButtonBaseViewController {

// swiftlint:disable:next implicitly_unwrapped_optional
var venmoClient: BTVenmoClient!

let webFallbackToggle = Toggle(title: "Enable Web Fallback")
let vaultToggle = Toggle(title: "Vault")

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -14,13 +17,11 @@ class VenmoViewController: PaymentButtonBaseViewController {

override func createPaymentButton() -> UIView {
let venmoButton = createButton(title: "Venmo", action: #selector(tappedVenmo))
let venmoECDButton = createButton(title: "Venmo (with ECD options)", action: #selector(tappedVenmoWithECD))
let venmoUniversalLinkButton = createButton(title: "Venmo Universal Links", action: #selector(tappedVenmoWithUniversalLinks))

let stackView = UIStackView(arrangedSubviews: [venmoButton, venmoECDButton, venmoUniversalLinkButton])
let stackView = UIStackView(arrangedSubviews: [webFallbackToggle, vaultToggle, venmoButton])
stackView.axis = .vertical
stackView.spacing = 5
stackView.alignment = .center
stackView.spacing = 15
stackView.alignment = .fill
stackView.distribution = .fillEqually
stackView.translatesAutoresizingMaskIntoConstraints = false

Expand All @@ -31,44 +32,18 @@ class VenmoViewController: PaymentButtonBaseViewController {
self.progressBlock("Tapped Venmo - initiating Venmo auth")

let venmoRequest = BTVenmoRequest(paymentMethodUsage: .multiUse)
venmoRequest.vault = true

checkout(request: venmoRequest)
}

@objc func tappedVenmoWithECD() {
self.progressBlock("Tapped Venmo ECD - initiating Venmo auth")

let venmoRequest = BTVenmoRequest(paymentMethodUsage: .multiUse)
venmoRequest.vault = true
venmoRequest.collectCustomerBillingAddress = true
venmoRequest.collectCustomerShippingAddress = true
venmoRequest.totalAmount = "30.00"
venmoRequest.taxAmount = "1.10"
venmoRequest.discountAmount = "1.10"
venmoRequest.shippingAmount = "0.00"
if webFallbackToggle.isOn {
venmoRequest.fallbackToWeb = true
}

let lineItem = BTVenmoLineItem(quantity: 1, unitAmount: "30.00", name: "item-1", kind: .debit)
lineItem.unitTaxAmount = "1.00"
venmoRequest.lineItems = [lineItem]
if vaultToggle.isOn {
venmoRequest.vault = true
}

checkout(request: venmoRequest)
}

@objc func tappedVenmoWithUniversalLinks() {
self.progressBlock("Tapped Venmo Universal Links - initiating Venmo auth")

let venmoRequest = BTVenmoRequest(paymentMethodUsage: .multiUse)
venmoRequest.vault = true
venmoRequest.fallbackToWeb = true

checkout(request: venmoRequest)
}

func checkout(request: BTVenmoRequest) {
Task {
do {
let venmoAccount = try await venmoClient.tokenize(request)
let venmoAccount = try await venmoClient.tokenize(venmoRequest)
progressBlock("Got a nonce 💎!")
completionBlock(venmoAccount)
} catch {
Expand Down
4 changes: 4 additions & 0 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
57108A172832EA04004EB870 /* BraintreePayPalNativeCheckout.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 57108A162832EA04004EB870 /* BraintreePayPalNativeCheckout.framework */; };
57108A182832EA04004EB870 /* BraintreePayPalNativeCheckout.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 57108A162832EA04004EB870 /* BraintreePayPalNativeCheckout.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
62240F5A2B67FE1100ECE5C9 /* TextFieldWithLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62240F592B67FE1100ECE5C9 /* TextFieldWithLabel.swift */; };
8025988D2CC1A95400E7D898 /* Toggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8025988C2CC1A95400E7D898 /* Toggle.swift */; };
8028B9762B28C9E100C88CE8 /* ShopperInsightsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8028B9752B28C9E100C88CE8 /* ShopperInsightsViewController.swift */; };
8028B9782B28D42400C88CE8 /* BraintreeShopperInsights.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8028B9772B28D42400C88CE8 /* BraintreeShopperInsights.framework */; };
8028B9792B28D42400C88CE8 /* BraintreeShopperInsights.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8028B9772B28D42400C88CE8 /* BraintreeShopperInsights.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -148,6 +149,7 @@
62240F592B67FE1100ECE5C9 /* TextFieldWithLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldWithLabel.swift; sourceTree = "<group>"; };
6D23244B5E9EE59BAB3F3003 /* Pods_Demo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Demo.framework; sourceTree = BUILT_PRODUCTS_DIR; };
73498B4265CA7D315E2FBF38 /* Pods-Demo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Demo.debug.xcconfig"; path = "Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig"; sourceTree = "<group>"; };
8025988C2CC1A95400E7D898 /* Toggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toggle.swift; sourceTree = "<group>"; };
8028B9752B28C9E100C88CE8 /* ShopperInsightsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShopperInsightsViewController.swift; sourceTree = "<group>"; };
8028B9772B28D42400C88CE8 /* BraintreeShopperInsights.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = BraintreeShopperInsights.framework; sourceTree = BUILT_PRODUCTS_DIR; };
803D64EA256DAF9A00ACE692 /* BraintreeAmericanExpress.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = BraintreeAmericanExpress.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -293,6 +295,7 @@
BEAAAD042970A70D000BD296 /* BTSEPADirectDebitTestHelper.swift */,
BED461822AD072D9001B0DDF /* CardHelpers.swift */,
62240F592B67FE1100ECE5C9 /* TextFieldWithLabel.swift */,
8025988C2CC1A95400E7D898 /* Toggle.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -709,6 +712,7 @@
BEBD52832AAB62FB005D6687 /* ApplePayViewController.swift in Sources */,
BEAAAD052970A70D000BD296 /* BTSEPADirectDebitTestHelper.swift in Sources */,
809E86A62AD00AF4004998B0 /* AppDelegate.swift in Sources */,
8025988D2CC1A95400E7D898 /* Toggle.swift in Sources */,
A0988F9224DB44B20095EEEE /* BraintreeDemoSettings.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
10 changes: 0 additions & 10 deletions Demo/UI Tests/Venmo UI Tests/Venmo_UITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ class Venmo_UITests: XCTestCase {
XCTAssertTrue(demoApp.buttons["Got a nonce. Tap to make a transaction."].waitForExistence(timeout: 30))
}

func testTokenizeVenmo_withECDOptions_whenSignInSuccessfulWithPaymentContext_returnsNonce() {
waitForElementToBeHittable(demoApp.buttons["Venmo (with ECD options)"])
demoApp.buttons["Venmo (with ECD options)"].tap()

waitForElementToBeHittable(mockVenmo.buttons["SUCCESS WITH PAYMENT CONTEXT"])
mockVenmo.buttons["SUCCESS WITH PAYMENT CONTEXT"].tap()

XCTAssertTrue(demoApp.buttons["Got a nonce. Tap to make a transaction."].waitForExistence(timeout: 30))
}

func testTokenizeVenmo_whenSignInSuccessfulWithoutPaymentContext_returnsNonce() {
waitForElementToBeHittable(demoApp.buttons["Venmo"])
demoApp.buttons["Venmo"].tap()
Expand Down