【问题标题】:How to send an itemised PayPal invoice to user and merchant?如何向用户和商家发送明细的 PayPal 发票?
【发布时间】:2020-07-11 07:24:53
【问题描述】:

我正在开发一个包含商店的网站。用户可以在这家商店使用 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】:

    项目进入purchase_units 数组,记录在at v2/orders。可能很难理解所有必需的细分参数,必须加起来,否则结帐会出错并且无法打开——所以这里有一个包含两个项目的示例:

    "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",
            },
          ],
        }
      ]
    

    【讨论】:

    • 谢谢!如果用户添加了超过 2 个项目怎么办?这将如何运作?
    • 您将拥有一个包含更多项目的更长数组,或者数组中已经存在的项目数量会更高,并且所有总数都会更新以匹配
    • 哦,好吧,所以我把商店里所有的东西都加进去了吗?
    • 不,您需要将 purchase_units 设置为该特定客户在该特定付款尝试期间购买的商品
    • 我不能提供太多特别的建议;但是,是的,这是一个简单的 javascript/网页设计任务,所以你可以把它当作一个练习和学习的机会,就好像它是一个家庭作业问题
    猜你喜欢
    • 2012-09-25
    • 2014-12-23
    • 2012-10-16
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 2019-04-29
    • 2012-04-22
    • 2018-10-15
    相关资源
    最近更新 更多