title: call sessionId javascript function into another function
body: <p>i have a html page for Checkout Integration of mastercard &quot;Hosted Checkout Integration&quot; , but i have a Problem with sessionId
  how can i call result of javascript function into another javascript function
  i want call from this function &quot;sessionId&quot;</p>
  <pre><code>function getSessionID(){
                  axios({
                    method: 'POST',
                    url: 'https://banquemisr.gateway.mastercard.com/api/rest/version/61/merchant/xxxxx_xxx/session',
                    data: JSON.stringify({
                      apiOperation: 'CREATE_CHECKOUT_SESSION',
                      interaction: {
                          operation : &quot;PURCHASE&quot;,
                      },
                      order : {
                          amount: function() {
                          //Dynamic calculation of amount
                          return realAmount + commission;
                      },
                          currency: &quot;EGP&quot;,
                          description : &quot;Ordered goods&quot;,
                          id: idValue,
                      },
                    }),
  
                  auth: {
                      username: &quot;merchant.xxxx_xxx&quot;,
                      password: &quot;xxxxxxxxxxxxxxxxxxxxxxxxx&quot;
                  },
                  crossOrigin: null,
                  }).then(function (response) {
                      console.log('Authenticated');
                      localStorage.setItem('sessionId',response.data.session.id)
                      
                   });
  </code></pre>
  <p>into this function</p>
  <pre><code> Checkout.configure({
              session: {
                  id : sessionId;
              },
              interaction: {
                operation : &quot;PURCHASE&quot;,
                  merchant: {
                      name: &quot;xxxxx_xxx&quot;,
                      address: {
                          line1: clientAddress1,
                          line2: clientAddress2
                      }
                  }
              }
          });
  </code></pre>
  <p>i try to get it by</p>
  <pre><code>return getSessionID()
  </code></pre>
  <p>but not words , any Thoughts</p>
  <p>my full code page :</p>
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
   &lt;head&gt; 
       &lt;title&gt;xxxxx&lt;/title&gt;    
       &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css&quot; integrity=&quot;sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy&quot; crossorigin=&quot;anonymous&quot;&gt;
       &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css&quot;&gt;
    &lt;script src=&quot;https://banquemisr.gateway.mastercard.com/checkout/version/61/checkout.js&quot; data-error=&quot;errorCallback&quot; data-cancel=&quot;cancelCallback&quot;&gt;&lt;/script&gt; 
          &lt;script src=&quot;https://unpkg.com/axios/dist/axios.min.js&quot;&gt;&lt;/script&gt;
  
    &lt;script type=&quot;text/javascript&quot;&gt;
    /* ############################# Config */
  
  
  
  function session_id() {
      return /SESS\w*ID=([^;]+)/i.test(document.cookie) ? RegExp.$1 : false;
  }
  
      //Type Your commission that will be added to the real amount
      let commission = 0;
  
      //Start amount
      let realAmount = 0;
  
      //currency
      let currency = &quot;EGP&quot;;
  
      //Goods Item name and details
      let itemDescription = &quot;xxxxx&quot;;
  
      //Store Name
      let clietnName = document.title;//&quot;Store Name&quot;;
      //Store address 1 &amp; 2
      let clientAddress1 = &quot;200 Sample St&quot;;
      let clientAddress2 = &quot;1234 Example Townt&quot;;
  
      //cancel page redirect
      let cancelURL = 'https://google.com';
  
  
      //payment id    
      let idValue = Math.random().toString(36).substr(2, 9);
      let str = &quot;merchant.xxxxx:xxxxx&quot;;
      let enc = window.btoa(str);
      console.log(enc);
      getSessionID();
    /* ########################### End config */
              function errorCallback(error) {
                    console.log(JSON.stringify(error));
                    alert(JSON.stringify(error));
              }
              function cancelCallback() {
                    console.log('Payment cancelled');
                    window.href = cancelURL;
              }
              
              Checkout.configure({
                  session: {
                      id : return getSessionID();
                  },
                  interaction: {
                    operation : &quot;PURCHASE&quot;,
                      merchant: {
                          name: &quot;xxxxx&quot;,
                          address: {
                              line1: clientAddress1,
                              line2: clientAddress2
                          }
                      }
                  }
              });
  async function getSessionID() {
      const response = await axios({
      method: &quot;POST&quot;,
      url: &quot;https://banquemisr.gateway.mastercard.com/api/rest/version/61/merchant/xxxxx/session&quot;,
      data: JSON.stringify({
        apiOperation: &quot;CREATE_CHECKOUT_SESSION&quot;,
        interaction: {
          operation: &quot;PURCHASE&quot;,
        },
        order: {
          amount: function () {
            //Dynamic calculation of amount
            return realAmount + commission;
          },
          currency: &quot;EGP&quot;,
          description: &quot;Ordered goods&quot;,
          id: idValue,
        },
      }),
  
      auth: {
        username: &quot;merchant.xxxxx&quot;,
        password: &quot;xxxxx&quot;,
      },
      crossOrigin: null,
    });
  
    return response.data.session.id;
  }
  
  async function foo(){
      const sessionID = await getSessionID();
  }
              function makePayment()
              {
                  realAmount = parseFloat(document.getElementById('amount').value);
                  
                  document.getElementById('amount').disabled = true;
                  document.getElementById('pay').disabled = true;
                  document.getElementById('cancel').disabled = true;
                  Checkout.showPaymentPage();
                 return false;
              }
          &lt;/script&gt; 
   &lt;/head&gt; 
   &lt;style&gt;
      
      .card-header .icons .fa-cc-discover{
          color: #027878;
      }
      .card-header .icons .fa-cc-amex{
          color: #ef6903;
      }
      label.labelamount{
          color: #ef6903;
      }
      .card-body label{
          font-size: 14px;
      }
      .submitpay{
          color: #fff;
          background-color: #ef6903;
          width: 83%;
      margin: auto;
      border: 2px solid #ef6903;
    border-radius: 5px;
      }
      .icons{
          text-align: right;
      }
      .inputamout{
          width: 85%;
      }
      body{
          background:  url(&quot;http://www.rimallytravel.com/wp-content/themes/altair/bg.jpg&quot;) no-repeat fixed center;
  
      }
      .imgbq{
          margin: auto;
      }
      .imglogo{
          width: 100%;
      }
      &lt;/style&gt;
  &lt;body class=&quot;bg-danger pt-5&quot;&gt;
      &lt;div class=&quot;container&quot;&gt;
         
              &lt;div class=&quot;row&quot;&gt;
            
                      &lt;div class=&quot;col-md-4 offset-md-4 col-10 offset-1 pl-0 pr-0&quot;&gt;
                          &lt;div class=&quot;card1&quot;&gt;
                                  &lt;img class=&quot;imglogo&quot; src=&quot;http://www.rimallytravel.com/wp-content/uploads/2017/10/ww.png&quot; alt=&quot;logo&quot;  &gt;
                                  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
               &lt;/div&gt;
  
  
  
  
        &lt;div class=&quot;row&quot;&gt;
            
            &lt;div class=&quot;col-md-4 offset-md-4 col-10 offset-1 pl-0 pr-0&quot;&gt;
                &lt;div class=&quot;card&quot;&gt;
                    
                      &lt;div class=&quot;card-header&quot;&gt;
                        &lt;div class=&quot;row&quot;&gt;
                            &lt;div class=&quot;col-md-6 col-12 pt-2&quot;&gt;
                                &lt;h6 class=&quot;m-0&quot;&gt;&lt;strong&gt;Payment Details&lt;/strong&gt;&lt;/h6&gt;
                            &lt;/div&gt;
                            &lt;div class=&quot;col-md-6 col-12 icons&quot;&gt;
                               &lt;img class=&quot;imgcredit&quot; src=&quot;http://www.rimallytravel.com/wp-content/uploads/2017/10/Credit-Card-Visa-And-Master-Card-PNG-File-300x65.png&quot; alt=&quot;banq&quot; width=&quot;170&quot; &gt;
                                
                            &lt;/div&gt;
                        &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;card-body&quot;&gt;
                        &lt;form onsubmit=&quot;return makePayment()&quot;&gt;
                                  &lt;div class=&quot;col-md-12 col-12&quot;&gt;
                                      &lt;div class=&quot;form-group&quot;&gt;
                                        &lt;label class=&quot;labelamount&quot; for=&quot;exampleInputamount&quot;&gt;&lt;strong&gt;Amount&lt;/strong&gt;&lt;/label&gt;
                                      &lt;/br&gt;
                                        &lt;input class=&quot;inputamout&quot; type=&quot;number&quot; min=&quot;1&quot; step=&quot;0.01&quot; id=&quot;amount&quot; style=&quot;text-align: center;&quot; required&gt; EGP
                                    &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                             
                              &lt;input class=&quot;submitpay&quot; type=&quot;submit&quot; id=&quot;pay&quot; value=&quot;Pay Now&quot;&gt;
           &lt;br /&gt;
           &lt;img class=&quot;imgbq&quot; src=&quot;http://www.rimallytravel.com/wp-content/themes/altair/bq.png&quot; alt=&quot;banq&quot; width=&quot;125&quot; &gt;
           &lt;br /&gt;
           &lt;input type=&quot;hidden&quot; id=&quot;cancel&quot; onclick=&quot;cancelCallback()&quot; value=&quot;Cancel&quot;  &gt;
                        &lt;/form&gt;
                      &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;    
    &lt;script&gt;
      document.getElementById('amount').value = realAmount;
  &lt;/script&gt;   
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>