PayPal结账中的特定行项目

11

我想在我的网站上设置PayPal来接受付款,并且我希望能够为付款指定条目(使用新的SDK,而不是JavaScript版本)。

我尝试查看此处列出的API文档: https://developer.paypal.com/docs/api/orders/v2/。然而,它显示我有无效的语法或者我缺少一个字段。

<head>
<script>
paypal.Buttons({
    createOrder: function(data, actions) {
    return actions.order.create({
        purchase_units: [{
        amount: {
            currency_code: 'USD',
            value: '0.01',
            amount_breakdown: {

            }

          },
            items: {
                item: {
                    name: 'Cake',
                    quantity:'1',
                    unit_amount:{
                        currency_code:'USD',
                        value:'0.01'
                    }
                }
            }



    }],
        application_context: {
            shipping_preference: 'NO_SHIPPING',
        }

      });
    },
    onApprove: function(data, actions) {
    return actions.order.capture().then(function(details) {
            alert('Transaction completed by ' + details.payer.name.given_name);
            // Call your server to save the transaction
            return fetch('/paypal-transaction-complete', {
          method: 'post',
          body: JSON.stringify({
            orderID: data.orderID
          })
        });
      });
}
  }).render('#paypal-button-container');
</script>
</head>

<body>
<div id="paypal-button-container"></div>
</body>
1个回答

21

这是我用于purchase_units的正确代码,我从这里得到了它:

https://github.com/paypal/paypal-checkout-components/issues/1016

purchase_units: [{
                amount: {
                    value: '7',
                    currency_code: 'USD',
                    breakdown: {
                        item_total: {value: '7', currency_code: 'USD'}
                    }
                },
                invoice_id: 'muesli_invoice_id',
                items: [{
                    name: 'Hafer',
                    unit_amount: {value: '3', currency_code: 'USD'},
                    quantity: '1',
                    sku: 'haf001'
                }, {
                    name: 'Discount',
                    unit_amount: {value: '4', currency_code: 'USD'},
                    quantity: '1',
                    sku: 'dsc002'
                }]
            }]

SKU不是必需的字段,尽管对于你来说可能很重要,Caleb。 - Ken

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接