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

ApplePay Component cancel issue #517

Closed
zayar-supers opened this issue May 28, 2021 · 4 comments
Closed

ApplePay Component cancel issue #517

zayar-supers opened this issue May 28, 2021 · 4 comments

Comments

@zayar-supers
Copy link

zayar-supers commented May 28, 2021

I used ApplePayComponent to pop up payment sheet controller and cannot cancel the payment by clicking Cancel button before authenticate the payment. Nothing is happening when I click Cancel button.

Another issue is when I click the upper area of the payment sheet at that time, the payment sheet disappears but the controller is still in view hierarchy when I debug the view hierarchy.

Can I able to check didFail delegate method will be called for the upper scenarios ?
Cause didFail delegate is not called upon my testing.

Is this possible to happen this kind of issues if I am using the improper client key for the ApplePayComponent ?

The iOS sdk version I used is the latest v3.8.5.

@descorp
Copy link
Contributor

descorp commented May 28, 2021

Hey @zayar-supers

Thanks for reaching out!

The client key has no effect on ApplePayComponent.

Quick questions:

  1. Do you persist the component?
  2. Does didFail called when you click 'Cancel' ?
  3. Did you try dismissing it manually?

@zayar-supers
Copy link
Author

zayar-supers commented May 28, 2021

@descorp Thanks for your confirmation on client key portion.

The component is not dismiss and didFail is not called when I click 'Cancel'.
I did not try to dismiss it manually.

I only try to present component in this code as the sample.

               let payment = Payment(amount: Payment.Amount(value: amt, currencyCode: "SGD"),
                                     countryCode: "SG")
               
               let configuration = ApplePayComponent.Configuration(summaryItems: [PKPaymentSummaryItem(label: “***”, amount: NSDecimalNumber(decimal: amt), type: .final)], merchantIdentifier: “***”)
               
               let applePayComponent = try ApplePayComponent(paymentMethod: paymentMethod, payment: payment, configuration: configuration, cancelHandler: {
                   print("Apple Pay is cancel.")
               })

               applePayComponent.clientKey = “***”
               applePayComponent.delegate = self
               applePayComponent.environment = .test
               self.present(applePayComponent.viewController, animated: true)

@descorp
Copy link
Contributor

descorp commented May 28, 2021

aha!

Unfortunately ApplePay does not dismiss itself from NavigationController's stack.

there are few things you need to do:

  1. persist applePayComponent until the payment is finished.
private var applePayComponent: ApplePayComponent?
  1. dismiss top viewController (in your case it is self) manually when finished
    private func finish(with resultCode: PaymentsResponse.ResultCode) {
        let success = resultCode == .authorised || resultCode == .received || resultCode == .pending

        applePayComponent?.stopLoading(withSuccess: success) { [weak self] in
            self?.dismiss {
                // Do success flow
            }
        }
    }

    private func finish(with error: Error) {
        let isCancelled = ((error as? ComponentError) == .cancelled)

        self.dismiss {
            if !isCancelled {
                // Do nothing - user decided not to continue with ApplePay
            } else {
                // Do unsuccess flow
        }
    }

@descorp descorp removed the bug label May 28, 2021
@zayar-supers
Copy link
Author

@descorp Thanks for your sample snippet. My problem was the component did not persist. Now the issue is solved. 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants