Adding the payment source
How to add a Stripe payment source to an order
Problem
Solution
Adding a payment sourceExample
1. Get the payment source type
curl -g -X GET \
'http://yourdomain.commercelayer.io/api/orders/qaMAhZkZvd?include=payment_method' \
-H 'Authorization: Bearer your-access-token' \
-H 'Accept: application/vnd.api+json'{
"data": {
"id": "qaMAhZkZvd",
"type": "orders",
"links": {
"self": "https://yourdomain.commercelayer.io/api/orders/qaMAhZkZvd"
},
"attributes": {...},
"relationships": {
"market": {
"links": {...}
},
"customer": {
"links": {...}
},
"shipping_address": {
"links": {...}
},
"billing_address": {
"links": {...}
},
"available_payment_methods": {
"links": {...}
},
"payment_method": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/orders/qaMAhZkZvd/relationships/payment_method",
"related": "https://yourdomain.commercelayer.io/api/orders/qaMAhZkZvd/payment_method"
},
"data": {
"type": "payment_methods",
"id": "WmOodsVPmQ"
}
},
"payment_source": {
"links": {...}
},
"line_items": {
"links": {...}
},
"shipments": {
"links": {...}
}
},
"meta": {
"mode": "test"
}
},
"included": [
{
"id": "WmOodsVPmQ",
"type": "payment_methods",
"links": {...},
"attributes": {
"payment_source_type": "stripe_payments",
"name": "Stripe Payment",
"disabled_at": null,
"price_amount_cents": 0,
"price_amount_float": 0.0,
"formatted_price_amount": "€0,00",
"created_at": "2018-01-01T12:00:00.000Z",
"updated_at": "2018-01-01T12:00:00.000Z",
"reference": "",
"reference_origin": "",
"metadata": {}
},
"relationships": {
"market": {
"links": {...}
},
"payment_gateway": {
"links": {...}
}
},
"meta": {
"mode": "test"
}
}
]
}2. Create the payment source and associate it with the order
curl -g -X POST \
'http://yourdomain.commercelayer.io/api/stripe_payments' \
-H 'Accept: application/vnd.api+json' \
-H 'Authorization: Bearer your-access-token' \
-H 'Content-Type: application/vnd.api+json' \
-d '{
"data": {
"type": "stripe_payments",
"attributes": {},
"relationships": {
"order": {
"data": {
"type": "orders",
"id": "qaMAhZkZvd"
}
}
}
}
}'Additional notes
Client secret generation
Asynchronous authorization
Authorization check on order placement
Payment source nullification
More to read
Placing the orderLast updated