Introduction
Payske.js reference
Looking for a step-by-step guide?
Learn to accept a payment or use the Payment Request Button.
Need to upgrade?
If you are currently using Payske.js v2 to collect card information, check out our migration guide to learn how to switch.
Not a developer?
Use apps from our partners to get started with Payske and to do more with your Payske account—no code required.
This reference documents every object and method available in Payske’s browser-side JavaScript library, Payske.js. Use our React Payske.js reference if you want to add Elements to your React based app.
You can use Payske.js’ APIs to tokenize customer information, collect sensitive payment details using customizable Payske Elements, and accept payments with browser payment APIs like Apple Pay and the Payment Request API.
Including Payske.js
<script src="https://js.payske.com/v3/"></script>
Include the Payske.js script on each page of your site—it should always be loaded directly from https://js.payske.com
, rather than included in a bundle or hosted yourself.
To best leverage Payske’s advanced fraud functionality, include this script on every page, not just the checkout page. This allows Payske to detect suspicious behavior that may be indicative of fraud as customers browse your website.
Using Payske.js as a module
We also provide an npm package that makes it easier to load and use Payske.js as a module. For more information, check out the project on GitHub.
Asynchronous and deferred loading of Payske.js
Asynchronous loading of JavaScript is generally recommended, as it can improve the user experience of your site by not blocking DOM rendering during script loading. The easiest way to asynchronously load Payske.js is to use the npm module as described above. It does asynchronous loading by default.
You can also load Payske.js using the async
or defer
attribute on the script tag. Note, however, that with asynchronous loading any API calls will have to be made only after the script execution has finished.
Was this section helpful? Yes No
Initializing Payske.js
Payske(publishableKey,options?)
var payske = Payske('pk_test_TYooMQauvdEDq54NiTphI7jx');
const payske = Payske('pk_test_TYooMQauvdEDq54NiTphI7jx');
Use Payske(publishableKey, options?)
to create an instance of the Payske object. The Payske object is your entrypoint to the rest of the Payske.js SDK.
Your Payske publishable API key is required when calling this function, as it identifies your website to Payske.
We've prefilled the example with a sample test API key. To create a Payske object using your account, replace the sample API key with your actual API key or sign in.
When you’re ready to accept live payments, replace the test key with your live key in production. Learn more about how API keys work in test mode and live mode.
Method parameters
publishableKey required string
Your publishable key.
options optional object
Initialization options.
Hide options properties
payskeAccount string
For usage with Connect only. Specifying a connected account ID (e.g.,
acct_24BFMpJ1svR5A89k
) allows you to perform actions on behalf of that account.apiVersion string
Override your account's API version.
locale string
A locale used to globally configure localization in Payske. Setting the locale here will localize error strings for all Payske.js methods. It will also configure the locale for Elements and Checkout. Default is
auto
(Payske detects the locale of the browser).Note that Checkout supports a slightly different set of locales than Payske.js.
Was this section helpful? Yes No
TOKENS AND SOURCES
Create Token
payske.createToken(Element,data?)
Create token from card
payske.createToken(cardElement).then(function(result) {
// Handle result.error or result.token
});
Create token from card
const {token, error} = await payske.createToken(cardElement);
Element:
- cardElement
- cardNumberElement
- cardCvcElement
- 'bank_account'
- 'person'
- 'account'
- 'cvc_update'
Use payske.createToken
to convert information collected by card elements into a single-use Token that you safely pass to your server to use in an API call.
Method parameters
cardElement required Element
The
card
Element you wish to tokenize data from. If applicable, theElement
tokenizes by pulling data from other elements you’ve created on the same instance of Elements—you only need to supply oneElement
as the parameter.data optional object
An object containing additional payment information you might have collected.
Although these fields are optional, we highly recommend collecting name and address. This information can be used to perform a number of verifications, such as CVC, ZIP, and address verification. Radar includes built-in rules that can block payments where the ZIP or CVC verifications with the cardholder’s bank failed.
Hide data properties
name recommended string
Cardholder name.
address_line1 string
address_line2 string
address_city string
address_state string
address_zip string
address_country recommended string
A two character country code (for example,
US
).currency string
Required in order to add the card to a Connect account (in all other cases, this parameter is not used).
Returns
payske.createToken
returns a Promise
which resolves with a result
object. This object has either:
result.token
: a Token was created successfully.result.error
: there was an error. This includes client-side validation errors. Refer to the API reference for all possible errors.
Was this section helpful? Yes No
Create a Source from Element
payske.createSource(element,sourceData)
Create a Source
payske
.createSource(ibanElement, {
type: 'sepa_debit',
currency: 'eur',
owner: {
name: 'Jenny Rosen',
},
})
.then(function(result) {
// Handle result.error or result.source
});
Create a Source
const {source, error} = await payske.createSource(
ibanElement,
{
type: 'sepa_debit',
currency: 'eur',
owner: {
name: 'Jenny Rosen',
},
},
);
Use payske.createSource
to convert payment information collected by elements into a Source object that you safely pass to your server to use in an API call. See the Sources documentation for more information about sources.
Method parameters
element required object
The Element containing payment information. If applicable, the
Element
pulls data from other elements you’ve created on the same Elements instance.sourceData required object
A required object containing the
type
ofSource
you want to create, and any additional payment information that you have collected. See the Sources API reference for details.
Returns
This method returns a Promise
which resolves with a result object. This object has either:
result.source
: a Source was created successfully.result.error
: there was an error. This includes client-side validation errors. Refer to the API reference for all possible errors.
Was this section helpful? Yes No
Create a Source from data
payske.createSource(sourceData)
Create a Source from data
payske
.createSource({
type: 'ideal',
amount: 1099,
currency: 'eur',
owner: {
name: 'Jenny Rosen',
},
redirect: {
return_url: 'https://shop.example.com/crtA6B28E1',
},
})
.then(function(result) {
// Handle result.error or result.source
});
Create a Source from data
const {source, error} = await payske.createSource({
type: 'ideal',
amount: 1099,
currency: 'eur',
owner: {
name: 'Jenny Rosen',
},
redirect: {
return_url: 'https://shop.example.com/crtA6B28E1',
},
});
Use payske.createSource
to convert raw payment information into a Source object that you can safely pass to your server for use in an API call. See the Sources documentation for more information about sources.
Method parameters
sourceData required object
A required object containing the
type
ofSource
you want to create, and any additional payment information that you have collected. See the Sources API reference for details.
Returns
This method returns a Promise
which resolves with a result object. This object has either:
result.source
: a Source was created successfully.result.error
: there was an error. This includes client-side validation errors. Refer to the API reference for all possible errors.
You cannot pass raw card information to payske.createSource(sourceData)
. Instead, you must gather card information in an Element and use payske.createSource(element, sourceData)
. You can also pass an existing card token to convert it into a Source
object.
Was this section helpful? Yes No
Retrieve a Source
payske.retrieveSource(source)
Retrieve a Source
payske
.retrieveSource({
id: '{SOURCE_ID}',
client_secret: '{SOURCE_CLIENT_SECRET}',
})
.then(function(result) {
// Handle result.error or result.source
});
Retrieve a Source
const {source, error} = await payske.retrieveSource({
id: '{{SOURCE_ID}}',
client_secret: '{{SOURCE_CLIENT_SECRET}}',
});
Retrieve a Source using its unique ID and client secret.
Method parameters
source required object
An object containing the unique ID and client secret for a
Source
.You can use a
Source
object created withpayske.createSource
as the argument topayske.retrieveSource
, as everySource
object has bothid
andclient_secret
keys.Hide source properties
Returns
This method returns a Promise
which resolves with a result object. This object has either:
result.source
: a Source was retrieved successfully.result.error
: there was an error. This includes client-side validation errors. Refer to the API reference for all possible errors.
Was this section helpful? Yes No
.
THE ELEMENTS OBJECT
Payske Elements are customizable UI components used to collect sensitive information in your payment forms.
Use an Elements
instance to create and manage a group of individual Element instances.
Create an Elements
payske.elements(options?)
Create an Elements instance
var elements = payske.elements({
clientSecret: 'CLIENT_SECRET',
});
Create an Elements instance
const elements = payske.elements({
clientSecret: 'CLIENT_SECRET',
});
This method creates an Elements
instance, which manages a group of elements.
Method parameters
options optional object
A set of options to create this
Elements
instance with.options properties
fonts array
An array of custom fonts, which elements created from the
Elements
object can use. Fonts can be specified as CssFontSource or CustomFontSource objects.locale string
A locale to display placeholders and error strings in. Default is
auto
(Payske detects the locale of the browser).Setting the locale does not affect the behavior of postal code validation—a valid postal code for the billing country of the card is still required.
appearance object
Used with the Payment Element.
Match the design of your site with the appearance option. The layout of each Element stays consistent, but you can modify colors, fonts, borders, padding, and more.
clientSecret required string
Requried to use with the Payment Element.
The client secret for a PaymentIntent or SetupIntent.
Was this section helpful?YesNo
Update Elements
Update Elements
elements.update({locale: 'fr'});
Update Elements
elements.update({locale: 'fr'});
elements.update(options)
This method updates options on an existing instance of Elements
. Note that not all options (e.g. fonts
) are updatable.
Method parameters
options required object
A set of options to update this
Elements
instance with.options properties
locale string
A locale to display placeholders and error strings in. Default is
auto
(Payske detects the locale of the browser).Setting the locale does not affect the behavior of postal code validation—a valid postal code for the billing country of the card is still required.
appearance object
Used with the Payment Element.
Match the design of your site with the appearance option. The layout of each Element stays consistent, but you can modify colors, fonts, borders, padding, and more.
Was this section helpful?YesNo
THE ELEMENT
Use Element
instances to collect sensitive information in your checkout flow.
The Payment Element
The Payment Element is an embeddable component for securely collecting payment details. The Payment Element supports dozens of payment methods with a single integration.
Create the Payment Element
elements.create('payment',options?)
Create a Payment Element
var paymentElement = elements.create('payment');
Create a Payment Element
const paymentElement = elements.create('payment');
This method creates an instance of the Payment Element.
Method parameters
type required 'payment'
The type of Element being created, which is
payment
in this case.options optional object
Options for creating the Payment Element.
options properties
business object
Provide information about your business that will be displayed in the Payment Element. This information will be retrieved from your Payske account if not provided.
business properties
paymentMethodOrder array
By default, the Payment Element will use a dynamic ordering that optimizes payment method display for each user.
You can override the default order in which payment methods are displayed in the Payment Element with a list of payment method types.
If the associated PaymentIntent has payment method types not specified in
paymentMethodOrder
, they will be displayed after the payment methods you specify. If you specify payment method types not on the associated PaymentIntent, they will be ignored.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 payske.confirmPayment or the payment will be rejected.See below for details.
fields properties
billingDetails 'never' | 'auto' | object
Specify
never
to avoid collecting all billing details in the Payment Element. If you would like to disable only certain billing details, pass an object specifying which fields you would like to disable collection for. The default setting for each field or object isauto
.billingDetails properties
terms object
Control how mandates or other legal agreements are displayed in the Payment Element. Use
never
to never display legal agreements. The default setting isauto
, which causes legal agreements to only be shown when necessary.terms properties
wallets object
By default, the Payment Element will display all the payment methods that the underlying Payment Intent was created with.
However, wallets like Apple Pay and Google Pay are not payment methods per the Payment Intent API. They will show when the the Payment Intent has the
card
payment method and the customer is using a supported platform and have an active card in their account. This is theauto
behavior, and it is the default for choice for all wallets.If you do not want to show a given wallet as a payment option, you can set its property in
wallets
tonever
.wallets properties
with customized fields
Create a Payment Element with customized fields
// Customize which fields are collected by the Payment Element
var paymentElement = elements.create('payment', {
fields: {
billingDetails: {
name: 'never',
email: 'never',
}
}
});
// If you disable collecting fields in the Payment Element, you
// must pass equivalent data when calling `payske.confirmPayment`.
form.addEventListener('submit', async (event) => {
payske.confirmPayment({
elements,
confirmParams: {
return_url: 'https://example.com',
payment_method_data: {
billing_details: {
name: 'Jenny Rosen',
email: 'jenny.rosen@example.com',
}
},
},
})
.then(function(result) {
if (result.error) {
// Inform the customer that there was an error.
}
});
});
Create a Payment Element with customized fields
// Customize which fields are collected by the Payment Element
const paymentElement = elements.create('payment', {
fields: {
billingDetails: {
name: 'never',
email: 'never',
}
}
});
// If you disable collecting fields in the Payment Element, you
// must pass equivalent data when calling `payske.confirmPayment`.
const handleSubmit = async () => {
const {error} = await payske.confirmPayment({
elements,
confirmParams: {
return_url: 'https://example.com/return',
payment_method_data: {
billing_details: {
name: 'Jenny Rosen',
email: 'jenny.rosen@example.com',
}
},
},
});
// Other actions ...
};
Option parameter
fields object
Pass an object to specify payment
fields
you don't want to collect with the Payment Element.fields properties
billingDetails 'never' | 'auto' | object
Specify
never
to avoid collecting all billing details in the Payment Element. If you would like to disable only certain billing details, pass an object specifying which fields you would like to disable collection for. The default setting for each field or object isauto
.billingDetails properties
Get a Payment Element
elements.getElement('payment')
Get a Payment Element
const paymentElement = elements.getElement('payment');
Get a Payment Element
var paymentElement = elements.getElement('payment');
This method retrieve a previously created Payment Element.
Method parameters
Returns
elements.getElement('payment')
returns one of the following:
- An instance of a Payment Element.
null
, when no Payment Element has been created.
Was this section helpful?YesNo
Update a Payment Element
element.update(options)
Update a Payment Element
// Update a Payment Element after creation
var paymentElement = elements.getElement('payment');
paymentElement.update({business: {name: 'Payske Shop'}});
Update a Payment Element
// Update a Payment Element after creation
const paymentElement = elements.getElement('payment');
paymentElement.update({business: {name: 'Payske Shop'}});
Updates the options the Payment Element was initialized with. Updates are merged into the existing configuration.
Method parameters
options optional object
Options for updating the Payment Element.
options properties
business object
Provide information about your business that will be displayed in the Payment Element. This information will be retrieved from your Payske account if not provided.
Hide business properties
paymentMethodOrder array
By default, the Payment Element will use a dynamic ordering that optimizes payment method display for each user.
You can override the default order in which payment methods are displayed in the Payment Element with a list of payment method types.
If the associated PaymentIntent has payment method types not specified in
paymentMethodOrder
, they will be displayed after the payment methods you specify. If you specify payment method types not on the associated PaymentIntent, they will be ignored.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 payske.confirmPayment or the payment will be rejected.See below for details.
fields properties
billingDetails 'never' | 'auto' | object
Specify
never
to avoid collecting all billing details in the Payment Element. If you would like to disable only certain billing details, pass an object specifying which fields you would like to disable collection for. The default setting for each field or object isauto
.billingDetails properties
terms object
Control how mandates or other legal agreements are displayed in the Payment Element. Use
never
to never display legal agreements. The default setting isauto
, which causes legal agreements to only be shown when necessary.terms properties
wallets object
By default, the Payment Element will display all the payment methods that the underlying Payment Intent was created with.
However, wallets like Apple Pay and Google Pay are not payment methods per the Payment Intent API. They will show when the the Payment Intent has the
card
payment method and the customer is using a supported platform and have an active card in their account. This is theauto
behavior, and it is the default for choice for all wallets.If you do not want to show a given wallet as a payment option, you can set its property in
wallets
tonever
.wallets properties
Was this section helpful?Yes No
The Card Element
Payske also offers a set of Elements for individual payment methods that you can use in your payment flows.
Create a card Element
elements.create('card',options?)
Create a card Element
var cardElement = elements.create('card');
Create a card Element
const cardElement = elements.create('card');
This method creates an instance of an individual Element
.
It takes the type
of Element
to create as well as an options
object.
Method parameters
type required 'card'
The type of element you are creating. In this case,
card
.options optional object
Options for creating a
card
element.options properties
classes object
Set custom class names on the container DOM element when the Payske element is in a particular state.
classes properties
base string
The base class applied to the container. Defaults to
PayskeElement
.complete string
The class name to apply when the
Element
is complete. Defaults toPayskeElement--complete
.empty string
The class name to apply when the
Element
is empty. Defaults toPayskeElement--empty
.focus string
The class name to apply when the
Element
is focused. Defaults toPayskeElement--focus
.invalid string
The class name to apply when the
Element
is invalid. Defaults toPayskeElement--invalid
.webkitAutofill string
The class name to apply when the
Element
has its value autofilled by the browser (only on Chrome and Safari). Defaults toPayskeElement--webkit-autofill
.
style object
Customize the appearance of this element using CSS properties passed in a Style object.
value string
A pre-filled set of values to include in the input (e.g.,
{postalCode: '94110'}
). Note that sensitive card information (card number, CVC, and expiration date) cannot be pre-filledhidePostalCode boolean
Hide the postal code field. Default is
false
. If you are already collecting a full billing address or postal code elsewhere, set this totrue
.iconStyle string
Appearance of the icon in the Element. Either
solid
ordefault
.hideIcon boolean
Hides the icon in the Element. Default is
false
.disabled boolean
Applies a disabled state to the Element such that user input is not accepted. Default is
false
.
Was this section helpful?YesNo
Get an Element
elements.getElement(type)
Get an Element
var cardElement = elements.getElement('card');
Get an Element
const cardElement = elements.getElement('card');
This method looks up a previously created Element by its type.
Method parameters
type required string
The type of Element to lookup.
Returns
elements.getElement
returns one of the following:
- An instance of an
Element
with a matching type. null
, when noElement
with a matching type has been created.
Was this section helpful?YesNo
Update a card element
card.update(options)
Update a card element
// Update an element with details collected elsewhere on your page
var myPostalCodeField = document.querySelector('input[name="my-postal-code"]');
myPostalCodeField.addEventListener('change', function(event) {
cardElement.update({value: {postalCode: event.target.value}});
});
// Dynamically change the styles of an element
window.addEventListener('resize', function(event) {
if (window.innerWidth <= 320) {
cardElement.update({style: {base: {fontSize: '13px'}}});
} else {
cardElement.update({style: {base: {fontSize: '16px'}}});
}
});
Update a card element
// Update an element with details collected elsewhere on your page
const myPostalCodeField = document.querySelector(
'input[name="my-postal-code"]',
);
myPostalCodeField.addEventListener('change', ({target}) => {
cardElement.update({value: {postalCode: target.value}});
});
// Dynamically change the styles of an element
window.addEventListener('resize', (event) => {
if (window.innerWidth <= 320) {
cardElement.update({style: {base: {fontSize: '13px'}}});
} else {
cardElement.update({style: {base: {fontSize: '16px'}}});
}
});
Updates the options the Element was initialized with. Updates are merged into the existing configuration.
If you collect certain information in a different part of your interface (e.g., ZIP or postal code), use element.update
with the appropriate information.
The styles of an Element
can be dynamically changed using element.update
. This method can be used to simulate CSS media queries that automatically adjust the size of elements when viewed on different devices.
Method parameters
options optional object
Options for updating a
card
element.options properties
classes object
Set custom class names on the container DOM element when the Payske element is in a particular state.
classes properties
base string
The base class applied to the container. Defaults to
PayskeElement
.complete string
The class name to apply when the
Element
is complete. Defaults toPayskeElement--complete
.empty string
The class name to apply when the
Element
is empty. Defaults toPayskeElement--empty
.focus string
The class name to apply when the
Element
is focused. Defaults toPayskeElement--focus
.invalid string
The class name to apply when the
Element
is invalid. Defaults toPayskeElement--invalid
.webkitAutofill string
The class name to apply when the
Element
has its value autofilled by the browser (only on Chrome and Safari). Defaults toPayskeElement--webkit-autofill
.
style object
Customize the appearance of this element using CSS properties passed in a Style object.
value string
A pre-filled set of values to include in the input (e.g.,
{postalCode: '94110'}
). Note that sensitive card information (card number, CVC, and expiration date) cannot be pre-filledhidePostalCode boolean
Hide the postal code field. Default is
false
. If you are already collecting a full billing address or postal code elsewhere, set this totrue
.iconStyle string
Appearance of the icon in the Element. Either
solid
ordefault
.hideIcon boolean
Hides the icon in the Element. Default is
false
.disabled boolean
Applies a disabled state to the Element such that user input is not accepted. Default is
false
.
Was this section helpful?YesNo
Style the Element container
The Element container
<style>
.my-input {
padding: 10px;
border: 1px solid #ccc;
}
</style>
<form>
<div>
<label>Name</label>
<input class="my-input">
</div>
<div>
<label>Card</label>
<!-- Using the same "my-input" class on the -->
<!-- regular input above and on this container. -->
<div class="my-input" id="card-element"></div>
</div>
</form>
Style the container you mount an Element to as if it were an <input>
on your page. For example, to control padding
and border
on an Element
, set these properties on the container. This is usually done by re-using the classes that you have applied to your DOM <input>
elements. After the Element
is mounted, the .PayskeElement
class is added to the container. Additionally, the following classes are automatically added to the container when the Element
is complete, empty, focused, invalid, or autofilled by the browser:
.PayskeElement--complete
.PayskeElement--empty
.PayskeElement--focus
.PayskeElement--invalid
.PayskeElement--webkit-autofill
(Chrome and Safari only)
These class names can be customized using the classes
option when you create an Element.
Was this section helpful?YesNo
Mount an Element
element.mount(domElement)
Mount an Element
<!-- Mount the instance within a <label> -->
<label>Card
<div id="card-element"></div>
</label>
<!--
Or create a <label> with a 'for' attribute,
referencing the ID of your container.
-->
<label for="card-element">Card</label>
<div id="card-element"></div>
<script>
cardElement.mount('#card-element');
</script>
The element.mount
method attaches your Element to the DOM. element.mount
accepts either a CSS Selector (e.g., '#card-element'
) or a DOM element.
You need to create a container DOM element to mount an 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:
- Mount the instance within a
<label>
. - Create a
<label>
with afor
attribute, referencing the ID of your container.
Method parameters
domElement required string | DOM element
The CSS selector or DOM element where your Element will be mounted.
Was this section helpful?Yes No
Element events
The only way to communicate with your Element is by listening to an event. An Element might emit any of the events below. All events have a payload object that has an elementType
property with the type of the Element
that emitted the event.
Change event
Payment Element:-
paymentElement.on('change',handler)
Handle a payment element change event
paymentElement.on('change', function(event) {
if (event.complete) {
// enable payment button
}
});
Handle a payment element change event
paymentElement.on('change', (event) => {
if (event.complete) {
// enable payment button
}
});
Handler event object
{
elementType: 'payment',
complete: false,
empty: false,
collapsed: false,
value: { type: "card" },
}
The change event is triggered when the Element
's value changes. The event payload always contains certain keys, in addition to some Element
-specific keys.
Method parameters
event required 'change'
The name of the event. In this case,
change
.handler required function
handler(event) => void
is a callback function that you provide that will be called when the event is fired. When called it will be passed an event object with the following properties:handler event object properties
Was this section helpful?YesNo
Card Element:-
cardElement.on('change',handler)
Handle a card change event
cardElement.on('change', function(event) {
if (event.complete) {
// enable payment button
} else if (event.error) {
// show validation to customer
}
});
Handle a card change event
cardElement.on('change', (event) => {
if (event.complete) {
// enable payment button
} else if (event.error) {
// show validation to customer
}
});
Handler event object
{
complete: false,
brand: 'visa',
elementType: 'card',
empty: false,
error: undefined,
value: { postalCode: "" },
}
The change event is triggered when the Element
's value changes. The event payload always contains certain keys, in addition to some Element
-specific keys.
Method parameters
event required 'change'
The name of the event. In this case,
change
.handler required function
handler(event) => void
is a callback function that you provide that will be called when the event is fired. When called it will be passed an event object with the following properties:handler event object properties
elementType string
The type of element that emitted this event.
empty boolean
true
if the value is empty.complete boolean
true
if the value is well-formed and potentially complete. Thecomplete
value can be used to progressively disclose the next parts of your form or to enable form submission.It is not an indicator of whether a customer is done with their input—it only indicates that the Element contains a potentially complete, well-formed value. In many cases the customer could still add further input.
The
complete
value should not be used to perform an action such as advancing the cursor to a subsequent field or performing a tokenization request.error object
The current validation error, if any. Comprised of
message
,code
, andtype
. Thetype
is always set tovalidation_error
.value string, object
brand string
Was this section helpful?YesNo
Card Number Element:-
cardNumberElement.on('change',handler)
Handle a cardNumber change event
cardNumberElement.on('change', function(event) {
if (event.error) {
// show validation to customer
}
});
Handle a cardNumber change event
cardNumberElement.on('change', (event) => {
if (event.error) {
// show validation to customer
}
});
Handler event object
{
complete: true,
brand: 'visa',
elementType: 'cardNumber',
empty: false,
error: undefined,
}
The change event is triggered when the Element
's value changes. The event payload always contains certain keys, in addition to some Element
-specific keys.
Method parameters
event required 'change'
The name of the event. In this case,
change
.handler required function
handler(event) => void
is a callback function that you provide that will be called when the event is fired. When called it will be passed an event object with the following properties:handler event object properties
elementType string
The type of element that emitted this event.
empty boolean
true
if the value is empty.complete boolean
true
if the value is well-formed and potentially complete. Thecomplete
value can be used to progressively disclose the next parts of your form or to enable form submission.It is not an indicator of whether a customer is done with their input—it only indicates that the Element contains a potentially complete, well-formed value. In many cases the customer could still add further input.
The
complete
value should not be used to perform an action such as advancing the cursor to a subsequent field or performing a tokenization request.error object
The current validation error, if any. Comprised of
message
,code
, andtype
. Thetype
is always set tovalidation_error
.brand string
Was this section helpful?YesNo
Card Expiry Element:-
cardExpiryElement.on('change',handler)
Handle a cardExpiry change event
cardExpiryElement.on('change', function(event) {
if (event.error) {
// show validation to customer
}
});
Handle a cardExpiry change event
cardExpiryElement.on('change', (event) => {
if (event.error) {
// show validation to customer
}
});
Handler event object
{
complete: true,
elementType: 'cardExpiry',
empty: false,
error: undefined,
}
The change event is triggered when the Element
's value changes. The event payload always contains certain keys, in addition to some Element
-specific keys.
Method parameters
event required 'change'
The name of the event. In this case,
change
.handler required function
handler(event) => void
is a callback function that you provide that will be called when the event is fired. When called it will be passed an event object with the following properties:Hide handler event object properties
elementType string
The type of element that emitted this event.
empty boolean
true
if the value is empty.complete boolean
true
if the value is well-formed and potentially complete. Thecomplete
value can be used to progressively disclose the next parts of your form or to enable form submission.It is not an indicator of whether a customer is done with their input—it only indicates that the Element contains a potentially complete, well-formed value. In many cases the customer could still add further input.
The
complete
value should not be used to perform an action such as advancing the cursor to a subsequent field or performing a tokenization request.error object
The current validation error, if any. Comprised of
message
,code
, andtype
. Thetype
is always set tovalidation_error
.
Was this section helpful?YesNo
Card Cvc Element:-
cardCvcElement.on('change',handler)
Handle a cardCvc change event
cardCvcElement.on('change', function(event) {
if (event.error) {
// show validation to customer
}
});
Handle a cardCvc change event
cardCvcElement.on('change', (event) => {
if (event.error) {
// show validation to customer
}
});
Handler event object
{
complete: true,
elementType: 'cardCvc',
empty: false,
error: undefined,
}
The change event is triggered when the Element
's value changes. The event payload always contains certain keys, in addition to some Element
-specific keys.
Method parameters
event required 'change'
The name of the event. In this case,
change
.handler required function
handler(event) => void
is a callback function that you provide that will be called when the event is fired. When called it will be passed an event object with the following properties:handler event object properties
elementType string
The type of element that emitted this event.
empty boolean
true
if the value is empty.complete boolean
true
if the value is well-formed and potentially complete. Thecomplete
value can be used to progressively disclose the next parts of your form or to enable form submission.It is not an indicator of whether a customer is done with their input—it only indicates that the Element contains a potentially complete, well-formed value. In many cases the customer could still add further input.
The
complete
value should not be used to perform an action such as advancing the cursor to a subsequent field or performing a tokenization request.error object
The current validation error, if any. Comprised of
message
,code
, andtype
. Thetype
is always set tovalidation_error
.
Was this section helpful?YesNo
Ready Event
element.on('ready',handler)
Handle an Element ready event
element.on('ready', function(event) {
// Handle ready event
});
Handle an Element ready event
element.on('ready', (event) => {
// Handle ready event
});
Triggered when the Element
is fully rendered and can accept element.focus
calls.
Method parameters
event required 'ready'
The name of the event. In this case,
ready
.handler required function
handler(event) => void
is a callback function that you provide that will be called when the event is fired.
Was this section helpful?YesNo
Focus event
element.on('focus',handler)
Handle an Element focus event
element.on('focus', function(event) {
// Handle focus event
});
Handle an Element focus event
element.on('focus', (event) => {
// Handle focus event
});
Triggered when the Element
gains focus.
Method parameters
event required 'focus'
The name of the event. In this case,
focus
.handler required function
handler(event) => void
is a callback function that you provide that will be called when the event is fired.
Was this section helpful?YesNo
Blur event
element.on('blur',handler)
Handle an Element blur event
element.on('blur', function(event) {
// Handle blur event
});
Handle an Element blur event
element.on('blur', (event) => {
// Handle blur event
});
Triggered when the Element
loses focus.
Method parameters
event required 'blur'
The name of the event. In this case,
blur
.handler required function
handler(event) => void
is a callback function that you provide that will be called when the event is fired.
Was this section helpful?YesNo
Escape event
element.on('escape',handler)
Handle an Element escape event
element.on('escape', function(event) {
// Handle escape event
});
Handle an Element escape event
element.on('escape', (event) => {
// Handle escape event
});
Triggered when the escape key is pressed within an Element.
Method parameters
event required 'escape'
The name of the event. In this case,
escape
.handler required function
handler(event) => void
is a callback function that you provide that will be called when the event is fired.
Was this section helpful?YesNo
Click event
element.on('click',handler)
Handle an Element click event
paymentRequestButtonElement.on('click', function(event) {
// Handle click event
});
Handle an Element click event
paymentRequestButtonElement.on('click', (event) => {
// Handle click event
});
Triggered when the Element
is clicked.
This event is only emmited from a paymentRequestButton
and issuingCardCopyButton
Element.
Method parameters
event required 'click'
The name of the event. In this case,
click
.handler required function
handler(event) => void
is a callback function that you provide that will be called when the event is fired.When called it will be passed an event object with the following properties:
Hide handler event object properties
Was this section helpful?YesNo
Input validation
Display validation errors from an Element
cardElement.on('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
Display validation errors from an Element
cardElement.on('change', ({error}) => {
const displayError = document.getElementById('payment-errors');
if (error) {
displayError.textContent = error.message;
}
});
Payske elements validate customer input as it is typed. To help your customers catch mistakes, listen to change
events on an Element
and display any errors.
Postal code formatting
The card
element automatically determines your customer’s billing address country based on their card number. Using this information, the postal code field validation reflects whether that country uses numeric or alphanumeric-formatted postal codes, or if the country uses postal codes at all. For instance, if a U.S. card is entered, the postal code field only accepts a five-digit numeric value. If it’s a UK card, an alphanumeric value can be provided instead.
Many of our test cards have a U.S. billing address country. When using these to test your payment form, you must also use a five-digit U.S. ZIP code (e.g., 12345). To test elements with other postal code formats, use our international test card numbers.
Was this section helpful?YesNo
.
CHECKOUT
Payske Checkout is the quickest way to start accepting payments on Payske. Send your customers to pay on Payske’s conversion-optimized page instead of building your own.
Redirect to Checkout
payske.redirectToCheckout(options?)
Redirect to Checkout
// Call your backend to create the Checkout Session
fetch('/create-checkout-session', {
method: 'POST',
})
.then(function(response) {
return response.json();
})
.then(function(session) {
return payske.redirectToCheckout({ sessionId: session.id });
})
.then(function(result) {
// If `redirectToCheckout` fails due to a browser or network
// error, you should display the localized error message to your
// customer using `error.message`.
if (result.error) {
alert(result.error.message);
}
});
Redirect to Checkout
// Call your backend to create the Checkout Session
const response = await fetch('/create-checkout-session', { method: 'POST' });
const session = await response.json();
// When the customer clicks on the button, redirect them to Checkout.
const result = await payske.redirectToCheckout({
sessionId: session.id,
});
if (result.error) {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `result.error.message`.
}
Use payske.redirectToCheckout
to redirect your customers to Checkout, a Payske-hosted page to securely collect payment information. When the customer completes their purchase, they are redirected back to your website.
Method parameters
options optional object
Hide options properties
sessionId string
The ID of the Checkout Session that is used in Checkout's client and server integration.
lineItems array
An array of objects representing the items that your customer would like to purchase. These items are shown as line items in the Checkout interface and make up the total amount to be collected by Checkout. Used with the client-only integration.
Hide lineItems properties
mode string
The mode of the Checkout Session, one of
payment
orsubscription
. Required if usinglineItems
with the client-only integration.successUrl string
The URL to which Payske should send customers when payment is complete. If you’d like access to the Checkout Session for the successful payment, read more about it in the guide on fulfilling orders. Required if using the client-only integration.
cancelUrl string
The URL to which Payske should send customers when payment is canceled. Required if using the client-only integration.
clientReferenceId string
A unique string to reference the Checkout session. This can be a customer ID, a cart ID, or similar. It is included in the
checkout.session.completed
webhook and can be used to fulfill the purchase.customerEmail string
The email address used to create the customer object. If you already know your customer's email address, use this attribute to prefill it on Checkout.
billingAddressCollection string
Specify whether Checkout should collect the customer’s billing address. If set to
required
, Checkout will attempt to collect the customer’s billing address. If not set or set toauto
Checkout will only attempt to collect the billing address when necessary.shippingAddressCollection object
When set, provides configuration for Checkout to collect a shipping address from a customer.
Hide shippingAddressCollection properties
allowedCountries required array
An array of two-letter ISO country codes representing which countries Checkout should provide as options for shipping locations. Unsupported country codes:
AS, CX, CC, CU, HM, IR, KP, MH, FM, NF, MP, PW, SD, SY, UM, VI
.
locale string
A locale that will be used to localize the display of Checkout. Default is
auto
(Payske detects the locale of the browser).submitType string
Describes the type of transaction being performed by Checkout in order to customize relevant text on the page, such as the Submit button.
submitType
can only be specified when using using line items or SKUs, and not subscriptions. The default isauto
. Supported values are:auto
,book
,donate
,pay
.items array
An array of objects representing the items that your customer would like to purchase. These items are shown as line items in the Checkout interface and make up the total amount to be collected by Checkout. Using
lineItems
is preferred.Hide items properties
Returns
This method returns a Promise
which resolves with a result object. If this method fails, the result object will contain a localized error message in the error.message
field.
If you are currently on a beta of the new version of Checkout, read the Beta Migration Guide to upgrade to the latest version.
Was this section helpful? Yes No
.
PAYMENT INTENTS
Accept global payments online with the Payment Intents APIs. For step-by-step instructions on using the Payment Intents APIs, see the accept a payment guide.
The following Payske.js methods are available to use as part of your integration.
Was this section helpful?YesNo
Confirm a PaymentIntent
payske.confirmPayment(options)
Confirm a payment intent
payske.confirmPayment({
elements,
confirmParams: {
// Return URL where the customer should be redirected after the PaymentIntent is confirmed.
return_url: 'https://example.com',
},
})
.then(function(result) {
if (result.error)
// Inform the customer that there was an error.
});
Confirm a payment intent
const {error} = await payske.confirmPayment(
{
elements,
confirmParams: {
// Return URL where the customer should be redirected after the PaymentIntent is confirmed.
return_url: 'https://example.com',
},
}
);
Use payske.confirmPayment
to confirm a PaymentIntent using data collected by the Payment Element. When called, payske.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.
Method parameters
options required object
options properties
elements required object
The Elements instance that was used to create the Payment Element.
confirmParams object
Parameters that will be passed on to the Payske API to confirm the PaymentIntent.
confirmParams properties
return_url required string
The url your customer will be directed to after they complete payment.
shipping recommended object
The shipping details for the payment, if collected.
payment_method_data object
When you call
payske.confirmPayment
, payment details are collected from the Element and passed to the PaymentIntents confirm endpoint as the payment_method_data parameter. You can also include additionalpayment_method_data
fields, which will be merged with the data collected from the Element.payment_method_data properties
billing_details object
The customer's billing_details. Details collected by Elements will override values passed here. Billing fields that are omitted in the Payment Element via the
fields
option required.
redirect 'always' | 'if_required'
By default,
payske.confirmPayment
will always redirect to yourreturn_url
after a successful confirmation. If you setredirect: "if_required"
, thenpayske.confirmPayment
will only redirect if your user chooses a redirect-based payment method.Note: Setting
if_required
requires that you handle successful confirmations for redirect-based and non-redirect based payment methods separately. When a non-redirect based payment method is successfully confirmed,payske.confirmPayment
will resolve with a{paymentIntent}
object.
Returns
payske.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 such as iDEAL or Afterpay Clearpay, 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.
Note that payske.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.
Was this section helpful?YesNo
Confirm by payment method
Below are a number of methods used to confirm a PaymentIntent for a specific payment method type.
Confirm a card payment
payske.confirmCardPayment(clientSecret,data?,options?)
Confirm a card payment
payske
.confirmCardPayment('{PAYMENT_INTENT_CLIENT_SECRET}', {
payment_method: {
card: cardElement,
billing_details: {
name: 'Jenny Rosen',
},
},
})
.then(function(result) {
// Handle result.error or result.paymentIntent
});
Confirm a card payment
const {paymentIntent, error} = await payske.confirmCardPayment(
'{PAYMENT_INTENT_CLIENT_SECRET}',
{
payment_method: {
card: cardElement,
billing_details: {
name: 'Jenny Rosen',
},
},
},
);
Use payske.confirmCardPayment
when the customer submits your payment form. When called, it will confirm the PaymentIntent with data
you provide and carry out 3DS or other next actions if they are required.
If you are using Dynamic 3D Secure, payske.confirmCardPayment
will trigger your Radar rules to execute and may open a dialog for your customer to authenticate their payment.
When you confirm a PaymentIntent
, it needs to have an attached PaymentMethod. In addition to confirming the PaymentIntent
, this method can automatically create and attach a new PaymentMethod
for you. It can also be called with an existing PaymentMethod
, or if you have already attached a PaymentMethod
you can call this method without needing to provide any additional data. These use cases are detailed in the sections that follow.
Method parameters
clientSecret required string
The client secret of the
PaymentIntent
.data optional object
Data to be sent with the request. Refer to the Payment Intents API for a full list of parameters.
data properties
payment_method recommended string | object
Either the
id
of an existing PaymentMethod, or an object containing data to create aPaymentMethod
with. See the use case sections below for details.shipping recommended object
The shipping details for the payment, if collected.
return_url string
If you are handling next actions yourself, pass in a
return_url
. If the subsequent action isredirect_to_url
, this URL will be used on the return path for the redirect.receipt_email string
Email address that the receipt for the resulting payment will be sent to.
setup_future_usage string
Indicates that you intend to make future payments with this PaymentIntent's payment method.
If present, the payment method used with this PaymentIntent can be attached to a Customer, even after the transaction completes.
Use
on_session
if you intend to only reuse the payment method when your customer is present in your checkout flow. Useoff_session
if your customer may or may not be in your checkout flow. See saving card details during payment to learn more.Payske uses
setup_future_usage
to dynamically optimize your payment flow and comply with regional legislation and network rules. For example, if your customer is impacted by SCA, usingoff_session
will ensure that they are authenticated while processing this PaymentIntent. You will then be able to collect off-session payments for this customer.payment_method_options object
An object containing payment-method-specific configuration to confirm the PaymentIntent with.
payment_method_options properties
card object
Configuration for this card payment.
card properties
cvc Element
Use the provided
cardCvc
Element when confirming the PaymentIntent with an existing PaymentMethod.network string
Selected network to process this PaymentIntent on. Depends on the available networks of the card attached to the PaymentIntent. Can only be set at confirm-time.
options optional object
An options object to control the behavior of this method.
options properties
handleActions boolean
Set this to
false
if you want to handle next actions yourself, or if you want to defer next action handling until later (e.g. for use in the PaymentRequest API). Default istrue
.
Returns
payske.confirmCardPayment
will return a Promise
which resolves with a result
object. This object has either:
result.paymentIntent
: the successful PaymentIntent.result.error
: an error. Refer to the API reference for all possible errors.
Note that payske.confirmCardPayment
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.
Additionally, payske.confirmCardPayment
may trigger a 3D Secure authentication challenge. This will be shown in a modal dialog and may be confusing for customers using assistive technologies like screen readers. You should make your form accessible by ensuring that success or error messages are clearly read out after this method completes.
-with data from an Element
Confirm a card payment with payment data from an Element
Confirm with an Element
payske
.confirmCardPayment('{PAYMENT_INTENT_CLIENT_SECRET}', {
payment_method: {
card: cardElement,
billing_details: {
name: 'Jenny Rosen',
},
},
})
.then(function(result) {
// Handle result.error or result.paymentIntent
});
Confirm with an Element
const {paymentIntent, error} = await payske.confirmCardPayment(
'{PAYMENT_INTENT_CLIENT_SECRET}',
{
payment_method: {
card: cardElement,
billing_details: {
name: 'Jenny Rosen',
},
},
},
);
Use payske.confirmCardPayment
with payment data from an Element by passing a card
or cardNumber
Element as payment_method[card]
in the data argument.
The new PaymentMethod
will be created with data collected by the Element
and will be used to confirm the PaymentIntent
.
Data argument properties
payment_method required object
Pass an object to confirm using data collected by a
card
orcardNumber
Element.payment_method properties
card required Element
Uses the provided
card
orcardNumber
Element for confirmation.billing_details recommended object
The billing_details associated with the card.
-with an existing payment method
Confirm a card payment with an existing payment method
Confirm with existing payment method
payske
.confirmCardPayment('{PAYMENT_INTENT_CLIENT_SECRET}', {
payment_method: '{PAYMENT_METHOD_ID}',
})
.then(function(result) {
// Handle result.error or result.paymentIntent
});
Confirm with existing payment method
const {paymentIntent, error} = await payske.confirmCardPayment(
'{PAYMENT_INTENT_CLIENT_SECRET}',
{
payment_method: '{PAYMENT_METHOD_ID}',
},
);
Use payske.confirmCardPayment
with an existing PaymentMethod
by passing its id
to payment_method
. The PaymentMethod
will be used to confirm the PaymentIntent
.
Data argument properties
payment_method required string
The
id
of an existing PaymentMethod.
-with an existing token
Confirm a card payment with an existing token
Confirm with existing token
payske
.confirmCardPayment('{PAYMENT_INTENT_CLIENT_SECRET}', {
payment_method: {
card: {
token: 'tok_visa',
},
},
})
.then(function(result) {
// Handle result.error or result.paymentIntent
});
Confirm with existing token
const {paymentIntent, error} = await payske.confirmCardSetup(
'{PAYMENT_INTENT_CLIENT_SECRET}',
{
payment_method: {
card: {
token: 'tok_visa',
},
},
},
);
For backwards compatibility, you can convert an existing Token
into a PaymentMethod
with payske.confirmCardPayment
by passing the Token
to payment_method[card][token]
. The newly created PaymentMethod
will be used to confirm the PaymentIntent
.
Data argument properties
payment_method required object
Pass an object to confirm using an existing token.
payment_method properties
card required object
An object of card data.
card properties
billing_details recommended object
The billing_details associated with the card.
-with an attached PaymentMethod
Confirm a card payment with an attached PaymentMethod
Confirm with an attached PaymentMethod
payske
.confirmCardPayment('{PAYMENT_INTENT_CLIENT_SECRET}')
.then(function(result) {
// Handle result.error or result.paymentIntent
});
Confirm with an attached PaymentMethod
const {paymentIntent, error} = await payske.confirmCardPayment(
'{PAYMENT_INTENT_CLIENT_SECRET}',
);
If you have already attached a PaymentMethod
to this PaymentIntent
, then you can confirm the PaymentIntent
using payske.confirmCardPayment
without passing in any additional data.
Retrieve a PaymentIntent
payske.retrievePaymentIntent(clientSecret)
Retrieve a PaymentIntent
payske
.retrievePaymentIntent('{PAYMENT_INTENT_CLIENT_SECRET}')
.then(function(result) {
// Handle result.error or result.paymentIntent
});
Retrieve a PaymentIntent
const {paymentIntent, error} = await payske.retrievePaymentIntent(
'{PAYMENT_INTENT_CLIENT_SECRET}',
);
// Handle error or paymentIntent
Retrieve a PaymentIntent using its client secret.
Method parameters
clientSecret required string
The client secret of the PaymentIntent to retrieve.
Returns
This method returns a Promise
which resolves with a result
object. This object has either:
result.paymentIntent
: a PaymentIntent was retrieved successfully.result.error
: an error. Refer to the API reference for all possible errors.
Was this section helpful?YesNo
Handle a card action
payske.handleCardAction(clientSecret)
Handle a card action
payske
.handleCardAction('{PAYMENT_INTENT_CLIENT_SECRET}')
.then(function(result) {
// Handle result.error or result.paymentIntent
});
Handle a card action
const {paymentIntent, error} = await payske.handleCardAction(
'{{PAYMENT_INTENT_CLIENT_SECRET}}',
);
// Handle the paymentIntent or error
Use payske.handleCardAction
in the Payment Intents API manual confirmation flow to handle a PaymentIntent with the requires_action
status. It will throw an error if the PaymentIntent
has a different status.
Method parameters
clientSecret required string
The client secret of the
PaymentIntent
to handle.
Returns
This method returns a Promise
which resolves with a result
object. This object has either:
result.paymentIntent
: a PaymentIntent with therequires_confirmation
status to confirm server-side.result.error
: an error. Refer to the API reference for all possible errors.
Note that payske.handleCardAction
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.
Additionally, payske.handleCardAction
may trigger a 3D Secure authentication challenge. The authentication challenge requires a context switch that can be hard to follow on a screen-reader. Ensure that your form is accessible by ensuring that success or error messages are clearly read out.
Was this section helpful?YesNo
APPENDIX
The CssFontSource object
Example CssFontSource object
{
cssSrc: 'https://fonts.googleapis.com/css?family=Open+Sans'
}
This object is used to pass custom fonts via a stylesheet URL when creating an Elements object.
Object Properties
cssSrc string
A relative or absolute URL pointing to a CSS file with @font-face definitions, for example:
https://fonts.googleapis.com/css?family=Open+Sans
Note that if you are using a content security policy (CSP), additional directives may be necessary.
Was this section helpful?YesNo
The CustomFontSource object
Example CustomFontSource object
{
family: 'Avenir',
src: 'url(https://my-domain.com/assets/avenir.woff)',
weight: '500',
}
This object is used to pass custom fonts when creating an Elements object.
Object Properties
family required string
The name to give the font.
src required string
A valid src value pointing to your custom font file. This is usually (though not always) a link to a file with a
.woff
,.otf
, or.svg
suffix.display string
A valid font-display value.
style string
One of
normal
,italic
,oblique
. Defaults tonormal
.unicodeRange string
A valid unicode-range value.
weight string
A valid font-weight. Note that this is a string, not a number.
Was this section helpful?YesNo
The PaymentItem object
Example PaymentItem object
{
amount: 2000,
label: 'A soft cotton shirt',
}
The PaymentItem
object is used to configure a PaymentRequest.
Object Properties
amount required number
The amount in the currency's subunit (e.g. cents, yen, etc.)
label required string
A name that the browser shows the customer in the payment interface.
pending boolean
If you might change this amount later (for example, after you have calcluated shipping costs), set this to
true
. Note that browsers treat this as a hint for how to display things, and not necessarily as something that will prevent submission.
Was this section helpful?YesNo
The PaymentResponse object
Example PaymentResponse object
{
source: {
id: "src_1FlM3yDbZnUGiCm0P8eqjAuI",
object: "source",
// ...
}
complete: function(status) {
// Call this when you have processed the source data provided
// by the API. Note that you must must call complete within 30
// seconds.
},
payerName: 'Jenny Rosen',
payerEmail: 'jenny@example.com',
walletName: 'browserCard',
shippingOption: {
id: 'basic',
label: 'Ground shipping',
detail: 'Ground shipping via UPS or FedEx',
amount: 995,
}
}
This object is returned as the payload of the PaymentRequest
object's token
, paymentmethod
, or source
event handlers.
Object Properties
token object
A Token object. Present if this was the result of a
token
event listener.paymentMethod object
A PaymentMethod object. Present if this was the result of a
paymentmethod
event listener.source object
A Source object. Present if this was the result of a
source
event listener.complete function
complete(status) => void
is a Payske.js provided function. Call this when you have processed the token data provided by the API. Note that you must must callcomplete
within 30 seconds.Accepts one of the following values:
allowed status values
'success' value
Report to the browser that the payment was successful, and that it can close any active payment interface.
'fail' value
Report to the browser that you were unable to process the customer‘s payment. Browsers may re-show the payment interface, or simply show a message and close.
'invalid_payer_name' value
Equivalent to
fail
, except that the browser can choose to show a more-specific error message.'invalid_payer_phone' value
Equivalent to
fail
, except that the browser can choose to show a more-specific error message.'invalid_payer_email' value
Equivalent to
fail
, except that the browser can choose to show a more-specific error message.'invalid_shipping_address' value
Equivalent to
fail
, except that the browser can choose to show a more-specific error message.
payerName string
The customer's name. Only present if it was explicitly asked for when creating the PaymentRequest object.
payerEmail string
The customer's email. Only present if it was explicitly asked for when creating the PaymentRequest object.
payerPhone string
The customer's phone. Only present if it was explicitly asked for when creating the PaymentRequest object.
shippingAddress ShippingAddress
The final ShippingAddress the customer selected.
Only present when
requestShipping
istrue
when creating the PaymentRequest object, and you've supplied at least oneShippingOption
.shippingOption ShippingOption
The final ShippingOption the customer selected.
Only present when
requestShipping
istrue
when creating the PaymentRequest object, and you've supplied at least oneShippingOption
.walletName string
The unique name of the wallet the customer chose to authorize payment. For example,
browserCard
.
Was this section helpful?YesNo
The ShippingOption object
Example ShippingOption object
{
id: 'basic',
label: 'Ground shipping',
detail: 'Ground shipping via UPS or FedEx',
amount: 995,
}
The ShippingOption
object describes a shipping method used with a PaymentRequest.
Object Properties
id string
A unique ID you create to keep track of this shipping option. You’ll be told the ID of the selected option on changes and on completion.
label string
A short label for this shipping option.
detail string
A longer description of this shipping option.
amount number
The amount to show for this shipping option. If the cost of this shipping option depends on the shipping address the customer enters, listen for the
shippingaddresschange
event.
Was this section helpful?YesNo
The ShippingAddress object
Example ShippingAddress object
{
recipient: 'Jenny Rosen',
addressLine: ['185 Berry St.'],
city: 'San Francisco',
region: 'CA',
postalCode: '94941',
country: 'US',
}
The ShippingAddress
object describes a shipping address collected with a PaymentRequest.
Object Properties
country string
Two-letter country code, capitalized. Valid two-letter country codes are specified by ISO3166 alpha-2.
addressLine array
An array of address line items. For example,
185 Berry St.
,Suite 500
,P.O. Box 12345
, etc.region string
The most coarse subdivision of a country. Depending on the country, this might correspond to a state, a province, an oblast, a prefecture, or something else along these lines.
city string
The name of a city, town, village, etc.
postalCode string
The postal code or ZIP code, also known as PIN code in India.
recipient string
The name of the recipient. This might be a person, a business name, or contain “care of” (c/o) instructions.
phone string
The phone number of the recipient. Note that this might be different from any phone number you collect with
requestPayerPhone
.sortingCode string
The sorting code as used in, for example, France. Not present on Apple platforms.
dependentLocality string
A logical subdivision of a city. Can be used for things like neighborhoods, boroughs, districts, or UK dependent localities. Not present on Apple platforms.
Was this section helpful?YesNo
The Style object
Creating a styled element
var element = elements.create('card', {
style: {
base: {
iconColor: '#c4f0ff',
color: '#fff',
fontWeight: '500',
fontFamily: 'Roboto, Open Sans, Segoe UI, sans-serif',
fontSize: '16px',
fontSmoothing: 'antialiased',
':-webkit-autofill': {
color: '#fce883',
},
'::placeholder': {
color: '#87BBFD',
},
},
invalid: {
iconColor: '#FFC7EE',
color: '#FFC7EE',
},
},
});
Creating a styled element
const element = elements.create('card', {
style: {
base: {
iconColor: '#c4f0ff',
color: '#fff',
fontWeight: '500',
fontFamily: 'Roboto, Open Sans, Segoe UI, sans-serif',
fontSize: '16px',
fontSmoothing: 'antialiased',
':-webkit-autofill': {
color: '#fce883',
},
'::placeholder': {
color: '#87BBFD',
},
},
invalid: {
iconColor: '#FFC7EE',
color: '#FFC7EE',
},
},
});
Elements are styled using a Style
object, which consists of CSS properties nested under objects for any of the following variants:
base
, base variant—all other variants inherit from these stylescomplete
, applied when the Element has valid inputempty
, applied when the Element has no customer inputinvalid
, applied when the Element has invalid input
The following pseudo-classes and pseudo-elements can also be styled using a nested object inside of a variant:
:hover
:focus
::placeholder
::selection
:-webkit-autofill
:disabled
, available for all Elements except thepaymentRequestButton
Element.::-ms-clear
, available for thecardNumber
,cardExpiry
, andcardCvc
Elements. Inside the::-ms-clear
selector, the display property can be customized.
The following CSS properties are supported:
Object Properties
backgroundColor string
The background-color CSS property.
This property works best with the
::selection
pseudo-class. In other cases, consider setting the background color on the Element's container instead.color string
The color CSS property.
fontFamily string
The font-family CSS property.
fontSize string
The font-size CSS property.
fontSmoothing string
The font-smoothing CSS property.
fontStyle string
The font-style CSS property.
fontVariant string
The font-variant CSS property.
fontWeight string
The font-weight CSS property.
iconColor string
A custom property, used to set the color of the icons that are rendered in an Element.
lineHeight string
The line-height CSS property.
To avoid cursors being rendered inconsistently across browsers, consider using a padding on the Element's container instead.
letterSpacing string
The letter-spacing CSS property.
textAlign string
The text-align CSS property.
Available for the
cardNumber
,cardExpiry
,cardCvc
andiban
Elements.padding string
The padding CSS property.
Available for the
idealBank
Element. Accepts integer length withpx
unit as values.textDecoration string
The text-decoration CSS property.
textShadow string
The text-shadow CSS property.
textTransform string
The text-transform CSS property.
Was this section helpful?YesNo
The UpdateDetails object
Example UpdateDetails object
{
status: 'success',
total: {
amount: 15000,
label: 'A soft cotton shirt',
},
}
This object is passed to the updateWith
callback on a PaymentRequest's shippingaddresschange
and shippingoptionchange
events.
Object Properties
status string
The browser uses this value to show an error message to the customer if they‘ve taken an action that invalidates the payment request. The value must be one of the following:
allowed values
'success' value
Let the customer proceed.
'fail' value
Prevent the customer from making the change they just made.
'invalid_shipping_address' value
Equivalent to
fail
, except we show a more specific error message. Can only be used in ashippingaddresschange
handler.
total PaymentItem
The new total amount, if applicable, as a PaymentItem object.
displayItems array
An array of PaymentItem objects. These PaymentItems are shown as line items in the browser‘s payment interface. Note that the sum of the line item amounts does not need to add up to the total amount above.
shippingOptions array
An array of ShippingOption objects. The first shipping option listed appears in the browser payment interface as the default option.
Was this section helpful?YesNo
Supported browsers
Payske.js strives to support all recent versions of major browsers. For the sake of security and providing the best experience to the majority of customers, we do not support browsers that are no longer receiving security updates and represent a small minority of traffic.
- We support the following evergreen browsers: Chrome, Chrome Mobile, Firefox, and Microsoft Edge.
- IE11 support will end on February 28, 2022.
- We support Safari on desktop and iOS (last 3 major versions).
- We support the latest major version of Android and iOS WebViews.
- We require TLS 1.2 to be supported by the browser.
- We respond to bug reports but do not proactively test other mobile browsers.
If you have an issue with Payske.js on a specific browser, please contact us so we can improve its support.
Payske.js to end support for Internet Explorer 11
Starting on February 28, 2022, Payske.js will no longer support IE11. On that date, we will no longer test Payske.js, Checkout, and Elements in IE11, and will start to ship changes that will break in that browser.
Additionally, any new Elements launched leading up to this date, such as the Payment Element, will not work in IE11.
Was this section helpful?YesNo
Supported locales
Create a Payske instance with a locale
var payske = Payske('pk_test_TYooMQauvdEDq54NiTphI7jx', {
locale: 'fr'
});
Create a Payske instance with a locale
const payske = Payske('pk_test_TYooMQauvdEDq54NiTphI7jx', {
locale: 'fr'
});
The following subset of IETF language tags can be used to configure localization in Payske.js.
Note that Checkout supports a slightly different set of locales than Payske.js. If you are using Checkout with payske.redirectToCheckout
, make sure to use a locale that Checkout supports.
Value | Locale | Elements | Checkout |
---|---|---|---|
auto |
Payske detects the locale of the browser | ✔ | ✔ |
ar |
Arabic | ✔ | |
bg |
Bulgarian (Bulgaria) | ✔ | ✔ |
cs |
Czech (Czech Republic) | ✔ | ✔ |
da |
Danish (Denmark) | ✔ | ✔ |
de |
German (Germany) | ✔ | ✔ |
el |
Greek (Greece) | ✔ | ✔ |
en |
English | ✔ | ✔ |
en-GB |
English (United Kingdom) | ✔ | ✔ |
es |
Spanish (Spain) | ✔ | ✔ |
es-419 |
Spanish (Latin America) | ✔ | ✔ |
et |
Estonian (Estonia) | ✔ | ✔ |
fi |
Finnish (Finland) | ✔ | ✔ |
fil |
Filipino (Philipines) | ✔ | ✔ |
fr |
French (France) | ✔ | ✔ |
fr-CA |
French (Canada) | ✔ | ✔ |
he |
Hebrew (Israel) | ✔ | |
hr |
Croatian (Croatia) | ✔ | ✔ |
hu |
Hungarian (Hungary) | ✔ | ✔ |
id |
Indonesian (Indonesia) | ✔ | ✔ |
it |
Italian (Italy) | ✔ | ✔ |
ja |
Japanese (Japan) | ✔ | ✔ |
ko |
Korean (Korea) | ✔ | ✔ |
lt |
Lithuanian (Lithuania) | ✔ | ✔ |
lv |
Latvian (Latvia) | ✔ | ✔ |
ms |
Malay (Malaysia) | ✔ | ✔ |
mt |
Maltese (Malta) | ✔ | ✔ |
nb |
Norwegian Bokmål | ✔ | ✔ |
nl |
Dutch (Netherlands) | ✔ | ✔ |
pl |
Polish (Poland) | ✔ | ✔ |
pt-BR |
Portuguese (Brazil) | ✔ | ✔ |
pt |
Portuguese (Brazil) | ✔ | ✔ |
ro |
Romanian (Romania) | ✔ | ✔ |
ru |
Russian (Russia) | ✔ | ✔ |
sk |
Slovak (Slovakia) | ✔ | ✔ |
sl |
Slovenian (Slovenia) | ✔ | ✔ |
sv |
Swedish (Sweden) | ✔ | ✔ |
th |
Thai (Thailand) | ✔ | ✔ |
tr |
Turkish (Turkey) | ✔ | ✔ |
vi |
Vietnamese (Vietnam) | ✔ | ✔ |
zh |
Chinese Simplified (China) | ✔ | ✔ |
zh-HK |
Chinese Traditional (Hong Kong) | ✔ | ✔ |
zh-TW |
Chinese Traditional (Taiwan) | ✔ | ✔ |
Was this section helpful?YesNo
Cookies
Payske uses cookies to ensure that the site works properly, detect and prevent fraud, and understand how people interact with Payske. There are some cookies that are essential for Payske to function properly. These Necessary Cookies provide secure access to the site and enable page navigation. Other categories of cookies include Advertising Cookies, Analytics Cookies, and Preference Cookies.
You can find more information in the Payske Cookies Policy, including how to opt-out or manage your cookie preferences.
Was this section helpful?YesNo
Viewport meta tag requirements
Example viewport meta tag
<meta name="viewport" content="width=device-width, initial-scale=1" />
In order to provide a great user experience for 3D Secure on all devices, you should set your page's viewport width
to device-width
with the the viewport meta tag.
There are several other viewport settings, and you can configure those based on your needs. Just make sure you include width=device-width
somewhere in your configuration.
Was this section helpful?YesNo