How can I change shipping amount before execute payment using PayPal restAPI

后端 未结 2 611
臣服心动
臣服心动 2021-01-24 02:23

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 shippin

相关标签:
2条回答
  • 2021-01-24 02:26

    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.

    0 讨论(0)
  • 2021-01-24 02:42

    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 :

    {
      "intent": "sale",
      "payer": {
        "payment_method": "paypal"
      },
      "redirect_urls": {
        "return_url": "http://www.fff.com",
        "cancel_url": "http://www.fff.com"
      },
      "transactions": [
        {
          "amount": {
            "total": "20.00",
            "currency": "USD",
            "details": {
              "subtotal": "18.00",
              "tax": "1.00",
              "shipping": "1.00"
            }
          },
          "description": "This is payment description.",
          "item_list": {
            "items": [
              {
                "quantity": "3",
                "name": "Hat",
                "price": "2.00",
                "sku": "product12345",
                "description": "This is desc",
                "currency": "USD"
              },
              {
                "quantity": "3",
                "name": "Hat",
                "price": "2.00",
                "sku": "product12345",
                "description": "This is desc",
                "currency": "USD"
              },
              {
                "quantity": "3",
                "name": "Hat",
                "price": "2.00",
                "sku": "product12345",
                "description": "This is desc",
                "currency": "USD"
              }
            ]
          }
        }
      ]
    }
    

    While executing the payment :

    https://api.sandbox.paypal.com/v1/payments/payment/PAY-2NX408505D489885FKQ6M7NA/execute/

    {
      "payer_id": "KQMQZ9Y7XZYBA",
      "transactions": [
        {
          "amount": {
            "total": "28.00",
            "currency": "USD",
            "details": {
              "subtotal": "18.00",
              "tax": "5.00",
              "shipping": "5.00"
            }
          },
          "description": "This is payment description.",
          "item_list": {
            "items": [
              {
                "quantity": "3",
                "name": "Hat",
                "price": "2.00",
                "sku": "product12345",
                "description": "This is desc",
                "currency": "USD"
              },
              {
                "quantity": "3",
                "name": "Hat",
                "price": "2.00",
                "sku": "product12345",
                "description": "This is desc",
                "currency": "USD"
              },
              {
                "quantity": "3",
                "name": "Hat",
                "price": "2.00",
                "sku": "product12345",
                "description": "This is desc",
                "currency": "USD"
              }
            ]
          }
        }
      ]
    }
    

    Response :

    {
      "id": "PAY-2NX408505DYT5005FKQ6M7NA",
      "create_time": "2014-10-14T07:24:36Z",
      "update_time": "2014-10-14T07:29:09Z",
      "state": "approved",
      "intent": "sale",
      "payer": {
        "payment_method": "paypal",
        "payer_info": {
          "email": "XXXXXXXXXXX",
          "first_name": "Eshan Personal Test",
          "last_name": "Account",
          "payer_id": "XXXXXXXXXXXX",
          "shipping_address": {
            "line1": "cxas",
            "line2": "asa",
            "city": "FL",
            "state": "FL",
            "postal_code": "95616",
            "country_code": "US",
            "recipient_name": "Eshan Personal Test Account"
          }
        }
      },
      "transactions": [
        {
          "amount": {
            "total": "28.00",
            "currency": "USD",
            "details": {
              "subtotal": "18.00",
              "tax": "5.00",
              "shipping": "5.00"
            }
          },
          "description": "This is payment description.",
          "item_list": {
            "items": [
              {
                "name": "Hat",
                "sku": "product12345",
                "price": "2.00",
                "currency": "USD",
                "quantity": "3",
                "description": "This is desc"
              },
              {
                "name": "Hat",
                "sku": "product12345",
                "price": "2.00",
                "currency": "USD",
                "quantity": "3",
                "description": "This is desc"
              },
              {
                "name": "Hat",
                "sku": "product12345",
                "price": "2.00",
                "currency": "USD",
                "quantity": "3",
                "description": "This is desc"
              }
            ],
            "shipping_address": {
              "recipient_name": "Eshan Personal Test Account",
              "line1": "cxas",
              "line2": "asa",
              "city": "FL",
              "state": "FL",
              "postal_code": "95616",
              "country_code": "US"
            }
          },
          "related_resources": [
            {
              "sale": {
                "id": "04B04851PF2563348",
                "create_time": "2014-10-14T07:24:36Z",
                "update_time": "2014-10-14T07:29:09Z",
                "amount": {
                  "total": "28.00",
                  "currency": "USD"
                },
                "payment_mode": "INSTANT_TRANSFER",
                "state": "completed",
                "protection_eligibility": "ELIGIBLE",
                "protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
                "parent_payment": "PAY-2NX408505D485005FKQ6M7NA",
                "links": [
                  {
                    "href": "https://api.sandbox.paypal.com/v1/payments/sale/04B04851PF2563348",
                    "rel": "self",
                    "method": "GET"
                  },
                  {
                    "href": "https://api.sandbox.paypal.com/v1/payments/sale/04B04851PF2563348/refund",
                    "rel": "refund",
                    "method": "POST"
                  },
                  {
                    "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-2NX408505D485005FKQ6M7NA",
                    "rel": "parent_payment",
                    "method": "GET"
                  }
                ]
              }
            }
          ]
        }
      ],
      "links": [
        {
          "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-2NX408505D485005FKQ6M7NA",
          "rel": "self",
          "method": "GET"
        }
      ]
    }
    

    As you can see , I have passed the new shipping amount while executing the payment and it will be final one .

    0 讨论(0)
提交回复
热议问题