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

Link v3: Re-add PayWithLinkViewController #4165

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class EmbeddedPlaygroundViewController: UIViewController {
checkoutButton.translatesAutoresizingMaskIntoConstraints = false
return checkoutButton
}()

private let paymentOptionView = EmbeddedPaymentOptionView()

init(configuration: EmbeddedPaymentElement.Configuration, intentConfig: PaymentSheet.IntentConfiguration, appearance: PaymentSheet.Appearance) {
Expand Down Expand Up @@ -94,7 +94,7 @@ class EmbeddedPlaygroundViewController: UIViewController {
checkoutButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
checkoutButton.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -20),
])

paymentOptionView.configure(with: embeddedPaymentElement.paymentOption, showMandate: !configuration.embeddedViewDisplaysMandateText)
}

Expand Down Expand Up @@ -123,15 +123,14 @@ extension EmbeddedPlaygroundViewController: EmbeddedPaymentElementDelegate {
self.view.setNeedsLayout()
self.view.layoutIfNeeded()
}

func embeddedPaymentElementDidUpdatePaymentOption(embeddedPaymentElement: EmbeddedPaymentElement) {
paymentOptionView.configure(with: embeddedPaymentElement.paymentOption, showMandate: !configuration.embeddedViewDisplaysMandateText)
}
}


private class EmbeddedPaymentOptionView: UIView {

private let titleLabel: UILabel = {
let label = UILabel()
label.font = .preferredFont(forTextStyle: .body)
Expand All @@ -140,22 +139,22 @@ private class EmbeddedPaymentOptionView: UIView {
label.text = "Selected payment method"
return label
}()

private let imageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
imageView.translatesAutoresizingMaskIntoConstraints = false
return imageView
}()

private let label: UILabel = {
let label = UILabel()
label.font = .preferredFont(forTextStyle: .subheadline)
label.numberOfLines = 1
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()

private let mandateTextLabel: UILabel = {
let mandateLabel = UILabel()
mandateLabel.font = .preferredFont(forTextStyle: .footnote)
Expand All @@ -165,45 +164,45 @@ private class EmbeddedPaymentOptionView: UIView {
mandateLabel.textAlignment = .left
return mandateLabel
}()

override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}

required init?(coder: NSCoder) {
super.init(coder: coder)
setupView()
}

private func setupView() {
addSubview(titleLabel)
addSubview(imageView)
addSubview(label)
addSubview(mandateTextLabel)

NSLayoutConstraint.activate([
titleLabel.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 15),
titleLabel.topAnchor.constraint(equalTo: self.topAnchor),
titleLabel.widthAnchor.constraint(equalTo: self.widthAnchor),
titleLabel.heightAnchor.constraint(equalToConstant: 25),

imageView.leadingAnchor.constraint(equalTo: titleLabel.leadingAnchor),
imageView.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 20),
imageView.widthAnchor.constraint(equalToConstant: 25),
imageView.heightAnchor.constraint(equalToConstant: 25),

label.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 12),
label.trailingAnchor.constraint(equalTo: self.trailingAnchor),
label.topAnchor.constraint(equalTo: self.topAnchor),
label.centerYAnchor.constraint(equalTo: imageView.centerYAnchor),

mandateTextLabel.leadingAnchor.constraint(equalTo: imageView.leadingAnchor),
mandateTextLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -12),
mandateTextLabel.topAnchor.constraint(equalTo: imageView.bottomAnchor, constant: 12),
])
}

func configure(with data: EmbeddedPaymentElement.PaymentOptionDisplayData?, showMandate: Bool) {
titleLabel.isHidden = data == nil
imageView.image = data?.image
Expand All @@ -212,4 +211,3 @@ private class EmbeddedPaymentOptionView: UIView {
mandateTextLabel.isHidden = !showMandate
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ extension PayWithLinkButtonSnapshotTests {
fileprivate struct LinkAccountStub: PaymentSheetLinkAccountInfoProtocol {
let email: String
let isRegistered: Bool
var redactedPhoneNumber: String?
var isLoggedIn: Bool
}

fileprivate func makeAccountStub(email: String, isRegistered: Bool) -> LinkAccountStub {
return LinkAccountStub(
email: email,
isRegistered: isRegistered
isRegistered: isRegistered,
redactedPhoneNumber: "+1********55",
isLoggedIn: true
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ import Foundation
case linkPopupError = "link.popup.error"
case linkPopupLogout = "link.popup.logout"

// MARK: - Link 2FA
case link2FAStart = "link.2fa.start"
case link2FAStartFailure = "link.2fa.start_failure"
case link2FAComplete = "link.2fa.complete"
case link2FACancel = "link.2fa.cancel"
case link2FAFailure = "link.2fa.failure"

// MARK: - Link Misc
case linkAccountLookupComplete = "link.account_lookup.complete"
case linkAccountLookupFailure = "link.account_lookup.failure"
Expand Down
Loading
Loading