title: Payment Authorization & Capture the Payment (Future) using PayPal-node-SDK (PayPal Express Checkout)
body: <p>I'm working with PayPal Express Checkout and and what i need to do is Authorize and Capture the payment later separately, my current PayPal flow is,</p>
  
  <p>1) I create a payment using following code:</p>
  
  <pre><code>var paypal = require('paypal-rest-sdk');
  
  function createPayPal(req, res, itemsArray, redirectsTos) {
      var payment = {
          "intent": "sale",
          "payer": {},
          "transactions": [{
              "amount": {
                  "currency": sails.config.currency,
                  "total": itemsArray.totalArrayAmount,
                  "details": {
                      "subtotal": itemsArray.totalArrayAmount,
                      "fee": sails.config.PayPalCreateFee
                  }
              },
              "invoice_number": req.session.invNum,
              "item_list": {
                  "items": itemsArray.itemsArray
              }
          }]
      };
      sails.log.info('payment obj :', JSON.stringify(payment))
      payment.payer.payment_method = sails.config.PayPalPaymentMethod;
      payment.redirect_urls = {
          "return_url": res.locals.return_url_buy,
          "cancel_url": res.locals.cancel_url_buy
      };
  
      paypal.payment.create(payment, function(error, payment) {
          if (error) {
              sails.log.error(error);
              redirectsTos(({
                  message: 'failure',
                  redirect: '/paypal/error'
              }), null);
          } else {
          sails.log.info('Payment ID = ', payment.id);
          sails.log.info('User ID = ', req.session.userSession);
          var redirectUrl;
          for (var i = 0; i &lt; payment.links.length; i++) {
              var link = payment.links[i];
              if (link.method === 'REDIRECT') {
                  redirectUrl = link.href;
                  sails.log.info('goto:', redirectUrl)
                  redirectsTos(null, ({
                      message: 'success',
                      redirect: redirectUrl
                  }));
              }
          }
          }
      });
  }
  </code></pre>
  
  <p>and Paypal returns me the order information and the redirect <code>urls</code> and i redirected the user to the <code>href</code> in <code>links</code> object. then when the payflow returns to me website it sends me </p>
  
  <pre><code>{
      paymentId: 'PAY-5FB60654T5508144abcxyzZLQ',
      token: 'EC-26U68825EW2123428',
      PayerID: 'QSABTRW6AHYH6'
  }
  </code></pre>
  
  <p>and then i executed the payment using following code.</p>
  
  <pre><code>function executePayPal(req, paymentId, payerId, executedPayPal) {
      sails.log.info('in executedPayPal');
      var details = {
          "payer_id": payerId
      };
      var payment = paypal.payment.execute(paymentId, details, function(error, payment) {
          if (error) {
              sails.log.error('error in payment id in executePayPal function of paypal controller', error);
              var err = JSON.stringify(error);
              var errParsed = JSON.parse(err);
              crashHandlingService.appCrash(errParsed, 101202);
              executedPayPal(({
                  message: 'failure',
                  redirect: '/paypal/error/'
              }), null);
          } else {
              executedPayPal(({
                  message: 'success',
                  redirect: '/paypal/success/'
              }), null);
          }
      });
  }
  </code></pre>
  
  <p>Now what this code basically do is </p>
  
  <ol>
  <li>Create the payment, </li>
  <li>Redirect the user to paypal page C</li>
  <li>Capture the payment.</li>
  </ol>
  
  <p>and what i actually want to achieve is </p>
  
  <ol>
  <li>authorize the payment -></li>
  <li><p>capturing the payment so that i can capture the payment some later time in some cronJob or service.</p>
  
  <p>And redirect the user to paypal page in the middle of above flow, i really don't know how to authorize, redirect and then capture payment.</p></li>
  </ol>
  
  <p>So please guide me in this regards.</p>
  
  <p>Note: i've read the following paypal documentation but not able to understand. and please keep in mind that i need to show payment detail on paypal page and also the coupon code and its discount on the payment page.</p>
  
  <p><a href="https://developer.paypal.com/docs/integration/direct/capture-payment/#authorize-the-payment" rel="nofollow">https://developer.paypal.com/docs/integration/direct/capture-payment/#authorize-the-payment</a>
  <a href="https://developer.paypal.com/docs/classic/express-checkout/ht_ec-singleAuthPayment-curl-etc/" rel="nofollow">https://developer.paypal.com/docs/classic/express-checkout/ht_ec-singleAuthPayment-curl-etc/</a></p>
  
  <p>Thanks in advance :) .</p>