如何摆脱 paypal-rest-sdk 的验证错误?
How to get rid of validation error with paypal-rest-sdk?
我正在使用 paypal-rest-sdk 来练习使用 paypal 结账。我设置了一个小测试,每当我在表单中单击提交时,我都会在 Chrome 中收到 "localhost refused to connect" 错误。我关闭了我的代理并清除了我的历史记录和缓存。我还仔细检查了我的客户端和来自 Paypal 的密钥。我不确定我做错了什么。这是我的代码:
app.js:
const express = require('express');
const ejs = require('ejs');
const paypal = require('paypal-rest-sdk');
paypal.configure({
'mode': 'sandbox', //sandbox or live
'client_id': 'xxxxxxxx',
'client_secret': 'xxxxxxx'
});
const app = express();
app.set('view engine', 'ejs');
app.get('/', (req, res) => res.render('index'));
// create the json obj for the transaction with the order details
app.post('/pay', (req, res) => {
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": "25.00",
"currency": "USD",
"quantity": 1
}]
},
"amount": {
"currency": "USD",
"total": "1.00"
},
"description": "This is the payment description."
}]
};
// pass in the object we've created and now create the actual payment
paypal.payment.create(create_payment_json, function (error, payment) {
if (error) {
console.log(error);
throw error;
} else {
console.log("Create Payment Response");
console.log(payment);
res.send('test');
}
});
});
app.listen(3000, () => console.log('Server Started'));
这是终端从错误中输出的内容:
response:
{ name: 'VALIDATION_ERROR',
details: [ [Object] ],
message: 'Invalid request - see details',
information_link: 'https://developer.paypal.com/docs/api/payments/#errors',
debug_id: 'fb61fe9c14b46',
httpStatusCode: 400 },
httpStatusCode: 400 }
我希望 'test' 的消息在呈现支付路线时出现在屏幕上,以便我知道连接有效,但到目前为止我得到的只是 "ERR_CONNECTION_REFUSED" 来自 Chrome。请让我知道我做错了什么。提前致谢。
您的付款 JSON 缺少必需的信息。
请在下方查看有效付款 JSON:
{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://www.example.com/return_url",
"cancel_url": "http://www.example.com.br/cancel"
},
"transactions": [
{
"amount": {
"currency": "USD",
"total": "200.00",
"details": {
"shipping": "10.00",
"subtotal": "190.00"
}
},
"item_list": {
"items": [
{
"name": "Foto 1",
"currency": "USD",
"sku": "123",
"quantity": "1",
"price": "190.00"
}
]
},
"description": "Payment description"
}
]
}
我正在使用 paypal-rest-sdk 来练习使用 paypal 结账。我设置了一个小测试,每当我在表单中单击提交时,我都会在 Chrome 中收到 "localhost refused to connect" 错误。我关闭了我的代理并清除了我的历史记录和缓存。我还仔细检查了我的客户端和来自 Paypal 的密钥。我不确定我做错了什么。这是我的代码:
app.js:
const express = require('express');
const ejs = require('ejs');
const paypal = require('paypal-rest-sdk');
paypal.configure({
'mode': 'sandbox', //sandbox or live
'client_id': 'xxxxxxxx',
'client_secret': 'xxxxxxx'
});
const app = express();
app.set('view engine', 'ejs');
app.get('/', (req, res) => res.render('index'));
// create the json obj for the transaction with the order details
app.post('/pay', (req, res) => {
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": "25.00",
"currency": "USD",
"quantity": 1
}]
},
"amount": {
"currency": "USD",
"total": "1.00"
},
"description": "This is the payment description."
}]
};
// pass in the object we've created and now create the actual payment
paypal.payment.create(create_payment_json, function (error, payment) {
if (error) {
console.log(error);
throw error;
} else {
console.log("Create Payment Response");
console.log(payment);
res.send('test');
}
});
});
app.listen(3000, () => console.log('Server Started'));
这是终端从错误中输出的内容:
response:
{ name: 'VALIDATION_ERROR',
details: [ [Object] ],
message: 'Invalid request - see details',
information_link: 'https://developer.paypal.com/docs/api/payments/#errors',
debug_id: 'fb61fe9c14b46',
httpStatusCode: 400 },
httpStatusCode: 400 }
我希望 'test' 的消息在呈现支付路线时出现在屏幕上,以便我知道连接有效,但到目前为止我得到的只是 "ERR_CONNECTION_REFUSED" 来自 Chrome。请让我知道我做错了什么。提前致谢。
您的付款 JSON 缺少必需的信息。 请在下方查看有效付款 JSON:
{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://www.example.com/return_url",
"cancel_url": "http://www.example.com.br/cancel"
},
"transactions": [
{
"amount": {
"currency": "USD",
"total": "200.00",
"details": {
"shipping": "10.00",
"subtotal": "190.00"
}
},
"item_list": {
"items": [
{
"name": "Foto 1",
"currency": "USD",
"sku": "123",
"quantity": "1",
"price": "190.00"
}
]
},
"description": "Payment description"
}
]
}