【发布时间】: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