Search…
API Reference
Resources
Create an external payment
How to create an external payment via API
To create a new external payment, send a POST request to the /api/external_payments endpoint, passing the resource arguments in the request body.

Request

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

Arguments

Body Parameter
Type
Required
type
string
Required
attributes.payment_source_token
string
Required
attributes.options
object
Optional
attributes.reference
string
Optional
attributes.reference_origin
string
Optional
attributes.metadata
object
Optional
relationships.order
object
Required

Example

Request
Response
The following request creates a new external payment:
1
curl -g -X POST \
2
'https://yourdomain.commercelayer.io/api/external_payments' \
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": "external_payments",
9
"attributes": {
10
"payment_source_token": "xxxx.yyyy.zzzz"
11
},
12
"relationships": {
13
"order": {
14
"data": {
15
"type": "orders",
16
"id": "QWERtyUpBa"
17
}
18
}
19
}
20
}
21
}'
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": "external_payments",
5
"links": {
6
"self": "https://yourdomain.commercelayer.io/api/external_payments/xYZkjABcde"
7
},
8
"attributes": {
9
"payment_source_token": "xxxx.yyyy.zzzz",
10
"options": {
11
"foo": "bar"
12
},
13
"created_at": "2018-01-01T12:00:00.000Z",
14
"updated_at": "2018-01-01T12:00:00.000Z",
15
"reference": "ANY-EXTERNAL-REFEFERNCE",
16
"reference_origin": "ANY-EXTERNAL-REFEFERNCE-ORIGIN",
17
"metadata": {
18
"foo": "bar"
19
}
20
},
21
"relationships": {
22
"order": {
23
"links": {
24
"self": "https://yourdomain.commercelayer.io/api/external_payments/xYZkjABcde/relationships/order",
25
"related": "https://yourdomain.commercelayer.io/api/external_payments/xYZkjABcde/order"
26
}
27
},
28
"payment_gateway": {
29
"links": {
30
"self": "https://yourdomain.commercelayer.io/api/external_payments/xYZkjABcde/relationships/payment_gateway",
31
"related": "https://yourdomain.commercelayer.io/api/external_payments/xYZkjABcde/payment_gateway"
32
}
33
}
34
},
35
"meta": {
36
"mode": "test"
37
}
38
}
39
}
Copied!
Last modified 2mo ago
Copy link