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

Apple Pay Custom Errors Implementation #1128

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tareksabry1337
Copy link

What this does

Since the SDK supports iOS 12 as a minimum right now, it was time to move away from Apple Pay iOS 10 delegate methods to iOS 11 delegate methods, this allows other developers to validate and provide custom errors through Apple Pay error objects such as

PKPaymentRequest.paymentContactInvalidError
PKPaymentRequest.paymentShippingAddressInvalidError
PKPaymentRequest.paymentBillingAddressInvalidError
PKPaymentRequest.paymentShippingAddressUnserviceableError

Instead of just showing "Shipping address is invalid", developers will be able to show specific error message which ultimately allows for a better customization when presenting Shopify's Apple Pay Modal.

This PR introduces breaking changes to PaySessionDelegate, all delegate methods now include extra error array in provide closures, and the final call which has completeTransaction closure now has associated type on its failure case to include array of errors, in order to display them on the UI.

PaySessionDelegate Changes

func paySession(_ paySession: PaySession, didRequestShippingRatesFor address: PayPostalAddress, checkout: PayCheckout, provide: @escaping (PayCheckout?, [PayShippingRate], [Error]?) -> Void)
func paySession(_ paySession: PaySession, didUpdateShippingAddress address: PayPostalAddress, checkout: PayCheckout, provide: @escaping (PayCheckout?, [Error]?) -> Void)
func paySession(_ paySession: PaySession, didSelectShippingRate shippingRate: PayShippingRate, checkout: PayCheckout, provide: @escaping (PayCheckout?, [Error]?) -> Void)
func paySession(_ paySession: PaySession, didAuthorizePayment authorization: PayAuthorization, checkout: PayCheckout, completeTransaction: @escaping (PaySession.TransactionStatus) -> Void)

Incentive

While implementing Shopify's Apple Pay modal, a requirement was defined that I need to validate all the user inputs and display custom messages on the UI. There was no way except for forking this and rolling my own implementation. I suppose this will be helpful for other developers that would face the same challenge.

Code Design / Convention / Tests

The PR ensures that the new implementation does not break the design of the code, naming conventions and all tests are passing.

@xanderbuck
Copy link

@tareksabry1337 was this ever integrated in the SDK, this would be awesome to have!

@tareksabry1337
Copy link
Author

@xanderbuck Unfortunately, the PR is stale, I am just rolling my own version and keeping it up to date with master branch

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

Successfully merging this pull request may close these issues.

2 participants