4. Confirm the payment

Users of your website will likely have poor connectivity so to avoid any lost payments you must confirm all payments using an HTTP POST request sent from your server. This also provides added security because your private AUTH_TOKEN provided by Paycorp is never exposed in a public web page.

ඔබගේ Web Site එක හරහා ගණුදෙණු කරන පරිශීලකයින්ගේ ජාල සම්බන්දතා ගැටලු හේතුවෙන් ඔබේ ගණුදෙණු සාර්තක නොවිය හැක.මේ නිසා මෙය වලක්වා ගැනීමට සියලුම ගණුදෙණු තහවුරු කිරීමට HTTP POST Request එකක් භාවිතා කල යුතුය. මෙහිදී Paycorp මගින් සපයන ඔබේ පෞද්ගලික AUTH_TOKEN එක බාහිර පාර්ශවයන්ට නිරාවරණය නොවීම නිසා අතිරේක වශයෙන් ආරක්ෂාවක් සැලසේ.

KEEP YOUR AUTH-TOKEN SECURE and NEVER include your AUTH-TOKEN in any HTML page or clear text config file. ඔබේ AUTHTOKEN සුරැකි තබන්න. කිසිම පිටුවක හෝ සැකසුම් ගොනුවක් තුළ ඔබේ AUTH-TOKEN ඇතුළත් කරන්න එපා

function processResponse(req, res, next) {

  // This will vary depending on your bank
  // and may also change so please check any emails you
  // receive from Paycorp that contain setup instructions
  const BASE_URL = 'https://sampath.paycorp.lk/webinterface/qw/confirm';

  // This is the your private auth token. It must
  // never be used in the browser, only on your secure server
  const AUTH_TOKEN = '7c0c1c98-0f1e-4da9-9e93-1d4939d9282f'; 

  // First submit the payment complete request, NOTE: empty body, 
  // only needs URL params
  axios.post(`${BASE_URL}?csrfToken=${reqId}&authToken=${AUTH_TOKEN}`, {})
    .then(function (response) {

      // The response data will be in x-www-form-urlencode format
      // Convert x-www-form-urlencode to simple object
      const respData = querystring.parse(response.data);
      
      // and add req ID if you wish
      respData.reqid = req.query.reqid;

      // Show the user a receipt page
      res.render('payment-response', {
        title:  'Payment Response',
        data: respData 
      });

      // FURTHER PROCESSING OF THE PAYMENT.........
      
    })
    .catch(function (error) {
      console.log('ERROR:', error);
      next(createError(error.response.status, error.response.statusText));
    });  
}

Last updated