title: How can I use the amount variable outside this function please can any one help me
body: <p>Please can anyone tell me how can I get the amount variable or its data which I am fetching from <code>req.body</code> outside of the this function?</p>
  <pre><code>app.post(&quot;/pay&quot;, (req, res) =&gt; {
    console.log(req.body); 
    const { amount , description , name } = req.body;    //this is that amount variable
    const create_payment_json = {
      intent: &quot;sale&quot;,
      payer: {
        payment_method: &quot;paypal&quot;,
      },
      redirect_urls: {
        return_url: &quot;http://localhost:3000/success&quot;,
        cancel_url: &quot;http://localhost:3000/cancel&quot;,
      },
      transactions: [
        {
          item_list: {
            items: [
              {
                name: name,
                sku: &quot;001&quot;,
                price: amount,
                currency: &quot;USD&quot;,
                quantity: 1,
              },
            ],
          },
          amount: {
            currency: &quot;USD&quot;,
            total: amount,
          },
          description: description,
        },
      ],
    };
  
    paypal.payment.create(create_payment_json, function (error, payment) {
      if (error) {
        throw error;
      } else {
        for (let i = 0; i &lt; payment.links.length; i++) {
          if (payment.links[i].rel === &quot;approval_url&quot;) {
            res.redirect(payment.links[i].href);
          }
        }
      }
    });
  });
  
  app.get(&quot;/success&quot;, (req, res) =&gt; {
    const payerId = req.query.PayerID;
    const paymentId = req.query.paymentId;
  
    const execute_payment_json = {
      payer_id: payerId,
      transactions: [
        {
          amount: {
            currency: &quot;USD&quot;,
            total: amount,    // I want it here also
          },
        },
      ],
    };
  
    paypal.payment.execute(
      paymentId,
      execute_payment_json,
      function (error, payment) {
        if (error) {
          console.log(error.response);
          ;
        } else {
          console.log(JSON.stringify(payment));
          res.send(&quot;Success&quot;);
        }
      }
    );
  });
  </code></pre>