【问题标题】:Node.js Express.js PayPal integrationNode.js Express.js 贝宝集成
【发布时间】:2020-07-12 10:09:05
【问题描述】:

我需要将 PayPal 集成到我的网站中,并且我已经集成了它,但我现在不知道如何将 total 放入我的代码中的 paypal 语法中。在 app.js 中,它为我在网站中的页面创建路由。在 cart.js 中,我创建了购物车和一个计算总数的函数。

app.js

app.post('/pay', function(  data,req, res)  {
    
 

  console.log(total);
  const create_payment_json = {
    "intent": "sale",
    "payer": {
        "payment_method": "paypal"
    },
    "redirect_urls": {
        "return_url": "http://localhost:3000/success",
        "cancel_url": "http://localhost:3000/cancel"
    },
    "transactions": [{
        "item_list": {
            "items": [{
                // "name": "Red Sox Hat",
                // "sku": "001",
                "price": "45.00",
                "currency": "USD",
                "quantity": 1
            }]
        },
        "amount": {
            "currency": "USD",
            "total": total,
        },
        "description": "Hat for the best team ever"
    }]
  
};

cart.js

function showCart(data) {
  let out = '<table class="table table-striped table-cart"><tbody>';
  let total = 0;
  for (let key in cart) {
    out += `<tr><td colspan="4"><a href="/goods?id=${key}">${data[key]['name']}</a></tr>`;
    out += `<tr><td><i class="far fa-minus-square cart-minus" data-goods_id="${key}"></i></td>`;
    out += `<td>${cart[key]}</td>`;
    out += `<td><i class="far fa-plus-square cart-plus" data-goods_id="${key}"></i></td>`;
    out += `<td>${formatPrice(data[key]['cost'] * cart[key])} lei </td>`
    out += '</tr>';
    total += cart[key] * data[key]['cost'];
  }
  out += `<tr><td colspan="3">Total: </td><td>${formatPrice(total)}lei</td></tr>`;
  out += '</tbody></table>';
  document.querySelector('#cart-nav').innerHTML = out;
  document.querySelectorAll('.cart-minus').forEach(function (element) {
    element.onclick = cartMinus;
  });
  document.querySelectorAll('.cart-plus').forEach(function (element) {
    element.onclick = cartPlus;
  });
}

图片

如何将总数从 card.js 整合到我的网站中

【问题讨论】:

    标签: javascript node.js express paypal


    【解决方案1】:

    我会使用 PayPal Checkout 的服务器端演示模式作为基础:

    https://developer.paypal.com/demo/checkout/#/pattern/server

    【讨论】:

    • 朋友给我你的联系方式,我给你写信,有时间请帮我看看
    猜你喜欢
    • 2011-08-01
    • 2011-11-03
    • 2016-08-18
    • 2013-05-13
    • 2011-05-24
    • 2013-07-10
    • 2015-09-08
    • 2012-10-05
    • 2012-03-13
    相关资源
    最近更新 更多