Skip to content

Commit 802321f

Browse files
NastassiaRodziknrodzik
andauthored
Replace Pay Later toggle with a button in Braintree Demo App (#1697)
* Replace Pay Later toggle with a button * Update CHANGELOG.md * Fix error after merging main branch in * Fix Lint error * Remove entry from CHANGELOG.md * Apply suggestion to rename button * Rename variable to pass SwiftLint check --------- Co-authored-by: nrodzik <nrodzik@paypal.com>
1 parent 03e8f02 commit 802321f

1 file changed

Lines changed: 34 additions & 10 deletions

File tree

Demo/Application/Features/PayPalWebCheckoutViewController.swift

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {
7575
return stackView
7676
}()
7777

78-
let payLaterToggle = Toggle(title: "Offer Pay Later")
7978
let rbaDataToggle = Toggle(title: "Recurring Billing (RBA) Data")
8079
let contactInformationToggle = Toggle(title: "Add Contact Information")
8180
let amountBreakdownToggle = Toggle(title: "Amount Breakdown")
@@ -104,13 +103,18 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {
104103
title: "PayPal App Switch - Vault",
105104
action: #selector(tappedPayPalAppSwitchForVault)
106105
)
106+
107+
let payPalAppSwitchForCheckoutPayLaterButton = createButton(
108+
title: "Pay Later App Switch - Checkout",
109+
action: #selector(tappedPayLaterForCheckout)
110+
)
107111

108112
let oneTimeCheckoutStackView = buttonsStackView(label: "1-Time Checkout", views: [
109-
payLaterToggle,
110113
contactInformationToggle,
111114
amountBreakdownToggle,
112115
payPalCheckoutButton,
113116
payPalAppSwitchForCheckoutButton,
117+
payPalAppSwitchForCheckoutPayLaterButton,
114118
payPalAppSwitchForCreditButton
115119
])
116120
oneTimeCheckoutStackView.spacing = 12
@@ -170,11 +174,9 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {
170174
recipientPhoneNumber: .init(countryCode: "52", nationalNumber: "123456789")
171175
)
172176

173-
// pay later is only available on amounts greater than or equal to 35
174-
let amount = payLaterToggle.isOn ? "35.00" : "5.00"
177+
let amount = "5.00"
175178
var request = BTPayPalCheckoutRequest(
176179
amount: amount,
177-
offerPayLater: payLaterToggle.isOn,
178180
contactInformation: contactInformationToggle.isOn ? contactInformation : nil,
179181
contactPreference: .updateContactInformation,
180182
lineItems: [lineItem],
@@ -305,14 +307,12 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {
305307
sender.setTitle("Processing...", for: .disabled)
306308
sender.isEnabled = false
307309

308-
// pay later is only available on amounts greater than or equal to 35
309-
let amount = payLaterToggle.isOn ? "35.00" : "10.00"
310+
let amount = "10.00"
310311
let request = BTPayPalCheckoutRequest(
311312
amount: amount,
312313
enablePayPalAppSwitch: true,
313314
userAuthenticationEmail: emailTextField.text,
314-
userAction: .payNow,
315-
offerPayLater: payLaterToggle.isOn
315+
userAction: .payNow
316316
)
317317

318318
payPalClient.tokenize(request) { nonce, error in
@@ -336,7 +336,6 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {
336336
enablePayPalAppSwitch: true,
337337
userAuthenticationEmail: emailTextField.text,
338338
userAction: .payNow,
339-
offerPayLater: payLaterToggle.isOn,
340339
offerCredit: true
341340
)
342341

@@ -372,4 +371,29 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {
372371
self.completionBlock(nonce)
373372
}
374373
}
374+
375+
@objc func tappedPayLaterForCheckout(_ sender: UIButton) {
376+
sender.setTitle("Processing...", for: .disabled)
377+
sender.isEnabled = false
378+
379+
let amount = "35.00"
380+
let request = BTPayPalCheckoutRequest(
381+
amount: amount,
382+
enablePayPalAppSwitch: true,
383+
userAuthenticationEmail: emailTextField.text,
384+
userAction: .payNow,
385+
offerPayLater: true
386+
)
387+
388+
payPalClient.tokenize(request) { nonce, error in
389+
sender.isEnabled = true
390+
391+
guard let nonce else {
392+
self.progressBlock(error?.localizedDescription)
393+
return
394+
}
395+
396+
self.completionBlock(nonce)
397+
}
398+
}
375399
}

0 commit comments

Comments
 (0)