Shift4.js is a browser-side JavaScript library that can be used to securely collect sensitive payment information (like credit card numbers).
This documentation describes every object and method made available by the library.
Shift4.js should be included on every page of your site where payment information will be collected.
It should never be bundled or hosted on your website, but should always be
loaded directly from https://js.dev.shift4.com
.
<script type="text/javascript" src="https://js.dev.shift4.com/shift4.js"></script>
To get started with Shift4.js
, first, call the Shift4()
method to create and configure a Shift4 object.
Create a new Shift4 object and configure it.
EXAMPLE
var shift4 = Shift4("pu_test_WVMFC9GFuvm54b0uorifKkCh");
Shift4 object is the main entry point to all
Shift4.js
functionalities.
Create a new component of the specified type.
EXAMPLE
var card = shift4.createComponent("card");
Create a new grouping object that will be used to create multiple related components, such as
number
, expiry
and cvc
components that will be used together to collect details for a single card.
EXAMPLE
var components = shift4.createComponentGroup();
Tokenize card data from a given component or component group by sending it to the "create token" API method.
number
, expMonth
, expYear
and
cvc
. Values of these fields must be collected using components.
Promise object
EXAMPLE
var card = shift4.createComponent("card");
function onFormSubmit() {
shift4.createToken(card)
.then(tokenCreatedCallback)
.catch(errorCallback);
}
Starts a 3D Secure process.
Depending on the card and the card's issuer, this may result in the 3D Secure challenge being displayed in an
iframe
or popup window.
Promise object
EXAMPLE
function tokenCreatedCallback(token) {
var request = {
card: token.id,
amount: 2499,
currency: 'USD',
};
shift4.verifyThreeDSecure(request)
.then(threeDSecureCompletedCallback)
.catch(errorCallback);
}
Component object is used to securely collect sensitive information (like card number or cvc).
Mounts component to placeholder tag located by given selector
.
Component object on which this method was called
EXAMPLE
var components = shift4.createComponentGroup();
var number = components.createComponent("number").mount("#number");
Removes any current value from a component.
Component object on which this method was called.
EXAMPLE
var card = shift4.createComponent("card");
card.clear();
When multiple components are required to collect card details for a single card, the ComponentGroup object is used to group them.
Automatically search all tags nested under the tag located by the given selector
and create
components on all tags with the data-shift4
attribute. The value of that attribute
is used to determine the type
of the component.
data-shift4
attribute.
ComponentGroup object on which this method was called.
EXAMPLE
var components = shift4.createComponentGroup().automount("#payment-form");
Create a new component of a given type and assigns it to this component group.
EXAMPLE
var components = shift4.createComponentGroup();
var number = components.createComponent("number");