当前位置: 首页 > 知识库问答 >
问题:

PayPal express结账:无法处理与沙箱测试帐户的付款

通博实
2023-03-14
POST https://www.sandbox.paypal.com/webapps/hermes/api/batch/setbuyer 400 (Bad Request)
{
"ack": "success",
"data": {
    "buyerEligibility": {
        "ack": "success",
        "data": {
            "eligible": true,
            "clearedRT": false
        },
        "meta": {
            "calc": "8f7cc8e266c07",
            "rlog": "PVs6nBwuIQ9X2gSdIEqzR%2BxkmohYC3WlOiW4HauQ%2FY%2Fh%2BkWFfmr2pOeyxVs3sSiqXDydWuJ%2B6QWLAsZZVtRfIA_15d276b99bf"
        },
        "server": "xG7Ol-1A5r4xEqHEubzBtkj6LgLo88Z7UFOPmqsoK957Q11gkENbvzjGa02RjhyhvYG_ff2SZRFgHYp0Nq5rCCIdwQAwbwL-RkZ0piofvsP6-i9NmpkouuuH47EBynDbMencyfNKhT-cIewGtGK2jKUX_q0FaWq9Gx0MaRB6QBwINBmRQB5tAuklfWE8ooIwOO7szgPXVg9pOXWI2ukxup08j93HODToZ4DnSLuqCK6XM2M49-_DDSyS6GviI3gWrBy7BLOsHky"
    },
    "eConsent": {
        "ack": "success",
        "data": {
            "required": false
        },
        "meta": {
            "calc": "8f7cc8e266c07",
            "rlog": "PVs6nBwuIQ9X2gSdIEqzR%2BxkmohYC3WlOiW4HauQ%2FY%2Fh%2BkWFfmr2pOeyxVs3sSiqXDydWuJ%2B6QWLAsZZVtRfIA_15d276b99bf"
        },
        "server": "-bDk6FVAJFycsTL-R5q_CGdrJwDz9XbAF9KqMHpr6QIMACZ6IA5zQ_BVyqi3jy6w9pKC5SS4TBrpDB_OJC0rU1W5wz5XBgo3ze_iOG0gDEwxuzu7WtAT1Nv5_VmLhmUWIdMm7qtgfy1y11v18zXSxhATUDaRI8hNdlnArSlBtKVNGWkhCD4OTp4KvSBXQ3lLHm-wCSrJzhpEmBoNZmDQMrd4wv1YEYA0VFPG1cPHapq9t4xJMLfiZOad10irqxJP"
    },
    "createCheckoutSession": {
        "ack": "contingency",
        "contingency": "PAYER_CANNOT_PAY",
        "errorData": {
            "cause": "",
            "step_up_context": {}
        },
        "meta": {
            "calc": "8f7cc8e266c07",
            "rlog": "PVs6nBwuIQ9X2gSdIEqzR%2BxkmohYC3WlOiW4HauQ%2FY%2Fh%2BkWFfmr2pOeyxVs3sSiqXDydWuJ%2B6QWLAsZZVtRfIA_15d276b99bf"
        },
        "server": "-eKOVjOLP5i0k_9Et8_N5HyfLSVBzycsA2AE8UY8RD88MnM3729QBQoHY2eD3sMhSThBqdYmvFoARIAbkHNoOT9jsHzAUCk1CtbA717xHK5gSuYujf5mvuDJQFXWlPEDBk7XFlZSyhUWy8VGKvYWwWhuTSzcjMdKIzRI_XTjfA2hQpzIvkbRQ5jLMDIIKeNm1XrF3mEMN3gkHzZIc2OBiRaVEA2Q0se_uVgEEGIbSgN2aeSOeh4WiMC08zUCvmdCLyCP0ZyE24fzDvL4ZMUurG"
    }
},
"meta": {
    "calc": "8f7cc8e266c07",
    "rlog": "PVs6nBwuIQ9X2gSdIEqzR%2BxkmohYC3WlOiW4HauQ%2FY%2Fh%2BkWFfmr2pOeyxVs3sSiqXDydWuJ%2B6QWLAsZZVtRfIA_15d276b99bf"
},
"server": "JwJRYq2SF3kUujC16-VsiMQu8IDN_RxPNOz8wY8m8YD4P3PzhHZB73hNd_IM9PktfJcPPHx2RyVUk1PV8bC2lLtejwTFKzq-7QDM9nLmxJLw7os2tgLnGYAebFJAkmIt2fFvlncVMrAg9bAsMF9INhPqixaCEWn7ug9OcPCci_3autJi3cvmTLb_8XvTaGBpPxI0ASQnkXTSVJa2GPIptYhGVHFN5N92hFdxzwp2uYQhHeJrePmExV4NlLd0s_wa"
class PayPalButton extends Component {
render() {
    const Btn = paypal.Button.driver('react', {React, ReactDOM});
    const CREATE_PAYMENT_URL = `${ROOT_URL}/paypal/create-payment/${this.props.regId}`;
    const EXECUTE_PAYMENT_URL = `${ROOT_URL}/paypal/execute-payment/${this.props.regId}`;
    const token = localStorage.getItem('deotoken');

    let client = {
        sandbox: 'TO_BE_REPLACED_WITH_SANDBOX_CLIENT_ID'
    };

    let payment = () => {
  return paypal.request({
    method: 'post',
    url: CREATE_PAYMENT_URL,
    headers: {
        authorization: token
    }
  })
  .then(function(data) {
      return data.id;
  });
    };

    let onAuthorize = (data) => {
  return paypal.request({
    method: 'post',
    url: EXECUTE_PAYMENT_URL,
    headers: {
        authorization: token
    },
    json: {
                paymentID: data.paymentID,
      payerID:   data.payerID
    } 
  }).then(function() {
      // The payment is complete!
      // You can now show a confirmation message to the customer
      console.log('done');
  });
    };

return (
    <div>
    <Btn env={'sandbox'}
      client={client}
      payment={payment}
      commit={true}
      onAuthorize={onAuthorize}
    />
    </div>
);
}
module.exports = {
createPayment(req, res, next) {
    const { registration_id } = req.params;
    const { user } = req;

    Registration.findById(registration_id)
    .populate({ path: 'category', model: 'category' })
    .populate({ path: 'orders.meal', model: 'meal' })
    .then(reg => {
        if (reg) {
            const categoryItem = [{
                name: reg.category.name,
                sku: reg.category.name,
                price: reg.category.price,
                currency: 'MYR',
                quantity: 1
            }];
            const ordersItems = reg.orders.map(order => {
                return {
                    name: order.meal.name,
                    sku: order.meal.name,
                    price: order.meal.price,
                    currency: 'MYR',
                    quantity: order.quantity
                }
            });

            const create_payment_json = {
                intent: 'sale',
                payer: {
                    payment_method: 'paypal'
                },
                redirect_urls: {
                    return_url: 'http://localhost:8080/',
                    cancel_url: 'http://localhost:8080/'
                },
                transactions: [{
                    item_list: {
                        items: [...categoryItem, ...ordersItems]
                    },
                    amount: {
                        currency: 'MYR',
                        total: reg.totalBill
                    }
                }]
            };

            paypal.payment.create(create_payment_json, function(err, payment) {
                if (err) { 
                    next(err); 
                } else {
                    res.send(payment);
                }

            })
        } else {
            return res.status(422).send({error: 'Registration not found'});
        }
    })
    .catch(next);

},
executePayment(req, res, next) {
    const { registration_id } = req.params;
    const { paymentID, payerID } = req.body;

    const execute_payment_json = {
        payer_id: payerID
    }

    paypal.payment.execute(paymentID, execute_payment_json, function(err, paypalResponse) {
        if (err) {
            next(err);
        } else {
            if (paypalResponse.state === 'approved') {
                const payment = new Payment({
                    user: req.user._id,
                    registration: registration_id,
                    amount: paypalResponse.transactions[0].amount.total,
                    currency: paypalResponse.transactions[0].amount.currency,
                    paypalPaymentId: paypalResponse.id
                });

                payment.save()
                    .then(p => res.send(p))
                    .catch(next);
            } else {
                res.status(422).send({ error: 'Payment not approved' });
            }
        }
    });
}

问题是什么?我怎么才能让这件事成功呢?

共有1个答案

姜飞飙
2023-03-14

我也遇到过同样的问题。我已经设置INR作为我的货币在我的贝宝沙箱,但发送金额作为美元从API调用。所以,我认为我们必须用我们在沙箱中设置的货币进行交易。

以前得有效载荷:

transactions: [{
                item_list: {
                    items: [...categoryItem, ...ordersItems]
                },
                amount: {
                    currency: 'USD',
                    total: reg.totalBill
                }
            }]

更改有效载荷后:

transactions: [{
                item_list: {
                    items: [...categoryItem, ...ordersItems]
                },
                amount: {
                    currency: 'INR',
                    total: reg.totalBill
                }
            }]
 类似资料:
  • 我有一个英国贝宝商业账户。我目前正在开发一个网站支付系统,以支付到这个帐户使用快速结帐。 到目前为止,我的PHP代码工作正常,我能够连接到沙箱并设置和快速签出。下一个阶段是将用户重定向到PayPal沙箱进行测试支付。 null 当它说“删除这个账户”时,我不知道它实际上是什么意思,因为它没有用我刚刚输入的细节创建一个新的个人账户(至少没有一个我可以在任何地方看到的账户)。我甚至尝试创建一个新的商业

  • 本文向大家介绍PayPal 设置沙箱用户测试帐户,包括了PayPal 设置沙箱用户测试帐户的使用技巧和注意事项,需要的朋友参考一下 示例 在沙盒上测试PayPal集成时,您需要设置沙盒用户帐户以用于支付流程。 转到https://developer.paypal.com/developer/accounts/,使用您的PayPal帐户登录,然后单击“创建帐户”,如下所示: 输入新测试用户的帐户详细

  • {“response_envelope”=>{“timestamp”=>“2015-10-06T22:55:49.604-07:00”,“ack”=>“success”,“correlation_id”=>“9f0f563554297”,“build”=>“17820627”},“currency_code”=>“usd”,“refund_info_list”=>{“refund_info”=>[

  • 我已经配置了贝宝支付方式,我使用了商务电子邮件kokoxxx-facilitator@gmail.com,注意它与上面显示的pdt用户名不同,我复制并粘贴了上面显示的签名,我将ipn处理程序留空。然后我以来宾身份测试了一个交易,并输入了发货和账单地址(我的实际德克萨斯地址!)在这里我不知道这是否重要。在付款方式我看到两个选项信用卡和是信用卡!!我继续进入buyertest电子邮件作为沙箱帐户,并输

  • 一位客户报告说,在他创建贝宝账户之前,他无法使用贝宝支付我们的服务。因为我们启用了必要的设置,所以需要调试。 我想把这个问题复制到计算机上https://developer.paypal.com/ 但我不知道如何在不登录帐户或在那里创建帐户的情况下“支付”。 如何在PayPal沙盒网站上测试“没有PayPal账户的结账”?