PayPal 订单 API 架构
Posted
技术标签:
【中文标题】PayPal 订单 API 架构【英文标题】:PayPal Orders API schema 【发布时间】:2021-02-04 06:14:57 【问题描述】:我正在设置与 PayPal Checkout Buttons 和 Paypal Orders API V2 的付款集成。付款将被抛出,但现在我想在我的订单请求中包含项目,但我得到:
正如 PayPal 文档所说,我必须通过 array (contains the item object)
Link to Orders API purchase_unit object Link to Orders API item object。但我仍然收到此错误。
这是我的要求:
public function createOrder($value, $order, $products, $currency = 'EUR')
return $this->makeRequest(
'POST',
'/v2/checkout/orders',
[],
[
'intent' => 'CAPTURE',
'payer' => [
'name' => [
'given_name' => $order->billing_firstname,
'surname' => $order->billing_lastname
],
'email_address' => $order->email_address,
'address' => [
'address_line_1' => $order->billing_street_address,
'admin_area_2' => $order->billing_city,
'postal_code' => $order->billing_postcode,
'country_code' => $order->billing_country_code
],
],
'purchase_units' => [
0 => [
'amount' => [
'currency_code' => $currency,
'value' => $value,
],
'description' => 'Order: ' . $order->order_serial_number,
'items' => [
0 => [
'name' => 'Item1',
'unit_amount' => 100,
'quantity' => 1
],
],
],
],
'application_context' => [
'brand_name' => config('app.name'),
'shipping_preference' => 'NO_SHIPPING',
'user_action' => 'PAY_NOW',
'return_url' => route('approval.paypal', $order->id_order),
'cancel_url' => route('payment.cancelled', $order->id_order),
]
],
[],
$isJsonRequest = true
);
我正在使用:Laravel 和 Guzzle/HTTP 来执行支付请求。
正如我所说,付款会出错,但是当我尝试将商品添加到订单时,我收到了这个错误。
【问题讨论】:
【参考方案1】:您尚未发布详细说明问题的完整(其余)错误响应,因此可能存在我们看不到的另一个问题,但缺少的一件事是 amount.breakdown.item_total
小计,当传递带有数量的items
数组:https://developer.paypal.com/docs/api/orders/v2/#definition-amount_breakdown
API 的 JSON 格式的简单示例,可以适应 php 数组语法:
// based on example array from https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/
"purchase_units": [
"amount":
"value": "17.49",
"currency_code": "USD",
"breakdown":
"item_total":
"currency_code": "USD",
"value": "17.49"
,
,
"items": [
"unit_amount":
"currency_code": "USD",
"value": "17.49"
,
"quantity": "1",
"name": "item 1",
,
],
]
【讨论】:
以上是关于PayPal 订单 API 架构的主要内容,如果未能解决你的问题,请参考以下文章