简体   繁体   English

如何使用Paypal-rest-SDK摆脱验证错误?

[英]How to get rid of validation error with paypal-rest-sdk?

I am using the paypal-rest-sdk to practice using the paypal checkout. 我正在使用paypal-rest-sdk练习使用Paypal结帐。 I've set up a small test and whenever I click submit in my form I get a "localhost refused to connect" error in Chrome. 我已经设置了一个小测试,每当我单击表单中的提交时,Chrome中都会出现“本地主机拒绝连接”错误。 I've turned off my proxy and cleared my history and cache. 我已关闭代理,并清除了历史记录和缓存。 I've also double checked my client and secret keys from Paypal. 我还仔细检查了我的客户和来自Paypal的密钥。 I'm not sure what I am doing wrong. 我不确定自己在做什么错。 Here's my code: 这是我的代码:

app.js: 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'));

here is what the terminal outputs from the error: 这是终端从错误中输出的内容:

  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 }

I expect the message of 'test' to appear on the screen when the pay route is rendered so that I know the connection works, but so far all I've gotten is "ERR_CONNECTION_REFUSED" from Chrome. 我希望呈现支付路线时在屏幕上会显示“测试”消息,以便我知道连接正常,但是到目前为止,我所获得的只是Chrome的“ ERR_CONNECTION_REFUSED”。 Please let me know what I am doing wrong. 请让我知道我在做什么错。 Thanks in advance. 提前致谢。

Your payment JSON is missing required information. 您的付款JSON缺少必填信息。 Please see an valid payment JSON below: 请在下面查看有效的付款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"
    }
]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM