clientSecret
returned by your endpoint is used to complete the payment.
Important: Make sure to never share your API key with your client application as this could potentially compromise your payment flow.
Following this, create a unifiedCheckout and mount it to the placeholder div in your payment form. This embeds an iframe with a dynamic form that displays configured payment method types available from the Payment, allowing your customer to select a payment method. The form automatically collects the associated payment details for the selected payment method type.
In case you want the SDK to be loaded on a particular event (like button click), you can call the initialize function on that event.
onSDKHandleClick
and completeDoThis
that can be provided by merchants during the payment process. These callbacks allow merchants to hook into the payment flow at key stages and handle specific actions or events before continuing the normal flow.
onSDKHandleClick: This callback is triggered immediately after the user clicks any wallet button.
completeDoThis: This callback is triggered after the payment is completed, just before the SDK redirects to the walletReturnUrl
provided. It allows the merchant to handle actions post-payment. If not provided, the SDK’s default flow will proceed.
Redirection Handling: The completeDoThis
callback should handle redirection or any steps needed after payment, as the SDK no longer does this automatically. You must ensure to implement the necessary redirection logic.
Fallback: If no callbacks are provided by the merchant, the SDK will continue with its default behavior, including automatic redirection after payment completion.
Important: The task within onSDKHandleClick
must be completed within 1 second. If an asynchronous callback is used, it must resolve within this time to avoid Apple Pay payment failures.
confirmPayment()
, passing along the unifiedCheckout and a return_url
to indicate where Switch should redirect the user after they complete the payment. Switch redirects the customer to an authentication page depending on the payment method. After the customer completes the authentication process, they’re redirected to the return_url
.
return_url
, the payment_intent_client_secret
query parameter is appended by HyperLoader. Use this to retrieve the Payment to determine what to show to your customer.
clientSecret
returned by your endpoint is used to initialize the payment session.
initPaymentSession
Parameter | Description |
---|---|
clientSecret (string) | Required. Required to use as the identifier of the payment. |
paymentSession
object, the default customer payment method data can be fetched, using which you can craft your own payments experience. The paymentSession
object also exposes a confirmWithCustomerDefaultPaymentMethod
function, using which you can confirm and handle the payment session.
confirmWithCustomerDefaultPaymentMethod(payload)
Parameter | Description |
---|---|
confirmParams (object) | Parameters that will be passed on to the Switch API. |
redirect (string) | (web only) Can be either ‘always’ or ‘if_required’ By default, confirmWithCustomerDefaultPaymentMethod() will always redirect to your return_url after a successful confirmation. If you set redirect: “if_required”, then this method will only redirect if your user chooses a redirection-based payment method. |
Parameter | Description |
---|---|
return_url (string) | (web only) The url your customer will be directed to after they complete payment. |