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

Refactor PaymentSheet didSelectPayWithLink delegate flow #3571

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,6 @@ extension PaymentSheet: PaymentSheetViewControllerDelegate {
self.completion?(.canceled)
}
}

func paymentSheetViewControllerDidSelectPayWithLink(
_ paymentSheetViewController: PaymentSheetViewController
) {
self.presentPayWithLinkController(
from: paymentSheetViewController,
intent: paymentSheetViewController.intent
)
}
}

extension PaymentSheet: LoadingViewControllerDelegate {
Expand All @@ -327,53 +318,3 @@ extension PaymentSheet: LoadingViewControllerDelegate {
@_spi(STP) extension PaymentSheet: STPAnalyticsProtocol {
@_spi(STP) public static let stp_analyticsIdentifier: String = "PaymentSheet"
}

extension PaymentSheet: PayWithLinkWebControllerDelegate {

func payWithLinkWebControllerDidComplete(
_ PayWithLinkWebController: PayWithLinkWebController,
intent: Intent,
with paymentOption: PaymentOption
) {
let backgroundColor = self.configuration.appearance.colors.background.withAlphaComponent(0.85)
self.bottomSheetViewController.addBlurEffect(animated: false, backgroundColor: backgroundColor) {
self.bottomSheetViewController.startSpinner()
let psvc = self.findPaymentSheetViewController()
psvc?.clearTextFields()
psvc?.pay(with: paymentOption, animateBuyButton: true)
}
}

func payWithLinkWebControllerDidCancel(_ payWithLinkWebController: PayWithLinkWebController) {
}

private func findPaymentSheetViewController() -> PaymentSheetViewController? {
for vc in bottomSheetViewController.contentStack {
if let paymentSheetVC = vc as? PaymentSheetViewController {
return paymentSheetVC
}
}

return nil
}
}

// MARK: - Link

private extension PaymentSheet {

func presentPayWithLinkController(
from presentingController: UIViewController,
intent: Intent,
completion: (() -> Void)? = nil
) {
let payWithLinkVC = PayWithLinkWebController(
intent: intent,
configuration: configuration
)

payWithLinkVC.payWithLinkDelegate = self
payWithLinkVC.present(over: presentingController)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ protocol PaymentSheetViewControllerDelegate: AnyObject {
func paymentSheetViewControllerDidCancel(
_ paymentSheetViewController: PaymentSheetViewController
)
func paymentSheetViewControllerDidSelectPayWithLink(
_ paymentSheetViewController: PaymentSheetViewController
)
}

/// For internal SDK use only
Expand Down Expand Up @@ -554,13 +551,38 @@ extension PaymentSheetViewController: WalletHeaderViewDelegate {

func walletHeaderViewPayWithLinkTapped(_ header: WalletHeaderView) {
set(error: nil)
delegate?.paymentSheetViewControllerDidSelectPayWithLink(self)
let payWithLinkVC = PayWithLinkWebController(
intent: intent,
configuration: configuration
)

payWithLinkVC.payWithLinkDelegate = self
payWithLinkVC.present(over: self)
}
}

// MARK: - PayWithLinkWebControllerDelegate

extension PaymentSheetViewController: PayWithLinkWebControllerDelegate {

func payWithLinkWebControllerDidComplete(
_ PayWithLinkWebController: PayWithLinkWebController,
intent: Intent,
with paymentOption: PaymentOption
) {
let backgroundColor = self.configuration.appearance.colors.background.withAlphaComponent(0.85)
bottomSheetController?.addBlurEffect(animated: false, backgroundColor: backgroundColor) {
self.bottomSheetController?.startSpinner()
self.clearTextFields()
self.pay(with: paymentOption, animateBuyButton: true)
}
}

func payWithLinkWebControllerDidCancel(_ payWithLinkWebController: PayWithLinkWebController) {
}
}

// MARK: - BottomSheetContentViewController
/// :nodoc:
extension PaymentSheetViewController: BottomSheetContentViewController {
var allowsDragToDismiss: Bool {
return isDismissable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,4 @@ extension PaymentSheetViewControllerSnapshotTests: PaymentSheetViewControllerDel

func paymentSheetViewControllerDidCancel(_ paymentSheetViewController: StripePaymentSheet.PaymentSheetViewController) {
}

func paymentSheetViewControllerDidSelectPayWithLink(_ paymentSheetViewController: StripePaymentSheet.PaymentSheetViewController) {
}
}
Loading