Follow this guide to use the Vault SDK if you are not using our Checkout SDK.
FYI, our Checkout SDK uses our Vault directly. Only use our Vault SDK if you are using Vault standalone or if you are building a custom checkout experience.
The WhenThen Vault SDK is available on npm. See @whenthen/sdk-vault
for an API reference.
npm install --save @whenthen/sdk-vault
# or
yarn add @whenthen/sdk-vault
import { WhenThenVault } from '@whenthen/sdk-vault';
const options = {
apiKey: 'CLIENT_TOKEN_XXX',
};
window.addEventListener('load', async () => {
const vault = WhenThenVault(options);
});
apiKey
String ﹡ Initialise WhenThen Vault SDK with a Client Token.
The Vault API provides you with three methods: createCustomer( )
,tokenisePaymentMethod( )
, and getPaymentMethods( )
.
Creates a customer. If payment method data is provided, it also creates a payment method and assigns it to the new customer. The payment method is tokenised and stored in our secure vault.
The createCustomer( )
API enables you to create and manage customers. To setup a card for future payments, you must attach it to a Customer. You can also use the Customer to build card on file solutions.
const { data, errors } = await vault.createCustomer({
data: {
customer: {
billingAddress: {
line1: 'Bartlett Avenue',
line2: 'no. 4',
city: 'Southfield',
postalCode: '48076',
state: 'Michigan',
country: 'USA',
},
description: 'description',
email: 'john@test.com',
name: 'John Smith',
phone: '406-694-3629',
shippingAddress: {
address: {
line1: 'Gruenauer Strasse 55',
city: 'Buchhorst',
postalCode: '16567',
state: 'Brandenburg',
country: 'DEU',
},
name: 'John Smith',
phone: '04153 79 44141',
},
},
},
});
data.customer
Object ﹡ customer.billingAddress
Object customer.description
string customer.email
string customer.name
string ﹡ customer.phone
string customer.shippingAddress
Object customer.company
CompanyInput Promise<{
data: CreateCustomerOutput;
errors: Array<{ message: string; type: string; }>;
}>;
CreateCustomerOutput
id
String You can securely store a payment method in our vault. You should use our recommended payments integrations to perform this process client-side. This ensures that no sensitive card data touches your server, and allows your integration to operate in a PCI-compliant way. The payment method is tokenised and we return you a token for future use.
If customer id is provided, it assigns the payment method to that customer. If customer data is provided, it creates a new customer and assigns the payment method to that customer.
const idempotencyKey = '90e14226-d9f7-431d-a1df-831a7b2a0c9b';
const { data, errors } = vault.tokenisePaymentMethod(
{
data: {
paymentMethod: {
card: {
number: '4000056655665556',
expMonth: 8,
expYear: 2026,
cvc: '342',
name: 'John Smith',
billingAddress: {
line1: 'Bartlett Avenue',
line2: 'no. 4',
city: 'Southfield',
postalCode: '48076',
state: 'Michigan',
country: 'USA',
},
isDefault: true,
},
bankAccount: {
number: '123456',
accountHolderName: 'John Smith',
bankName: 'Golden Horizon',
},
},
customer: {
id: '421dd9b0-0af6-41ee-9fc5-48f42d5ad640',
},
},
},
idempotencyKey
);
paymentMethod
Object ﹡ paymentMethod.card
Object ﹡ customer
Object customer.id
string customer.billingAddress
Object customer.description
string customer.email
string customer.name
string customer.phone
string customer.shippingAddress
Object customer.company
CompanyInput idempotencyKey
string Promise<{
data: TokenisePaymentMethodDataOutput;
errors: Array<{ message: string; type: string; }>;
}>;
TokenisePaymentMethodDataOutput
id
String token
String customer
Object customer.id
String You can list customer payment methods.
const { data, errors } = await vault.getPaymentMethods({
customerId: '421dd9b0-0af6-41ee-9fc5-48f42d5ad640',
});
customerId
String Promise<{
data: Array<PaymentMethod>;
errors: Array<{ message: string; type: string; }>;
}>;
PaymentMethod
token
String number
String expMonth
Number expYear
Number name
String isDefault
Booleam brand
String