I try to migrate our old express checkout process based on PayPal classic API to new RestAPI , but a question has arisen during the new process:
How can I change shipping amount after create a payment and just before execute payment using PayPal restAPI?
Request after create payment:
{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"transactions": [
{
"amount": {
"currency": "AUD",
"total": "100",
"details": {
"shipping": "10",
"subtotal": "75",
"tax": "15"
}
},
"description": "Transaction description.",
"item_list": {
"items": [
{
"quantity": "5",
"name": "Item Name",
"price": "15",
"currency": "AUD",
"sku": "sku"
}
]
}
}
],
"redirect_urls": {
"return_url": "http://localhost:56508/PaymentWithPayPal.aspx?guid=77096",
"cancel_url": "http://localhost:56508/PaymentWithPayPal.aspx?guid=77096"
}
}
request before execute payment:
{
"id": "PAY-12X5617352981972MKQ64KKA",
"transactions": [
{
"amount": {
"currency": "AUD",
"total": "101",
"details": {
"shipping": "11",
"subtotal": "75",
"tax": "15"
}
}
}
]
}
PayPal response back after execute payment:
{
"id": "PAY-12X5617352981972MKQ64KKA",
"create_time": "2014-10-15T00:51:52Z",
"update_time": "2014-10-15T00:52:43Z",
"intent": "sale",
"payer": {
"payment_method": "paypal",
"payer_info": {
--------------------
-----------------------------
----------------------
}
}
},
"transactions": [
{
"amount": {
"currency": "AUD",
"total": "100.00",
"details": {
"shipping": "10.00",
"subtotal": "75.00",
"tax": "15.00"
}
},
"description": "Transaction description.",
"item_list": {
"items": [
{
"quantity": "5",
"name": "Item Name",
"price": "15.00",
"currency": "AUD",
"sku": "sku"
}
],
"shipping_address": {
------------------------------
}
},
"related_resources": [
{
"sale": {
"id": "5KX17441UU9021742",
"create_time": "2014-10-15T00:51:52Z",
"update_time": "2014-10-15T00:52:43Z",
"amount": {
"currency": "AUD",
"total": "100.00"
},
"state": "completed",
"parent_payment": "PAY-12X5617352981972MKQ64KKA",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/5KX17441UU9021742",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/5KX17441UU9021742/refund",
"rel": "refund",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-12X5617352981972MKQ64KKA",
"rel": "parent_payment",
"method": "GET"
}
]
}
}
]
}
],
"state": "approved",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-12X5617352981972MKQ64KKA",
"rel": "self",
"method": "GET"
}
]
}
You can change the shipping amount after creating a payment . You need to pass shipping amount in the execute payment call and it will override the shipping that you set while creating the payment .
Request passed in while creating the payment :
While executing the payment :
https://api.sandbox.paypal.com/v1/payments/payment/PAY-2NX408505D489885FKQ6M7NA/execute/
Response :
As you can see , I have passed the new shipping amount while executing the payment and it will be final one .
It doesn't look like REST supports the Express Checkout Callback API, which is used to update shipping and tax totals within Express Checkout. It's not surprising since REST is aimed at mobile developers and they wouldn't necessarily want the extra bandwidth spent.