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