繁体   English   中英

Node.js Express.js PayPal 集成

[英]Node.js Express.js PayPal integration

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

应用程序.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" }] };

购物车.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 将总数整合到我的网站中

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM