如何向用户和商家发送逐项的PayPal发票?

问题描述 投票:1回答:1

我正在开发一个包含商店的网站。用户可以在此商店中使用PayPal进行付款,并且效果很好!购物车是使用JavaScript编程的,这引起了一些问题。

我本来想拥有一个JS函数,该函数向用户发送了带有购物车的电子邮件,但是我可以找到用于此目的的任何代码。我知道您可以使用PayPal获得逐项收据,但是我的系统不会提供这些详细信息。我已经阅读了PayPal网站的开发人员部分,但似乎无法弄清楚!

我的PayPal脚本如下:

<script>
        paypal.Buttons({
            createOrder: function(data, actions) {
                // This function sets up the details of the transaction, including the amount and line item details.
                return actions.order.create({
                    purchase_units: [{
                        amount: {
                            value: countCartTotal()
                        }
                    }]
                });
            },
            onApprove: function(data, actions) {
                // This function captures the funds from the transaction.
                return actions.order.capture().then(function(details) {
                    // This function shows a transaction success message to your buyer.
                    window.location.href = "orderConfirmed.php"
                    clearCart()
                });
            }
        }).render('#paypal-button-container');
        //This function displays Smart Payment Buttons on your web page.
    </script>

购物车已在cart.js中编码,我知道我可以在PayPal脚本中使用此文件中的函数,因为函数'countCartTotal()'告诉PayPal向客户收取的费用。在我的购物车中。 js,这就是我将商品添加到购物车的方式:

function insertItemToDOM(product) {
    cartDOM.insertAdjacentHTML('beforeend', `
    <div class="cart__item">
      <img class="cart__item__image" src="${product.image}" alt="${product.name}">
      <h3 class="cart__item__name">${product.name}</h3>
      <h3 class="cart__item__price">${product.price}</h3>
      <button class="btn btn--primary btn--small${(product.quantity === 1 ? ' btn--danger' : '')}" data-action="DECREASE_ITEM">&minus;</button>
      <h3 class="cart__item__quantity">${product.quantity}</h3>
      <button class="btn btn--primary btn--small" data-action="INCREASE_ITEM">&plus;</button>
      <button class="btn btn--danger btn--small" data-action="REMOVE_ITEM">&times;</button>
    </div>
  `);

    addCartFooter();
}

我需要让Paypal包含'$ {product.name}'和'$ {product.quantity}']

javascript html paypal shopping-cart
1个回答
1
投票

项目进入purchase_units数组,记录在at v2/orders中。可能很难理解所有必需的故障参数,这些故障参数加起来[[must否则结帐将出错并且无法打开-因此,这里有两个示例:

"purchase_units": [{ "description": "Stuff", "amount": { "value": "20.00", "currency_code": "USD", "breakdown": { "item_total": { "currency_code": "USD", "value": "20.00" }, } }, "items": [ { "unit_amount": { "currency_code": "USD", "value": "10.00" }, "quantity": "1", "name": "Item 1", }, { "unit_amount": { "currency_code": "USD", "value": "10.00" }, "quantity": "1", "name": "Item 2", }, ], } ]
© www.soinside.com 2019 - 2024. All rights reserved.