Skip to content

Payments testing

Last updated: April 29, 2022

Create a token that represents a card's details that you can later use to request a test payment, without you having to process or store any sensitive information.


Step 1: Request a token

Exchange card details for a reference token that can be used later to request a card payment. Tokens are single use and expire after 15 minutes. To create a token, you'll need to authenticate using your public API key.

The request

Endpoint

post

https://api.sandbox.checkout.com/tokens

Header parameters

HeaderValue

Authorization

required

Public API key

This will be prefixed by pktest.

Content-Type

required

application/json

Body parameters

Tip

You can use any of our test cards' details in the body of your request.

Field nameDescription

type

required

string

Set this to card.

number

required

string

The card number.

expiry_month

required

integer

The expiry month of the card.

expiry_year

required

integer

The expiry year of the card.

name

optional

string

The cardholder's name.

cvv

optional

string

The card verification value/code. 3 digits, except for American Express (4 digits).

billing.address

optional

object

The payment source owner's billing address.

phone

optional

object

The payment source owner's phone number.

Request example

1
{
2
"type": "card",
3
"number": "4543474002249996",
4
"expiry_month": 6,
5
"expiry_year": 2025,
6
"name": "John Smith",
7
"cvv": "956",
8
"billing_address": {
9
"address_line1": "123 High St.",
10
"address_line2": "Flat 456",
11
"city": "London",
12
"zip": "SW1A 1AA",
13
"country": "GB"
14
},
15
"phone": {
16
"country_code": "+44",
17
"number": "1234 567890"
18
}
19
}

The response

If your request was successful, you'll receive a 201 response containing a card token prefixed by tok_. You then have 15 minutes to request a payment using this token.

Response example

1
{
2
"type": "card",
3
"token": "tok_ubfj2q76miwundwlk72vxt2i7q",
4
"expires_on": "2020-08-27T11:37:30Z",
5
"expiry_month": 6,
6
"expiry_year": 2025,
7
"scheme": "VISA",
8
"last4": "9996",
9
"bin": "454347",
10
"card_type": "Credit",
11
"card_category": "Consumer",
12
"issuer": "Test Bank",
13
"issuer_country": "US",
14
"product_id": "F",
15
"product_type": "CLASSIC",
16
"billing_address": {
17
"address_line1": "123 High St.",
18
"address_line2": "Flat 456",
19
"city": "London",
20
"zip": "SW1A 1AA",
21
"country": "GB"
22
},
23
"phone": {
24
"country_code": "+44",
25
"number": "1234 567890"
26
},
27
"name": "John Smith"
28
}

Step 2: Request a payment using the token

Create a payment request using the token you just received.