贝宝订单API模式

DomantasŠlaičiūnas

我正在使用PayPal结帐按钮和Paypal Orders API V2设置付款集成。付款即将到来,但现在我想在“订单”请求中包含商品,但得到:在此处输入图片说明

正如贝宝(PayPal)的文档所说,我必须将array (contains the item object) 链接 传递到订单API Purchase_unit对象链接到订单API物品对象但我仍然收到此错误。
这是我的要求:

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执行付款请求。

就像我说的那样,付款会抛出,但是当我尝试将商品添加到订单时,出现了此错误。

普雷斯顿PHX

您尚未发布详细说明问题的完整(其余)错误响应,因此我们可能看不到另一个问题,但缺少的一件事是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",
        },
      ],
    }
  ]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章