Skip to content

Commit c3ed42a

Browse files
committed
Made invocation through function
1 parent fdb7fa4 commit c3ed42a

File tree

1 file changed

+30
-64
lines changed

1 file changed

+30
-64
lines changed

processcheckout.php

+30-64
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,36 @@
11
<?php
2-
3-
require_once 'dotenv.php';
4-
// echo $_ENV['CALLBACK_URL'];
5-
6-
$MERCHANT_ID = $_ENV['PAYBILL_NO'];
7-
$MERCHANT_TRANSACTION_ID = generateRandomString();
8-
9-
$TIMESTAMP = date("Y-m-d H:i:s", time());
10-
$PASSWORD_ENCRYPT = base64_encode(hash("sha256", $MERCHANT_ID.$_ENV['PASSKEY'].$TIMESTAMP));
11-
$PASSWORD = strtoupper($PASSWORD_ENCRYPT);
12-
13-
$body = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
14-
xmlns:tns="tns:ns">
15-
<soapenv:Header>
16-
<tns:CheckOutHeader>
17-
<MERCHANT_ID>'.$MERCHANT_ID.'</MERCHANT_ID>
18-
<PASSWORD>ZTcxY2M3M2U1ZDM1ZGEyZTRiN2UyNGUyNDk0NGQwOTVkMzgzOTNmN2UzOTEzN2RlNDE1N2M0ZjViNDIzMWU0Yw==</PASSWORD>
19-
<TIMESTAMP>'.$TIMESTAMP.'</TIMESTAMP>
20-
</tns:CheckOutHeader>
21-
</soapenv:Header>
22-
<soapenv:Body>
23-
<tns:transactionConfirmRequest>
24-
<!--Optional:-->
25-
<TRX_ID>'.generateRandomString().'</TRX_ID>
26-
<!--Optional:-->
27-
<MERCHANT_TRANSACTION_ID>?</MERCHANT_TRANSACTION_ID>
28-
</tns:transactionConfirmRequest>
29-
</soapenv:Body>
30-
</soapenv:Envelope>'; /// Your SOAP XML needs to be in this variable
31-
32-
try {
33-
$ch = curl_init();
34-
35-
curl_setopt($ch, CURLOPT_URL, $_ENV['ENDPOINT']);
36-
curl_setopt($ch, CURLOPT_HEADER, 0);
37-
curl_setopt($ch, CURLOPT_VERBOSE, '0');
38-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
39-
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
40-
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '0');
41-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '0');
42-
43-
$output = curl_exec($ch);
44-
curl_close($ch);
45-
46-
// Check if any error occured
47-
if(curl_errno($ch))
48-
{
49-
echo 'Error no : '.curl_errno($ch).' Curl error: ' . curl_error($ch);
50-
}
51-
print_r($output);
52-
}
53-
catch (SoapFault $fault)
2+
function processcheckout($MERCHANT_TRANSACTION_ID, $ENDPOINT,$PASSWORD,$TIMESTAMP)
543
{
55-
echo $fault;
4+
$body = '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="tns:ns" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soapenv:Header><tns:CheckOutHeader><MERCHANT_ID>898998</MERCHANT_ID><PASSWORD>'.$PASSWORD.'</PASSWORD><TIMESTAMP>'.$TIMESTAMP.'</TIMESTAMP></tns:CheckOutHeader></soapenv:Header><soapenv:Body><tns:transactionConfirmRequest><TRX_ID>?</TRX_ID><MERCHANT_TRANSACTION_ID>'.$MERCHANT_TRANSACTION_ID.'</MERCHANT_TRANSACTION_ID></tns:transactionConfirmRequest></soapenv:Body></soapenv:Envelope>';
5+
// Your SOAP XML needs to be in this variable
6+
try {
7+
8+
$ch = curl_init();
9+
curl_setopt($ch, CURLOPT_URL, $ENDPOINT);
10+
curl_setopt($ch, CURLOPT_HEADER, 0);
11+
12+
curl_setopt($ch, CURLOPT_VERBOSE, '0');
13+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
14+
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
15+
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
16+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '0');
17+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '0');
18+
19+
$output = curl_exec($ch);
20+
curl_close($ch);
21+
22+
// Check if any error occured
23+
if(curl_errno($ch))
24+
{
25+
echo 'Error no : '.curl_errno($ch).' Curl error: ' . curl_error($ch);
26+
}
27+
28+
//ADD Databbase CRUD features here;
29+
30+
} catch (SoapFault $fault) {
31+
echo $fault;
32+
}
5633
}
5734

58-
function generateRandomString()
59-
{
60-
$length = 10;
61-
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
62-
$charactersLength = strlen($characters);
63-
$randomString = '';
64-
for ($i = 0; $i < $length; $i++) {
65-
$randomString .= $characters[rand(0, $charactersLength - 1)];
66-
}
67-
return $randomString;
68-
}
6935

7036
?>

0 commit comments

Comments
 (0)