【问题标题】:Adding a description and item name to PayPal javascript SDK向 PayPal javascript SDK 添加描述和项目名称
【发布时间】:2021-12-28 14:33:37
【问题描述】:

我使用 PayPal Javascript SDK 创建了我的第一个立即购买按钮。我发现了如何添加“不发货”(这是针对数字商品的),但我不知道如何添加商品编号和描述。谁能给我一些指点?

<!-- Include the PayPal JavaScript SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=CLIENT ID IS CORRECTLY ADDED&currency=USD"></script>

<script>
  paypal.Buttons({

    // Sets up the transaction when a payment button is clicked
    createOrder: function(data, actions) {
      return actions.order.create({
        purchase_units: [{
          
          amount: {
            value: '1'
          },
            
        }],
        application_context: {
            shipping_preference: "NO_SHIPPING",
        }
         
      });
    },

    // Finalize the transaction after payer approval
    onApprove: function(data, actions) {
      return actions.order.capture().then(function(orderData) {
        // Successful capture! For dev/demo purposes:
        //    console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
        //    var transaction = orderData.purchase_units[0].payments.captures[0];
        //   alert('Transaction '+ transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');

        // When ready to go live, remove the alert and show a success message within this page. For example:
        // var element = document.getElementById('paypal-button-container');
        // element.innerHTML = '';
        // element.innerHTML = '<h3>Thank you for your payment!</h3>';
        actions.redirect('https://wwwwebsite.com/att_thanks.php?id=1640035591');
      });
    }
  }).render('#paypal-button-container');

</script> 

【问题讨论】:

    标签: paypal


    【解决方案1】:

    阅读standard Checkout integration guide,它提供了完整的代码示例...

    createOrder: function(data, actions) {
          return actions.order.create({
             "purchase_units": [{
                "amount": {
                  "currency_code": "USD",
                  "value": "100",
                  "breakdown": {
                    "item_total": {  /* Required when including the `items` array */
                      "currency_code": "USD",
                      "value": "100"
                    }
                  }
                },
                "items": [
                  {
                    "name": "First Product Name", /* Shows within upper-right dropdown during payment approval */
                    "description": "Optional descriptive text..", /* Item details will also be in the completed paypal.com transaction view */
                    "unit_amount": {
                      "currency_code": "USD",
                      "value": "50"
                    },
                    "quantity": "2"
                  },
                ]
              }]
          });
        },
    

    并链接到the Orders v2 API reference 以获取完整的详细信息。

    【讨论】:

      猜你喜欢
      • 2013-11-17
      • 2016-11-25
      • 2017-11-29
      • 1970-01-01
      • 2014-11-14
      • 1970-01-01
      • 2022-11-16
      • 2021-03-23
      • 1970-01-01
      相关资源
      最近更新 更多