Paypal Integration

Intro To The Node.js PayPal REST SDK

bradtraversy / node_paypal_sdk_sample – Git
https://github.com/bradtraversy/node_paypal_sdk_sample/blob/master/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': 'AaU8tQfmz1_MFDTKuf84yYERXvdDt2ZFJVrxhNW_49DazF4A_F0VBuKyV5_nntyEdZqUa5Oq9ZBj65GV',
  'client_secret': 'EAZ8aFDU4lHHLy1bQqULYWqznf3dBknXZW3AH__zFC0bUs8AGUyR6RNbm-jHvqtikX7PsSqMO5vxuvKm'
});

const app = express();

app.set('view engine', 'ejs');

app.get('/', (req, res) =&glt res.render('index'));

app.post('/pay', (req, res) =&glt {
  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": "25.00"
        },
        "description": "Hat for the best team ever"
    }]
};

paypal.payment.create(create_payment_json, function (error, payment) {
  if (error) {
      throw error;
  } else {
      for(let i = 0;i < payment.links.length;i++){
        if(payment.links[i].rel === 'approval_url'){
          res.redirect(payment.links[i].href);
        }
      }
  }
});

});

app.get('/success', (req, res) =&glt {
  const payerId = req.query.PayerID;
  const paymentId = req.query.paymentId;

  const execute_payment_json = {
    "payer_id": payerId,
    "transactions": [{
        "amount": {
            "currency": "USD",
            "total": "25.00"
        }
    }]
  };

  paypal.payment.execute(paymentId, execute_payment_json, function (error, payment) {
    if (error) {
        console.log(error.response);
        throw error;
    } else {
        console.log(JSON.stringify(payment));
        res.send('Success');
    }
});
});

app.get('/cancel', (req, res) =&glt res.send('Cancelled'));

app.listen(3000, () =&glt console.log('Server Started'));

PayPal Checkout API SDK for NodeJS – Git
https://github.com/paypal/Checkout-NodeJS-SDK

PayPal REST SDK – Git
https://github.com/paypal/paypal-node-SDK
Executes : https://github.com/paypal/PayPal-node-SDK/blob/master/samples/payment/execute.js

PayPal Checkout Basic Integration – Smart Payment Buttons Overview
https://developer.paypal.com/docs/checkout/#

PayPal Checkout Basic Integration – Add the Buttons
https://developer.paypal.com/docs/checkout/integrate/#

REST APIs – Get Started
https://developer.paypal.com/docs/api/overview/#

Get an Access Token – cURL
https://developer.paypal.com/docs/api/get-an-access-token-curl/

PayPal REST SDKs Quickstart Guide – Nodejs
https://developer.paypal.com/docs/api/rest-sdks/#

PayPal Button Integration – https://code.tutsplus.com/categories/paypal

Slide Share : https://www.slideshare.net/gcsr/integration-of-payment-gateways-using-paypal-account

Node.js Express Paypal REST API SDK Payment Gateway Integration Full Example with Source Code 2020
https://codingshiksha.com/javascript/node-js-express-paypal-rest-api-sdk-payment-gateway-integration-full-example-with-source-code-2020/

Node.js Express Paytm Payment Gateway Integration Full Tutorial with Source Code 2020
https://codingshiksha.com/javascript/node-js-express-paytm-payment-gateway-integration-full-tutorial-with-source-code-2020/

Factors to Consider While Choosing a Payment Gateway Provide
https://www.netsolutions.com/insights/12-factors-to-consider-while-choosing-a-payment-gateway-for-your-e-commerce-store/

Leave a Reply

Your email address will not be published. Required fields are marked *