question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ios] Close Apple Pay sheet programmatically

See original GitHub issue

Is your feature request related to a problem? Please describe. I don’t think so.

Describe the solution you’d like I would like to be able to call theuseApplePay()method, and it return a method which can be used to close the Apply Pay window.

Currently, it returns 3 methods, and one property. Can we add a 4th method? Maybe called closeApplePayWindow()

Additional context I have an application where the user can toggle between n subscription tiers. They can pay by entering their card info into the app, or choose to pay with Apple Pay.

If they choose to pay with Apple Pay, the window pops up asking which card they would like to use. Once they decide and select their card, the application sends a request to our Payment Service, with the payment id they selected. Our Payment Service will subscribe the customer to that subscription plan using the payment method. The Payment Service will return success if everything goes well.

The application is then done processing the payment. It updates the state as needed, but there is no way to close the Apple Pay window. This is normally done with the confirmApplePayPayment() function, but in our case, we did not use a PaymentIntent, and so we have no ClientSecret to pass it.

Describe alternatives you’ve considered The existing implementation outlined in the example project utilizes the PaymentIntent workflow. That is not ideal for the subscription model. If I try to create a PaymentIntent, there is no way I can specify what Subscription it corresponds to. This is a problem because once the PaymentIntent succeeds, there is no way our Payment Service can determine this and provision the correct features.

A work around would be to modify our Payment Service to store the PaymentIntent Id, and what Subscription it corresponds to. We could then setup a webhook that looks this up after the PaymentIntent succeeds, but this is (to me at least) not the cleanest way. I think it would be better to implement a method returned from useApplePay(). I can call this method and it will close the Apple Pay window.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
acatalinacommented, Jul 30, 2021

I’ve got another use case for this feature… I am confirming all my payments server side so I need to be able to call the completion block myself when I get confirmation from the server.

Edit: Forgot to mention that currently there is no way neither of programatically cancelling apple pay. Example would be: present apple pay, confirm payment, something goes wrong, UI cannot recover

4reactions
JacobJaffecommented, Mar 16, 2022

This is definitely a requirement of this SDK. What happens if our call to get a client secret from the server fails? Currently, we have to wait for the Apple Pay UI to timeout itself and disappear, we really need a way to programmatically dismiss it!

Is there a workaround for this? Even forcing an error state would be good (I’ve tried via calling confirmApplePayPayment with a dummy clientSecret, but that just… crashes the app)

Read more comments on GitHub >

github_iconTop Results From Across the Web

dismiss(completion:) - Documentation - Apple Developer
Instance Method. dismiss(completion:) Dismisses the payment sheet. iOS 10.0+ iPadOS 10.0+ macOS 11.0+ Mac Catalyst 13.0+ watchOS 3.0+. Declaration.
Read more >
Prevent user from dismissing Apple Pay's dialog ...
I'm adding PKPaymentAuthorizationViewController to my app. I present it, and after the payment method is authorized, I get the token at ...
Read more >
Integrating Apple Pay into your iOS App - Medium
Apple Pay is arguably the best form of payment in an iOS app. It's easy and efficient for both the user and the...
Read more >
Apple Pay Tutorial: Getting Started - RayWenderlich.com
Enter the world of mobile payments on iOS in this Apple Pay tutorial! ... You should see the Apple Pay sheet pop up...
Read more >
How to present a Bottom Sheet in iOS 15 with ... - Sarunw
A bottom sheet isn't an official term for this half-screen modal presentation style, but I will use this term for brevity. Basic Usage....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found