Adding the payment source
How to add a PayPal 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/jNbQLhMeqo?include=payment_method' \
-H 'Authorization: Bearer your-access-token' \
-H 'Accept: application/vnd.api+json'{
"data": {
"id": "jNbQLhMeqo",
"type": "orders",
"links": {
"self": "https://yourdomain.commercelayer.io/api/orders/jNbQLhMeqo"
},
"attributes": {...},
"relationships": {
"market": {
"links": {...
}
},
"customer": {
"links": {...
}
},
"shipping_address": {
"links": {...
}
},
"billing_address": {
"links": {...
}
},
"payment_method": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/orders/jNbQLhMeqo/relationships/payment_method",
"related": "https://yourdomain.commercelayer.io/api/orders/jNbQLhMeqo/payment_method"
},
"data": {
"type": "payment_methods",
"id": "PNMGGzsQMd"
}
},
"payment_source": {
"links": {...
}
},
"line_items": {
"links": {...
}
},
"shipments": {
"links": {...
}
},
},
"meta": {
"mode": "test"
}
},
"included": [
{
"id": "PNMGGzsQMd",
"type": "payment_methods",
"links": {
"self": "https://yourdomain.commercelayer.io/api/payment_methods/PNMGGzsQMd"
},
"attributes": {
"payment_source_type": "paypal_payments",
"name": "Paypal 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": null,
"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/paypal_payments' \
-H 'Accept: application/vnd.api+json' \
-H 'Authorization: Bearer your-access-token' \
-H 'Content-Type: application/vnd.api+json' \
-d '{
"data": {
"type": "paypal_payments",
"attributes": {
"return_url": "https://checkout.yourdomain.com/jNbQLhMeqo/paypal",
"cancel_url": "https://checkout.yourdomain.com/jNbQLhMeqo"
},
"relationships": {
"order": {
"data": {
"type": "orders",
"id": "jNbQLhMeqo"
}
}
}
}
}'Additional notes
Client-side payment approval
Payment source nullification
More to read
Last updated