PayPal REST SDK: Remove shipping address and payment authorization so it does go to pending state [closed]

冷暖自知 提交于 2019-12-13 22:35:33

问题


I want to sell a feature/features to my client and the payment should be instant, so that it unlocks a feature immediately whenever the transaction is completed.

I managed to execute the transaction and the sandbox personal account shows that transaction but the sandbox merchant account doesn't show anything to approve it. sandbox personal account shows that " This is a temporary authorization to make sure your payment method will cover the payment. Your payment method will be charged when jawad merchant's Test Store completes your order."

this is the code :

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;

Help me with the following:

  1. My transactions shouldn't be linked to shipping addresses,

  2. Transaction should be instant and paypal personal sandbox account shouldn't say this:

  3. User can buy one or many features,

  4. Explain what the helper function at the end is doing

Thankyou in advance. I hope this code helps someone else too


回答1:


This document shows the use of the no_shipping field in button code:

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

To call the API directly, you have to create a web experience profile object containing this field (input_fields.no_shipping):

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

Then reference it in your /payment call (the experience_profile_id field) https://developer.paypal.com/docs/api/payments/v1/#payment




回答2:


  1. In the Classic API there was a flag for NOSHIPPING you could include in your request that would disable shipping address requirements during checkout. I know it's in REST somewhere, but I'm struggling to find it in the reference right now.

  2. Instead of "authorize" you should use "sale" for the intent parameter.

  3. Not sure what you're asking here..?? Just build your shopping cart so your user can add as many items as they want to their cart, and then pass those cart details into your PayPal payment request.

  4. It seems to be handling the actual pay call to PayPal (ie. paypal.payment.create)



来源:https://stackoverflow.com/questions/52297388/paypal-rest-sdk-remove-shipping-address-and-payment-authorization-so-it-does-go

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!