gpt4 book ai didi

javascript - 如何摆脱 paypal-rest-sdk 的验证错误?

转载 作者:行者123 更新时间:2023-11-30 13:53:05 25 4
gpt4 key购买 nike

我正在使用 paypal-rest-sdk 练习使用 paypal 结账。我设置了一个小测试,每当我在我的表单中单击提交时,我都会在 Chrome 中收到“localhost refused to connect”错误。我关闭了我的代理并清除了我的历史记录和缓存。我还仔细检查了我的客户端和来自 Paypal 的 key 。我不确定我做错了什么。这是我的代码:

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

我希望在呈现付费路线时屏幕上出现“测试”消息,以便我知道连接有效,但到目前为止我得到的只是来自 Chrome 的“ERR_CONNECTION_REFUSED”。请让我知道我做错了什么。提前致谢。

最佳答案

您的付款 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"
}
]
}

关于javascript - 如何摆脱 paypal-rest-sdk 的验证错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57844641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com