Я пытаюсь реализовать Paypal Checkout с помощью приложения Vue во внешнем интерфейсе и внутреннего интерфейса Node.js, на котором работает Express. Я пытаюсь запустить установку по умолчанию, и все работает до шага 6: (https://developer.paypal.com/docs/checkout/integrate/#6-verify-the-transaction)
Здесь я должен отправить запрос из моего интерфейса (6.1 в статье)
// Call your server to save the transaction
return fetch('/paypal-transaction-complete', { ...
, где я изменил URL-адрес на свой собственный, поэтому http://localhost:3000/paypal-transaction-complete'
Мой код на стороне сервера точно такой же, как в учебнике, но заключен в экспресс-маршрут:
app.post('/paypal-transaction-complete', function (req, res) {
// 1. Set up your server to make calls to PayPal
// 1a. Import the SDK package
const checkoutNodeJssdk = require('@paypal/checkout-server-sdk');
// 1b. Import the PayPal SDK client that was created in `Set up Server-Side SDK`.
/**
*
* PayPal HTTP client dependency
*/
const payPalClient = require('./paypalClient');
// 2. Set up your server to receive a call from the client
module.exports = async function handleRequest(req, res) {
// 2a. Get the order ID from the request body
const orderID = req.body.orderID;
// 3. Call PayPal to get the transaction details
let request = new checkoutNodeJssdk.orders.OrdersGetRequest(orderID);
let order;
try {
order = await payPalClient.client().execute(request);
} catch (err) {
// 4. Handle any errors from the call
console.error(err);
return res.send(500);
}
// 5. Validate the transaction details are as expected
// if (order.result.purchase_units[0].amount.value !== '220.00') {
// return res.send(400);
// }
// 6. Save the transaction in your database
// await database.saveTransaction(orderID);
// 7. Return a successful response to the client
console.log('payment successful');
return res.send(200);
};
});
К сожалениюсервер никогда не перестает работать на этом, и через некоторое время я получаю странную ошибку typeError в моей консоли Frontend:
Uncaught TypeError: Не удалось получить
Error: Failed to fetch
at or.<computed> (https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:50112)
at Object.<anonymous> (https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:56841)
at JSON.parse (<anonymous>)
at o (https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:56700)
at gr (https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:56853)
at Nr.l.on (https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:61935)
at Nr (https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:62124)
at https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:66869
at https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:66915
Error: Failed to fetch
at or.<computed> (https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:50112)
at Array.<anonymous> (https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:56841)
at JSON.parse (<anonymous>)
at o (https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:56700)
at gr (https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:56853)
at Nr.l.on (https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:61935)
at Nr (https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:62124)
at https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:66869
at https://www.paypal.com/sdk/js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1:66915
or.<computed> @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
(anonymous) @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
o @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
gr @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
Nr.l.on @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
Nr @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
(anonymous) @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
(anonymous) @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
setTimeout (async)
(anonymous) @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
n.dispatch @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
n.then @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
(anonymous) @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
(anonymous) @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
e.try @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
l @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
trigger @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
(anonymous) @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
e.try @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
n.onError @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
t @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
(anonymous) @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
n.dispatch @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
n.then @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
(anonymous) @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
(anonymous) @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
e.try @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
Tr.postrobot_message_request @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
Nr @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
(anonymous) @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
(anonymous) @ js?client-id=AWPUth_gVe12aLPuvNT7Yp4YZbtn_sDZb7AHYoevpU5e6gH2zBy1rIdtlx7ao8fIYHA_JRI2wvKwmCrz:1
Я предполагаю, что мое обертываниекод в экспрессе как-то не так. Как будет выглядеть реальный рабочий результат с экспрессом?
Большое спасибо!