API reference
Create a customer payment source
How to create a customer payment source via API
To create a new customer payment source, send a POST request to the /api/customer_payment_sources endpoint, passing the resource arguments in the request body.

Request

POST https://yourdomain.commercelayer.io/api/customer_payment_sources

Arguments

Body Parameter
Type
Required
type
string
Required
attributes.reference
string
Optional
attributes.reference_origin
string
Optional
attributes.metadata
object
Optional
relationships.customer
object
Required
relationships.payment_source
object
Required

Example

Request
Response
The following request creates a new customer payment source:
1
curl -g -X POST \
2
'https://yourdomain.commercelayer.io/api/customer_payment_sources' \
3
-H 'Accept: application/vnd.api+json' \
4
-H 'Authorization: Bearer your-access-token' \
5
-H 'Content-Type: application/vnd.api+json' \
6
-d '{
7
"data": {
8
"type": "customer_payment_sources",
9
"relationships": {
10
"customer": {
11
"data": {
12
"type": "customers",
13
"id": "QWERtyUpBa"
14
}
15
},
16
"payment_source": {
17
"data": {
18
"type": "payment_sources",
19
"id": "QWERtyUpBa"
20
}
21
}
22
}
23
}
24
}'
Copied!
On success, the API responds with a 201 Created status code, returning the created resource object:
1
{
2
"data": {
3
"id": "xYZkjABcde",
4
"type": "customer_payment_sources",
5
"links": {
6
"self": "https://yourdomain.commercelayer.io/api/customer_payment_sources/xYZkjABcde"
7
},
8
"attributes": {
9
"name": "XXXX-XXXX-XXXX-1111",
10
"customer_token": "cus_xxxyyyzzz",
11
"payment_source_token": "pm_xxxyyyzzz",
12
"created_at": "2018-01-01T12:00:00.000Z",
13
"updated_at": "2018-01-01T12:00:00.000Z",
14
"reference": "ANY-EXTERNAL-REFEFERNCE",
15
"reference_origin": "ANY-EXTERNAL-REFEFERNCE-ORIGIN",
16
"metadata": {
17
"foo": "bar"
18
}
19
},
20
"relationships": {
21
"customer": {
22
"links": {
23
"self": "https://yourdomain.commercelayer.io/api/customer_payment_sources/xYZkjABcde/relationships/customer",
24
"related": "https://yourdomain.commercelayer.io/api/customer_payment_sources/xYZkjABcde/customer"
25
}
26
},
27
"payment_source": {
28
"links": {
29
"self": "https://yourdomain.commercelayer.io/api/customer_payment_sources/xYZkjABcde/relationships/payment_source",
30
"related": "https://yourdomain.commercelayer.io/api/customer_payment_sources/xYZkjABcde/payment_source"
31
}
32
}
33
},
34
"meta": {
35
"mode": "test"
36
}
37
}
38
}
Copied!
Copy link