Quick Web
Search…
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 එක බාහිර පාර්ශවයන්ට නිරාවරණය නොවීම නිසා අතිරේක වශයෙන් ආරක්ෂාවක් සැලසේ.
NOTE the post request used to confirm the payment has an empty body and contains 2 url parameters:
  • The request ID or CSRF token extracted from the GET request.
  • The merchants AUTH-TOKEN that will be supplied by Paycorp
අවධානයට : Payment එක තහවුරු කිරීම සඳහා භාවිතා කරන POST request එක URL parameter 2 කින් සහ හිස් Body එකකින් සමන්විත වේ. Request ID හෝ CSRF token එක GET request එකෙන් උපුටා ගනු ලැබේ.පරිශීලකයාගේ AUTH-TOKEN එක Paycorp විසින් සපයනු ලැබේ.
KEEP YOUR AUTH-TOKEN SECURE and NEVER include your AUTH-TOKEN in any HTML page or clear text config file. ඔබේ AUTHTOKEN සුරැකි තබන්න. කිසිම පිටුවක හෝ සැකසුම් ගොනුවක් තුළ ඔබේ AUTH-TOKEN ඇතුළත් කරන්න එපා
Node.js
PHP
Java
.Net
1
function processResponse(req, res, next) {
2
3
// This will vary depending on your bank
4
// and may also change so please check any emails you
5
// receive from Paycorp that contain setup instructions
6
const BASE_URL = 'https://sampath.paycorp.lk/webinterface/qw/confirm';
7
8
// This is the your private auth token. It must
9
// never be used in the browser, only on your secure server
10
const AUTH_TOKEN = '7c0c1c98-0f1e-4da9-9e93-1d4939d9282f';
11
12
// First submit the payment complete request, NOTE: empty body,
13
// only needs URL params
14
axios.post(`${BASE_URL}?csrfToken=${reqId}&authToken=${AUTH_TOKEN}`, {})
15
.then(function (response) {
16
17
// The response data will be in x-www-form-urlencode format
18
// Convert x-www-form-urlencode to simple object
19
const respData = querystring.parse(response.data);
20
21
// and add req ID if you wish
22
respData.reqid = req.query.reqid;
23
24
// Show the user a receipt page
25
res.render('payment-response', {
26
title: 'Payment Response',
27
data: respData
28
});
29
30
// FURTHER PROCESSING OF THE PAYMENT.........
31
32
})
33
.catch(function (error) {
34
console.log('ERROR:', error);
35
next(createError(error.response.status, error.response.statusText));
36
});
37
}
Copied!
1
// PRIVATE Merchant Authtoken
2
$base_url = "https://sampath.paycorp.lk/webinterface/qw/confirm";
3
$auth_Token = "7c0c1c98-0f1e-4da9-9e93-1d4939d9282f";
4
5
// Construct the payment confirmation request
6
// Set CURLOPT_RETURNTRANSFER so that the content is returned as a variable.
7
// Set CURLOPT_FOLLOWLOCATION to true to follow redirects.
8
$ch = curl_init();
9
curl_setopt($ch, CURLOPT_URL, $base_url.'?csrfToken='.$csrfToken.'&authToken='.$auth_Token);
10
curl_setopt($ch, CURLOPT_POST, 1);
11
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
12
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
13
14
//Execute the request, Get the Errors & close the cURL handle
15
$response = curl_exec($ch);
16
$errors = curl_error($ch);
17
curl_close($ch);
18
19
// The response data will be in x-www-form-urlencode format
20
// Explode String data using "&" and "=".
21
$params = explode('&', $response);
22
$results = [];
23
24
foreach ($params as $element) {
25
list($key, $value) = explode('=', $element);
26
$results[$key] = $value;
27
}
28
29
// Display payment response
30
echo "<center>&#9886;<b>------Payment Complete Response------</b>&#9887;</br></br>";
31
echo "&#9755;&ensp;"."Request ID : ".$csrfToken."</br></br>";
32
echo "&#9755;&ensp;"."Client Ref : ".$results['clientRef']."</br></br>";
33
echo "&#9755;&ensp;"."Comment : ".$results['comment']."</br></br></center>";
34
echo "&#9755;&ensp;"."Card Type : ".$results['cardType']."</br></br>";
35
echo "&#9755;&ensp;"."Card Holder Name : ".$results['cardHolderName']."</br></br>";
36
echo "&#9755;&ensp;"."Card Number : ".$results['cardNumber']."</br></br>";
37
echo "&#9755;&ensp;"."Card Expiry : ".$results['cardExpiry']."</br></br>";
38
echo "&#9755;&ensp;"."Payment Amount : ".$results['paymentAmount']."</br></br>";
39
echo "&#9755;&ensp;"."Currency : ".$results['currency']."</br></br>";
40
echo "&#9755;&ensp;"."Transaction ref number : ".$results['txnReference']."</br></br>";
41
echo "&#9755;&ensp;"."Response Code : ".$results['responseCode']."</br></br>";
42
echo "&#9755;&ensp;"."Response Text : ".$results['responseText']."</br></br>";
43
44
// FURTHER PROCESSING OF THE PAYMENT.......
45
Copied!
1
String authToken = "7c0c1c98-0f1e-4da9-9e93-1d4939d9282f";
2
String baseUrl = "https://sampath.paycorp.lk/webinterface/qw/confirm";
3
String confirmUrl = baseUrl + "?csrfToken=" + reqId + "&authToken=" + authToken;
4
// Construct payment confirmation request
5
URL url = new URL(confirmUrl);
6
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
7
httpCon.setDoOutput(true);
8
httpCon.setRequestMethod("POST");
9
10
// Post the request and read the response
11
BufferedReader in = new BufferedReader(new InputStreamReader(httpCon.getInputStream()));
12
String inputLine = in.readLine();
13
in.close();
14
15
// The response data will be in x-www-form-urlencode format
16
String[] responseArray = inputLine.split("&");
17
Map<String, String> respMap = new HashMap<>();
18
for (String keyValuePair: responseArray) {
19
String[] split = keyValuePair.split("=");
20
respMap.put(split[0], split[1]);
21
}
22
23
request.setAttribute("reqid", reqId);
24
request.setAttribute("clientRef", respMap.get("clientRef"));
25
request.setAttribute("comment", respMap.get("comment"));
26
request.setAttribute("cardType" , respMap.get("cardType"));
27
request.setAttribute("cardHolderName", respMap.get("cardHolderName"));
28
request.setAttribute("cardNumber", respMap.get("cardNumber"));
29
request.setAttribute("cardExpiry", respMap.get("cardExpiry"));
30
request.setAttribute("paymentAmount", respMap.get("paymentAmount"));
31
request.setAttribute("currency" , respMap.get("currency"));
32
request.setAttribute("txnReference" , respMap.get("txnReference"));
33
request.setAttribute("responseCode", respMap.get("responseCode"));
34
request.setAttribute("responseText" , respMap.get("responseText"));
35
36
// FURTHER PROCESSING OF THE PAYMENT......
37
38
RequestDispatcher rd = request.getRequestDispatcher("/PaymentResponse.jsp");
39
rd.forward(request, response);
40
Copied!
1
var base_url = "https://sampath.paycorp.lk/webinterface/qw/confirm";
2
var auth_Token = "7c0c1c98-0f1e-4da9-9e93-1d4939d9282f";
3
var myrequest = (HttpWebRequest)WebRequest.Create(base_url + "?csrfToken=" + csrfToken + "&authToken=" + auth_Token);
4
myrequest.Method = "POST";
5
myrequest.ContentType = "application/x-www-form-urlencoded";
6
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
7
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
8
var myresponse = (HttpWebResponse)myrequest.GetResponse();
9
10
// Get the stream associated with the response.
11
Stream receiveStream = myresponse.GetResponseStream();
12
13
// Pipes the stream to a higher level stream reader with the required encoding format.
14
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
15
string readContents = readStream.ReadToEnd();
16
string[] lines = readContents.Split('&');
17
18
IDictionary<string, string> respMap = new Dictionary<string, string>();
19
foreach (string keyValuePair in lines) {
20
string[] split = keyValuePair.Split('=');
21
respMap.Add(split[0], split[1]);
22
}
23
24
clientref = respMap["clientRef"];
25
response_code = respMap["responseCode"];
26
amount = respMap["paymentAmount"];
27
card_expiry = respMap["cardExpiry"];
28
cardholdername = respMap["cardHolderName"];
29
txnreference = respMap["txnReference"];
30
response_text = respMap["responseText"];
31
comment = respMap["comment"];
32
card_Type = respMap["cardType"];
33
currency = respMap["currency"];
34
card_num = respMap["cardNumber"];
35
token = respMap["token"];
36
token_res_txt = respMap["tokenResponseText"];
37
Copied!

Copy link