PayPal REST SDK完成交易,但等待商家帐户完成帐户[关闭]

问题描述 投票:-2回答:2

我想向我的客户销售功能/功能,支付应该是即时的,以便在交易完成时立即解锁功能。

我设法执行交易,沙箱个人帐户显示该交易,但沙盒商家帐户没有显示任何批准它的内容。沙箱个人帐户显示“这是一项临时授权,以确保您的付款方式将涵盖付款。当jawad商家的测试商店完成您的订单时,将收取您的付款方式。”

这是代码:

var express = require('express');
const router = express.Router();
var paypal = require('paypal-rest-sdk');

paypal.configure({
    'mode': 'sandbox', //sandbox or live 
    'client_id': 'client id', 
    'client_secret': 'client secret'  
});

// payment process 
router.use('/buy', (req, res) => {


    // payment object 
    var payment = {
        "intent": "authorize",
        "payer": {
            "payment_method": "paypal"
        },
        "redirect_urls": {
            "return_url": "http://localhost:4040/xyz/paypal/success",
            "cancel_url": "http://localhost:4040/xyz/paypal/err"
        },
        "transactions": [{
            "item_list": {
                "items": [{
                    "name": 'item1',
                    "sku": "item",
                    "price": '39',
                    "currency": "USD",
                    "quantity": 1
                }]
            },
            "amount": {
                "total": 39.00,
                "currency": "USD"
            },
            "description": "A feature "
        }]
    }


    // calling the create Pay method 
    createPay(payment)
        .then((transaction) => {
            var id = transaction.id;
            var links = transaction.links;
            var counter = links.length;
            while (counter--) {
                if (links[counter].method == 'REDIRECT') {
                    // redirecting to paypal where user approves the transaction 
                    return res.redirect(links[counter].href)
                }
            }
        })
        .catch((err) => {
            console.log(err);
            res.redirect('/err');
        });
});
// success page 
router.use('/success', (req, res) => {


    var paymentId = req.query.paymentId;
    var payerId = { 'payer_id': req.query.PayerID };

    paypal.payment.execute(paymentId, payerId, function(error, payment){
        if(error){
            console.error(error);
        } else {
            if (payment.state === 'approved'){ 
                res.send('payment completed successfully');
                console.log(payment);
            } else {
                res.send('payment not successful');
            }
        }
    });
})

// error page 
router.use('/err', (req, res) => {
    console.log(req.query);
    res.redirect('https://soundcloud.com/');
})

// helper functions 
var createPay = (payment) => {
    return new Promise((resolve, reject) => {
        paypal.payment.create(payment, function (err, payment) {
            if (err) {
                reject(err);
            }
            else {
                resolve(payment);
                console.log(payment)
            }
        });
    });
}

module.exports = router;

帮助我以下内容:

  1. 我的交易不应与送货地址相关联,
  2. 交易应该是即时的,而paypal个人沙箱帐户不应该这样说: enter image description here
  3. 用户可以购买一个或多个功能,
  4. 解释最后帮助函数的作用

先感谢您。我希望这段代码也可以帮助别人

javascript node.js express paypal paypal-rest-sdk
2个回答
0
投票

本文档显示了按钮代码中no_shipping字段的使用:

https://developer.paypal.com/docs/checkout/how-to/customize-flow/#pass-experience-profile-options

要直接调用API,您必须创建一个包含此字段的Web体验配置文件对象(input_fields.no_shipping):

https://developer.paypal.com/docs/api/payment-experience/v1/#web-profiles_create

然后在您的/付款电话(experience_profile_id字段)https://developer.paypal.com/docs/api/payments/v1/#payment中引用它


1
投票
  1. 在Classic API中,有一个NOSHIPPING标志,您可以在请求中包含该标志,以便在结账时禁用送货地址要求。我知道它在REST的某个地方,但我现在正努力在引用中找到它。
  2. 而不是“授权”,你应该使用“sale”作为intent参数。
  3. 不知道你在这里问什么.. ??只需构建您的购物车,以便您的用户可以根据需要添加任意数量的商品,然后将这些购物车详细信息传递到您的PayPal付款请求中。
  4. 它似乎正在处理PayPal的实际付费电话(即paypal.payment.create)
© www.soinside.com 2019 - 2024. All rights reserved.