我正在使用PayPal结帐按钮和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执行付款请求。
正如我所说,付款会抛出,但是当我尝试将商品添加到订单时,出现此错误。
答案 0 :(得分: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",
},
],
}
]