Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Payment API Settings
- */
- $terminalID = 'anaqeed';
- $password = 'anaqeed@123';
- $secretKey = '77995d3e6232b329dc9bc3cbe6b7685d11c742dca5dbaa8ede0fbf052dc307ef';
- // Generate trackID
- function generateRandomString ( $length = 8 ) {
- $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $charactersLength = strlen($characters);
- $randomString = '';
- for ( $i = 0; $i < $length; $i++ ) {
- $randomString .= $characters[rand(0, $charactersLength - 1)];
- }
- return 'trck'.$randomString;
- }
- $trackID = generateRandomString(12);
- // Item Details
- $customerIP = '218.212.106.238';
- $customerEmail = 'nojoud.khaled@hotmail.com';
- $currency = 'SAR';
- $country = 'SA'; // Country Code
- $amount = '200.00';
- // trackid | Terminalid | password | secret_key | amount | currency_code
- $token = "$trackID|$terminalID|$password|$secretKey|$amount|$currency";
- $hashToken = hash('sha256', $token);
- /**
- * Sending Payment request
- */
- $fields = array(
- 'trackid' => $trackID,
- 'terminalId' => $terminalID,
- 'customerEmail' => $customerEmail,
- 'action' => '1', // action is always 1
- 'merchantIp' => $customerIP,
- 'password' => $password,
- 'currency' => $currency,
- 'country' => $country,
- 'amount' => $amount,
- 'requestHash' => $hashToken
- );
- $data = json_encode($fields);
- $error = '';
- $url = "https://payments-dev.urway-tech.com/URWAYPGService/transaction/jsonProcess/JSONrequest";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($data)
- ));
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $responseData = curl_exec($ch);
- if ( curl_errno( $ch ) ) {
- $error = curl_error($ch);
- }
- curl_close($ch);
- $responseData = json_decode($responseData, TRUE);
- if ( isset( $responseData['payid'] ) && ! empty( $responseData['payid'] ) ) {
- $url = $responseData['targetUrl'] . '?paymentid=' . $responseData['payid'];
- echo '
- <form name="pymForm" method="POST" action="'. $url .'">
- <h1>Transaction is processing.....</h1>
- </form>
- <script>document.pymForm.submit();</script>
- ';
- }
- else {
- // echo $error;
- echo "<h1>Something went wrong!</h1>";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement