Sessions and events
Learn how to create payment request sessions, attach event listeners, and handle the payment lifecycle with the Shop Pay Wallet API.
Anchor to Configure the APIConfigure the API
Use the shopId and clientId from your onboarding email to configure the API. For the full list of options, see configure parameters.
Anchor to Create a sessionCreate a session
Create a session to make a payment request. shop_id (integer) can be retrieved from the shop object in the Admin API.
PaymentRequest fields are defined here.
Anchor to Attach event listenersAttach event listeners
Use ShopPayPaymentRequestSessionCreate on your server to create a session.
Listen to events that may change calculations such as when a delivery method type, shipping address, delivery method, pickup location, pickup location filter, or discount code changes. Recalculate the payment request and update the session.
Confirm the payment once the user clicks the Pay now button in the Shop Pay popup.
The server confirmation must invoke the ShopPayPaymentRequestSessionSubmit mutation to confirm that the payment is to be processed.
Use ShopPayPaymentRequestSessionSubmit on your server to submit the session.
This event is dispatched when the payment is complete. Close the Shop Pay popup and redirect the user to the order confirmation page.
This event is dispatched when a payment attempt fails. The event contains information about why the payment failed.
Buyers have the option to select a different payment method to retry their checkout after a failure. Don't call session.close() so that users can retry with a new payment method without disrupting their session.
Buyers have the option to select a different payment method to retry their checkout after a failure. Don't call session.close() so that users can retry with a new payment method without disrupting their session.
This event is dispatched when the checkout window is closed.
Only call the corresponding complete call once for each event.
Only call the corresponding complete call once for each event.