贝宝订单 API 架构
PayPal Orders API schema
我正在设置与 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 来执行付款请求。
正如我所说,付款将被抛出,但是当我尝试将项目添加到订单时,出现此错误。
您尚未发布详细说明问题的完整(其余)错误响应,因此可能还有另一个我们看不到的问题,但缺少的一件事是 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 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 来执行付款请求。
正如我所说,付款将被抛出,但是当我尝试将项目添加到订单时,出现此错误。
您尚未发布详细说明问题的完整(其余)错误响应,因此可能还有另一个我们看不到的问题,但缺少的一件事是 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",
},
],
}
]