· 5 years ago · Mar 26, 2020, 03:54 PM
1<?php
2
3/**
4 * Payment API Settings
5 */
6$terminalID = 'anaqeed';
7$password = 'anaqeed@123';
8$secretKey = '77995d3e6232b329dc9bc3cbe6b7685d11c742dca5dbaa8ede0fbf052dc307ef';
9
10
11// Generate trackID
12function generateRandomString ( $length = 8 ) {
13 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
14 $charactersLength = strlen($characters);
15 $randomString = '';
16 for ( $i = 0; $i < $length; $i++ ) {
17 $randomString .= $characters[rand(0, $charactersLength - 1)];
18 }
19 return 'trck'.$randomString;
20}
21$trackID = generateRandomString(12);
22
23
24// Item Details
25$customerIP = '218.212.106.238';
26$customerEmail = 'nojoud.khaled@hotmail.com';
27$currency = 'SAR';
28$country = 'SA'; // Country Code
29$amount = '200.00';
30
31
32// trackid | Terminalid | password | secret_key | amount | currency_code
33$token = "$trackID|$terminalID|$password|$secretKey|$amount|$currency";
34$hashToken = hash('sha256', $token);
35
36
37
38/**
39 * Sending Payment request
40 */
41$fields = array(
42 'trackid' => $trackID,
43 'terminalId' => $terminalID,
44 'customerEmail' => $customerEmail,
45 'action' => '1', // action is always 1
46 'merchantIp' => $customerIP,
47 'password' => $password,
48 'currency' => $currency,
49 'country' => $country,
50 'amount' => $amount,
51 'requestHash' => $hashToken
52);
53$data = json_encode($fields);
54$error = '';
55
56$url = "https://payments-dev.urway-tech.com/URWAYPGService/transaction/jsonProcess/JSONrequest";
57$ch = curl_init();
58curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
59curl_setopt($ch, CURLOPT_URL, $url);
60curl_setopt($ch, CURLOPT_HTTPHEADER, array(
61 'Content-Type: application/json',
62 'Content-Length: ' . strlen($data)
63));
64curl_setopt($ch, CURLOPT_POST, 1);
65curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
66curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
67curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
68
69$responseData = curl_exec($ch);
70if ( curl_errno( $ch ) ) {
71 $error = curl_error($ch);
72}
73curl_close($ch);
74$responseData = json_decode($responseData, TRUE);
75
76if ( isset( $responseData['payid'] ) && ! empty( $responseData['payid'] ) ) {
77 $url = $responseData['targetUrl'] . '?paymentid=' . $responseData['payid'];
78 echo '
79 <form name="pymForm" method="POST" action="'. $url .'">
80 <h1>Transaction is processing.....</h1>
81 </form>
82 <script>document.pymForm.submit();</script>
83 ';
84}
85else {
86 // echo $error;
87 echo "<h1>Something went wrong!</h1>";
88}