Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
virginiacook committed Dec 12, 2023
1 parent 101e57c commit cd0157d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ extension PaymentSheetViewController {
stackView.axis = .vertical
stackView.spacing = Constants.buttonSpacing

if let walletSubview = walletSubview {
stackView.setCustomSpacing(Constants.labelSpacing, after: walletSubview)
} else if let lastButton = buttons.last {
stackView.setCustomSpacing(Constants.labelSpacing, after: lastButton)
}

addAndPinSubview(stackView)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,58 +136,55 @@ public class PaymentSheet {
completion(.failed(error: error))
return
}
let seconds = 1.0
DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
// Configure the Payment Sheet VC after loading the PI/SI, Customer, etc.
PaymentSheetLoader.load(
mode: self.mode,
configuration: self.configuration
) { result in
switch result {
case .success(let intent, let savedPaymentMethods, let isLinkEnabled):
// Set the PaymentSheetViewController as the content of our bottom sheet
let isApplePayEnabled = StripeAPI.deviceSupportsApplePay()
&& self.configuration.applePay != nil
&& intent.isApplePayEnabled

let presentPaymentSheetVC = { (justVerifiedLinkOTP: Bool) in
let paymentSheetVC = PaymentSheetViewController(
// Configure the Payment Sheet VC after loading the PI/SI, Customer, etc.
PaymentSheetLoader.load(
mode: self.mode,
configuration: self.configuration
) { result in
switch result {
case .success(let intent, let savedPaymentMethods, let isLinkEnabled):
// Set the PaymentSheetViewController as the content of our bottom sheet
let isApplePayEnabled = StripeAPI.deviceSupportsApplePay()
&& self.configuration.applePay != nil
&& intent.isApplePayEnabled

let presentPaymentSheetVC = { (justVerifiedLinkOTP: Bool) in
let paymentSheetVC = PaymentSheetViewController(
intent: intent,
savedPaymentMethods: savedPaymentMethods,
configuration: self.configuration,
isApplePayEnabled: isApplePayEnabled,
isLinkEnabled: isLinkEnabled,
isConfirmed: self.configuration.delegate == nil,
delegate: self
)

self.configuration.style.configure(paymentSheetVC)

let updateBottomSheet: () -> Void = {
self.bottomSheetViewController.contentStack = [paymentSheetVC]
}

if LinkAccountContext.shared.account?.sessionState == .verified {
self.presentPayWithLinkController(
from: self.bottomSheetViewController,
intent: intent,
savedPaymentMethods: savedPaymentMethods,
configuration: self.configuration,
isApplePayEnabled: isApplePayEnabled,
isLinkEnabled: isLinkEnabled,
isConfirmed: self.configuration.delegate == nil,
delegate: self
shouldOfferApplePay: justVerifiedLinkOTP,
shouldFinishOnClose: true,
completion: {
// Update the bottom sheet after presenting the Link controller
// to avoid briefly flashing the PaymentSheet in the middle of
// the View Controller transition.
updateBottomSheet()
}
)

self.configuration.style.configure(paymentSheetVC)

let updateBottomSheet: () -> Void = {
self.bottomSheetViewController.contentStack = [paymentSheetVC]
}

if LinkAccountContext.shared.account?.sessionState == .verified {
self.presentPayWithLinkController(
from: self.bottomSheetViewController,
intent: intent,
shouldOfferApplePay: justVerifiedLinkOTP,
shouldFinishOnClose: true,
completion: {
// Update the bottom sheet after presenting the Link controller
// to avoid briefly flashing the PaymentSheet in the middle of
// the View Controller transition.
updateBottomSheet()
}
)
} else {
updateBottomSheet()
}
} else {
updateBottomSheet()
}
presentPaymentSheetVC(false)
case .failure(let error):
completion(.failed(error: error))
}
presentPaymentSheetVC(false)
case .failure(let error):
completion(.failed(error: error))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class PaymentSheetViewController: UIViewController {
private lazy var savedPaymentOptionsViewController: SavedPaymentOptionsViewController = {
let showApplePay = !shouldShowWalletHeader && isApplePayEnabled
let showLink = !shouldShowWalletHeader && isLinkEnabled

return SavedPaymentOptionsViewController(
savedPaymentMethods: savedPaymentMethods,
configuration: .init(
Expand Down Expand Up @@ -214,9 +213,11 @@ class PaymentSheetViewController: UIViewController {
let stackView = UIStackView(arrangedSubviews: [
headerLabel, walletHeader, paymentContainerView, errorLabel, bottomNoticeTextField,
])

stackView.directionalLayoutMargins = PaymentSheetUI.defaultMargins
stackView.isLayoutMarginsRelativeArrangement = true
stackView.spacing = PaymentSheetUI.defaultPadding
stackView.setCustomSpacing(8.0, after: walletHeader)
stackView.axis = .vertical
stackView.bringSubviewToFront(headerLabel)

Expand Down

0 comments on commit cd0157d

Please sign in to comment.