当前位置: 首页 > 知识库问答 >
问题:

如何在使用PayPal restAPI执行付款之前更改发货金额

乜安志
2023-03-14

我尝试将基于PayPal classic API的旧快速结账流程迁移到新的RestAPI,但在新流程中出现了一个问题:

如何在创建付款后和使用PayPal restAPI执行付款前更改发货金额?

创建付款后的请求:

{
  "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"
  }
}
    

执行付款前的请求:

{
  "id": "PAY-12X5617352981972MKQ64KKA",
  "transactions": [
    {
      "amount": {
        "currency": "AUD",
        "total": "101",
        "details": {
          "shipping": "11",
          "subtotal": "75",
          "tax": "15"
        }
      }
    }
  ]
}

PayPal在执行付款后回复:

{
  "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"
    }
  ]
}

共有2个答案

长孙文栋
2023-03-14

看起来REST不支持快速结账回调应用编程接口,该应用编程接口用于更新快速结账中的运输和税收总额。这并不奇怪,因为REST是针对移动开发者的,他们不一定想要额外的带宽。

东方旭东
2023-03-14

您可以在创建付款后更改发货金额。您需要在执行付款呼叫中传递发货金额,它将覆盖您在创建付款时设置的发货。

创建付款时传入的请求:

{
  "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"
          }
        ]
      }
    }
  ]
}

在执行付款时:

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"
          }
        ]
      }
    }
  ]
}

答复:

{
  "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"
    }
  ]
}

如你所见,我在执行付款时已经通过了新的运费,这将是最终的运费。

 类似资料:
  • 我正在使用贝宝/签出-php-sdk,但我不知道创建订单后该做什么。 我可以成功创建订单: 正如你看到的,我把return_url到“/执行命令”, 因此,PayPal在验证后将我重定向到此url: 但我不知道下一步该怎么办。我必须执行付款,但在包的示例中,我只找到createOrder和captureOrder,但没有executeOrder

  • 给定一美元金额,将其转换为欧元硬币和纸币。你得到了美元金额作为论据,并说美元对欧元的汇率是1.30。你可以看到欧元的名称是500美元,200美元,100美元,50美元,20美元,10美元,5美元,2美元,1美元,50美分,25美分,10美分,5美分,2美分,1美分。将该美元金额转换为最小金额的纸币和硬币。(将数字美元金额(如10.00美元)转换为等值的欧元纸币和硬币。) 免责声明:这是我收到的家庭

  • 我的paypal按钮有一个小问题默认情况下,我会尝试隐藏它以显示我自己的按钮:/ 这是我的密码。js }); 问题是,我总是有黄色的贝宝按钮,出现在我的按钮底部,我不能得到面具。

  • 我正在为一个在线购物网站实施stripe,该网站在“余额”系统上运行,用户在该系统中输入他们想在交易余额中存入的金额,并提交信用卡信息进行存款。 我不知道如何避免在付款确认时进行两次连续的api调用stripe:一次使用html表单中的存款当前值更新付款金额,一次确认付款意图。 以下是我理解的限制条件: Stripe需要创建一个支付意图,以便用他们的信用卡表单填充iframe 为了简化存款体验,我

  • 我WooCommerce,我正在使用“更改管理付款状态返回到WoocommercePending order status unpayed for WoocommercePending”答案代码,当订单状态在后端手动更改为pending时,重置订单的已付款状态。 例如,如果订单状态从“完成”更改为“挂起”,则删除以下内容:“支付日期为4月2日,2019年@5:29 PM” 现在我这里的问题是在订单

  • 使用 Stripe 订阅 API,将发出,但它不包含对用于该付款的卡/源的引用。我知道附加到客户的默认源用于订阅发票上的付款,但如果默认源在发票支付和通过 webhook 接收事件之间的时间发生变化,则在我通过 webhook 接收事件时查找默认源将不是确定使用哪个付款源支付该发票的可靠方法。如何获取用于支付发票的来源?如果很重要,这是必要的,以便对成功付款进行与税收相关的操作,因此了解使用了哪张