Create a payment method
How to create a payment method via API
To create a new payment method, send a
POST
request to the /api/payment_methods
endpoint, passing the resource arguments in the request body.POST https://yourdomain.commercelayer.io/api/payment_methods
Body Parameter | Type | Required |
---|---|---|
type | string | Required |
attributes.payment_source_type | string | Required |
attributes.currency_code | string | Required, unless inherited by market |
attributes.moto | boolean | Optional, default is 'false' |
attributes.require_capture | boolean | Optional, deafult is 'true' |
attributes.auto_capture | boolean | Optional, default is 'false' |
attributes.price_amount_cents | integer | Required |
attributes.auto_capture_max_amount_cents | integer | Optional |
attributes.reference | string | Optional |
attributes.reference_origin | string | Optional |
attributes.metadata | object | Optional |
relationships.market | object | Optional |
relationships.payment_gateway | object | Required |
Request
Response
The following request creates a new payment method:
curl -g -X POST \
'https://yourdomain.commercelayer.io/api/payment_methods' \
-H 'Accept: application/vnd.api+json' \
-H 'Authorization: Bearer your-access-token' \
-H 'Content-Type: application/vnd.api+json' \
-d '{
"data": {
"type": "payment_methods",
"attributes": {
"payment_source_type": "StripePayment",
"currency_code": "EUR",
"price_amount_cents": 0
},
"relationships": {
"payment_gateway": {
"data": {
"type": "payment_gateways",
"id": "ABCRtyUpBa"
}
}
}
}
}'
On success, the API responds with a
201 Created
status code, returning the created resource object:{
"data": {
"id": "xYZkjABcde",
"type": "payment_methods",
"links": {
"self": "https://yourdomain.commercelayer.io/api/payment_methods/xYZkjABcde"
},
"attributes": {
"payment_source_type": "StripePayment",
"name": "Stripe Payment",
"currency_code": "EUR",
"moto": false,
"require_capture": true,
"auto_capture": false,
"disabled_at": "2018-01-01T12:00:00.000Z",
"price_amount_cents": 0,
"price_amount_float": 0.0,
"formatted_price_amount": "€0,00",
"auto_capture_max_amount_cents": 0,
"auto_capture_max_amount_float": 0.0,
"formatted_auto_capture_max_amount": "€0,00",
"created_at": "2018-01-01T12:00:00.000Z",
"updated_at": "2018-01-01T12:00:00.000Z",
"reference": "ANY-EXTERNAL-REFEFERNCE",
"reference_origin": "ANY-EXTERNAL-REFEFERNCE-ORIGIN",
"metadata": {
"foo": "bar"
}
},
"relationships": {
"market": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/payment_methods/xYZkjABcde/relationships/market",
"related": "https://yourdomain.commercelayer.io/api/payment_methods/xYZkjABcde/market"
}
},
"payment_gateway": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/payment_methods/xYZkjABcde/relationships/payment_gateway",
"related": "https://yourdomain.commercelayer.io/api/payment_methods/xYZkjABcde/payment_gateway"
}
},
"attachments": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/payment_methods/xYZkjABcde/relationships/attachments",
"related": "https://yourdomain.commercelayer.io/api/payment_methods/xYZkjABcde/attachments"
}
},
"versions": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/payment_methods/xYZkjABcde/relationships/versions",
"related": "https://yourdomain.commercelayer.io/api/payment_methods/xYZkjABcde/versions"
}
}
},
"meta": {
"mode": "test"
}
}
}
Last modified 29d ago