JS SDK Reference
Setting Up
https://js.wooshpay.com
, rather than included in a bundle or hosted yourself.Initializing Wooshpay.js
Wooshpay(publishableKey, options?)
to create an instance of the Wooshpay
object. This object is the entrypoint to the rest of the JS SDK. Your publishable API key is required when calling this function, as it identifies your website to us. When you’re ready to accept live payments, replace the test key with your live key in production.Name | Required (M/C/O) | Type | Description |
---|---|---|---|
publishableKey | M | string | Your publishable key. |
options | O | object | Initialization options. |
The Element Object
Elements
instance to create and manage a group of individual Element instances.Create an Elements object
wooshpay.elements(options?)
Elements
instance, which manages a group of elements.Parameters
Name | Required (M/C/O) | Type | Description |
---|---|---|---|
options | O | object | A set of options to create this Elements instance with. clientSecret REQUIRED string Required to use with the Payment Element. The client secret for a PaymentIntent or SetupIntent. |
The Element
Element
instances to collect sensitive information in your checkout flow.Create a Payment Element
elements.create('payments', options?)
Parameters
Name | Required (M/C/O) | Type | Description |
---|---|---|---|
type | M | string | The type of Element being created, which is payment in this case. |
options | O | object | Options for creating the Payment Element. fields object By default, the Payment Element will collect all necessary details to complete a payment. For some payment methods, this means that the Payment Element will collect details like name or email that you may have already collected from the user. If this is the case, you can prevent the Payment Element from collecting these data by using the fields option. If you disable the collection of a certain field with the fields option, you must pass that same data to confirmPayment or the payment will be rejected.
|
Get a Payment Element
elements.getElement('payment')
Parameters
Name | Required (M/C/O) | Type | Description |
---|---|---|---|
type | M | string | The type of Element being created, which is payment in this case. |
Returns
elements.getElement('payment')
returns one of the following:null
, when no Payment Element has been created.Mount an Element
element.mount(domElement)
element.mount
method attaches your Element to the DOM. element.mount
accepts either a CSS Selector (e.g., '#card-element'
) or a DOM element.Element
. If the container DOM element has a label, the Element
is automatically focused when its label is clicked. There are two ways to do this:1.
<label>
.2.
<label>
with a for
attribute, referencing the ID of your container.Parameters
Name | Required (M/C/O) | Type | Description |
---|---|---|---|
domElement | M | string | DOM element | The CSS selector or DOM element where your Element will be mounted. |
Listen to Element events
Element events
elementType
property with the type of the Element
that emitted the event.Ready Event
element.on('ready', handler)
Element
is fully rendered.Parameters
Name | Required (M/C/O) | Type | Description |
---|---|---|---|
event | M | string | The name of the event. In this case, ready . |
handler | M | function | handler(event) => void is a callback function that you provide that will be called when the event is fired. |
Click Event
element.on('click',handler)
Element
is clicked.Parameters
Name | Required (M/C/O) | Type | Description |
---|---|---|---|
event | M | string | The name of the event. In this case, click . |
handler | M | function | handler(event) => void is a callback function that you provide that will be called when the event is fired. |
Input Validation
change
events on an Element
and display any errors.Example
Payment Intents
Confirm a PaymentIntent
wooshpay.confirmPayment(options)
wooshpay.confirmPayment
to confirm a PaymentIntent using data collected by the Payment Element. When called, wooshpay.confirmPayment
will attempt to complete any required actions, such as authenticating your user by displaying a 3DS dialog or redirecting them to a bank authorization page. Your user will be redirected to the return_url
you pass once the confirmation is complete.Parameters
Name | Required (M/C/O) | Type | Description |
---|---|---|---|
options | M | object | elements Required object The Elements instance that was used to create the Payment Element. confirmParams object Parameters that will be passed on to the api. Refer to the Payment Intents API for a full list of parameters.
By default, wooshpay.confirmPayment will only redirect if your user chooses a redirect-based payment method. If you set redirect : "always", then wooshpay.confirmPayment will always redirect to your return_url after a successful confirmation. |
Returns
wooshpay.confirmPayment
will return a Promise
. Upon a successful confirmation, your user will be redirected to the return_url
you provide before the Promise ever resolves. If the confirmation fails, the Promise
will resolve with an {error}
object that describes the failure. When the error type is card_error
or validation_error
, you can display the error message in error.message
directly to your user. Note that for some payment methods, your user will first be redirected to an intermediate page to authorize the payment. If they fail to authorize the payment, they will be redirected back to your return_url
and the PaymentIntent will have a status
of requires_payment_method
. In this case you should attempt to recollect payment from the user.wooshpay.confirmPayment
may take several seconds to complete. During that time, you should disable your form from being resubmitted and show a waiting indicator like a spinner. If you receive an error result, you should be sure to show that error to the customer, re-enable the form, and hide the waiting indicator.Retrieve a PaymentIntent
wooshpay.retrievePaymentIntent(clientSecret)
Parameters
Name | Required (M/C/O) | Type | Description |
---|---|---|---|
clientSecret | M | string | The client secret of the PaymentIntent to retrieve. |
Returns
Promise
which resolves with a result
object. This object has either:result.paymentIntent
: a PaymentIntent was retrieved successfully.result.error
: an error.Setup Intents
Confirm a SetupIntent
wooshpay.confirmSetup(options)
wooshpay.confirmSetup
to confirm a SetupIntent using data collected by the Payment Element. When called, wooshpay.confirmSetup
will attempt to complete any required actions, such as authenticating your user by displaying a 3DS dialog or redirecting them to a bank authorization page. Your user will be redirected to the return_url
you pass once the confirmation is complete.Parameters
Name | Required (M/C/O) | Type | Description |
---|---|---|---|
options | M | object | elements Required object The Elements instance that was used to create the Payment Element. confirmParams object Parameters that will be passed on to the api. Refer to the Setup Intents API for a full list of parameters.
By default, wooshpay.confirmPayment will only redirect if your user chooses a redirect-based payment method. If you set redirect : "always", then wooshpay.confirmPayment will always redirect to your return_url after a successful confirmation. |
Returns
wooshpay.confirmSetup
will return a Promise
. Upon a successful confirmation, your user will be redirected to the return_url
you provide before the Promise ever resolves. If the confirmation fails, the Promise
will resolve with an {error}
object that describes the failure. When the error type is card_error
or validation_error
, you can display the error message in error.message
directly to your user. Note that for some payment methods, your user will first be redirected to an intermediate page to authorize the payment. If they fail to authorize the payment, they will be redirected back to your return_url
and the PaymentIntent will have a status
of requires_payment_method
. In this case you should attempt to recollect payment from the user.wooshpay.confirmSetup
may take several seconds to complete. During that time, you should disable your form from being resubmitted and show a waiting indicator like a spinner. If you receive an error result, you should be sure to show that error to the customer, re-enable the form, and hide the waiting indicator.Retrieve a SetupIntent
wooshpay.retrieveSetupIntent(clientSecret)
Parameters
Name | Required (M/C/O) | Type | Description |
---|---|---|---|
clientSecret | M | string | The client secret of the SetupIntent to retrieve. |
Returns
Promise
which resolves with a result
object. This object has either:result.setupIntent
: a Setupintent was retrieved successfully.result.error
: an error.Checkout
wooshpay.redirectToCheckout(options?)
wooshpay.redirectToCheckout
to redirect your customers to Checkout page. When the customer completes their purchase, they are redirected back to your website.Parameters
Name | Required (M/C/O) | Type | Description |
---|---|---|---|
options | M | object | The parameter object. |
options object
Name | Required (M/C/O) | Type | Description |
---|---|---|---|
sessionId | M | string | The ID of the Checkout Session that is used in Checkout's client and server integration. |
Modified at 2023-02-06 11:22:17