我正在为这个用于PayPal的sdk工作,我遇到了一堆错误,例如:“服务器遇到内部错误或配置错误,无法完成您的请求。
请与服务器管理员webmaster@paypal.com联系,告知他们错误发生的时间,以及可能导致错误的任何操作。
有关此错误的详细信息可能在服务器错误日志“
中提供当一切似乎都正常时,我将所有支付json转回/成功。问题是console.log(“payerId =”+ payerId)永远不会记录,当我登录我的沙箱时,我没有任何交易的历史,即使我通过了一个动作。我没有得到任何错误,所以我正在做错事。 THX!
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const path = require('path')
let port = 5007;
let app = express();
// const ejs = require('ejs');
const paypal = require('paypal-rest-sdk');
// const Paypal = require('./Server/Paypal_api.js')
// const Nodemailer = require('./Server/Nodemailer.js')
// app.use(express.static(path.join(__dirname, 'public')));
// app.use(express.static('assets'))
// app.use(cors())
// app.use(bodyParser.json())
paypal.configure({
'mode': 'sandbox', //sandbox or live
'client_id': 'AYoej9yvsPTO_giNMnI5pMecd4vbelcK_N',
'client_secret': 'EE8rJValbapV4Dk-g5yFFMG7pMC-bwwwv7sO'
});
客户ID&秘密不是真的,但你明白了
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": "25.00"
},
"description": "Hat for the best team ever"
}]
};
paypal.payment.create(create_payment_json, (error, payment) =>{
if (error) {
throw error;
} else {
// console.log(payment)
for(let i = 0;i < payment.links.length;i++){
if(payment.links[i].rel === 'approval_url'){
res.redirect(payment.links[i].href);
}
}
}
});
});
app.get('/success', (req, res) => {
const payerId = req.query.PayerID;
const paymentId = req.query.paymentId;
console.log("payerId = " + payerId)
const execute_payment_json = {
"payer_id": payerId,
"transactions": [{
"amount": {
"currency": "USD",
"total": "25.00"
}
}]
};
paypal.payment.execute(paymentId, execute_payment_json, (error, payment) =>{
if (error) {
console.log(error.response);
throw error;
} else {
console.log(JSON.stringify(payment));
res.send('Success');
}
});
});
app.get('/cancel', (req, res) => res.send('Cancelled'));
app.listen(port, () => {
console.log("resonating on port " + port)
})