Javascript Node.js SDK for PayPal API-尝试创建和执行付款时资源ID无效
我正在尝试使用Node.js PayPal SDK执行基本的PayPal支付。我正在尝试使用“快速结帐”流程 在我的客户端页面上,我有以下代码:Javascript Node.js SDK for PayPal API-尝试创建和执行付款时资源ID无效,javascript,node.js,paypal,Javascript,Node.js,Paypal,我正在尝试使用Node.js PayPal SDK执行基本的PayPal支付。我正在尝试使用“快速结帐”流程 在我的客户端页面上,我有以下代码: <div id="paypal-button"></div> <script> paypal.Button.render({ env: 'sandbox', // Or 'sandbox', commit: true, // Show a 'Pay
<div id="paypal-button"></div>
<script>
paypal.Button.render({
env: 'sandbox', // Or 'sandbox',
commit: true, // Show a 'Pay Now' button
payment: function() {
return paypal.request.post("/Checkout/checkout").then(function(data) {
console.log("I returned!" + data.id);
return data.id;
});
},
onAuthorize: function(data, actions) {
return paypal.request.post("/Checkout/confirmation", {
paymentID: data.id,
payerID: data.payerID}).then(function() {
window.location("/Checkout/Success");
});
}
}, '#paypal-button');
</script>
paypal_config.js文件如下所示:
var paypal = require("paypal-rest-sdk");
require("../../config/paypal_config.js");
module.exports = {
addCart: function(req, res) {
var items = [];
var listingID = req.param("id");
var cartID;
if (req.cookies.cart == {} || req.cookies.cart == null) { // cart is not set
// Create cart in DB and in Session
Cart.create().exec((err, cart) => {
res.cookie("cart", cart.cartID);
cartID = cart.cartID;
});
} else { // retrieve existing cart using session cookie
cartID = req.cookies.cart;
}
// Add items to cart and recalculate total
CartItem.create({ quantity: req.param("quan"), listing: listingID, cart: cartID, unitPrice: req.param("unitPrice") }).exec((err, result) => {
if (!err) {
return res.redirect("/checkout/cart");
} else {
console.log("Error - " + err);
}
});
},
// read cart, display total, prepare transaction details for PayPal
cart: function(req, res) {
return res.view("checkout/cart");
/* var cartItems = req.cookies.cart.items;
CartService.getCartView(cartItems, function(err, results) {
if (!err) {
return res.view("checkout/cart", { items: results });
}
});*/
},
checkout: function(req, res) {
Cart.findOne({ cartID: req.cookies.cart }).populate("cartItems").exec( function(err, cart) {
if (!err) {
console.log(cart);
cart.updateCart();
cart.save();
var jsonTran = cart.returnTransactionJSON();
paypal.payment.create(jsonTran, function(err, payment) {
if(err) {
console.log(JSON.stringify(err));
} else {
console.log("This is the payment.");
return res.send(payment);
}
});
}
});
},
cancel: function(req, res) {
return view("checkout/cancel")
},
confirmation: function(req, res) {
var paymentID = req.query.paymentID;
var payerID = { payer_id: req.query.PayerID };
paypal.payment.execute(paymentID, payerID, (err, payment) => {
if (!err && payment.status == "approved") {
console.log("Payment completed!");
return view("checkout/confimation");
} else {
console.log(JSON.stringify(err));
}
})
}
};
var paypal = require("paypal-rest-sdk");
paypal.configure({
"mode": "sandbox",
"client_id": "MYCLIENTKEY",
"client_secret": "MYSECRETKEY"
})
我可以使用我的测试帐户登录;但是,每当我单击“立即付款”按钮时,窗口仅停留在“处理…”屏幕上,我收到以下错误:
This is the payment. // logged from my code above
'{"Authorization":"Bearer A21AAHQU9emmuxBOevEsdGWl2NcE_gnz7rMARxbPVF6fW7LlZW8mCkzpv8ra5pBpQGRcxKJ95nuos7t6ITJxdY
m_b63Yx374Q","Content-Length":2,"Accept":"application/json","Content-Type":"application/json","PayPal-Request-Id
":"d19c6ac5-cd3e-428b-aa9d-4f7d34b6c013","User-Agent":"PayPalSDK/PayPal-node-SDK 1.7.1 (node v6.11.0-x64-linux;
OpenSSL 1.0.2k)"}'
'{}'
paypal-debug-id: a7c118ac9eb71, a7c118ac9eb71
'{"date":"Tue, 04 Jul 2017 00:34:26 GMT","server":"Apache","paypal-debug-id":"a7c118ac9eb71, a7c118ac9eb71","con
tent-language":"*","connection":"close","set-cookie":["X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%
26app%3Dplatformapiserv%26TIME%3D2464307801%26HTTP_X_PP_AZ_LOCATOR%3D; Expires=Tue, 04 Jul 2017 01:04:26 GMT; do
main=.paypal.com; path=/; Secure; HttpOnly","X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT"],"vary":"Auth
orization","content-length":"204","content-type":"application/json"}'
'{"name":"INVALID_RESOURCE_ID","message":"Requested resource ID was not found.","information_link":"https://deve
loper.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID","debug_id":"a7c118ac9eb71"}'
{"response":{"name":"INVALID_RESOURCE_ID","message":"Requested resource ID was not found.","information_link":"h
ttps://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID","debug_id":"a7c118ac9eb71","httpSta
tusCode":404},"response_stringified":"{\"name\":\"INVALID_RESOURCE_ID\",\"message\":\"Requested resource ID was
not found.\",\"information_link\":\"https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID
\",\"debug_id\":\"a7c118ac9eb71\",\"httpStatusCode\":404}","httpStatusCode":404}
我的客户端代码记录了以下内容:
I returned!PAY-14496911M2734903LLFNOF4Q
任何帮助都将不胜感激。
谢谢
谢谢您的帮助。似乎有一些人也遇到过同样的问题,不确定您是否能在这里找到对您有帮助的内容,或者谢谢,我会看一看。非常欢迎,我希望您能从这些人中找到一些帮助。我还没有将paypal与
node.js一起使用过,所以除了上面的评论之外,我无法提供任何进一步的帮助:(