· 6 years ago · Dec 20, 2019, 01:38 PM
1<?php
2$secretKey = 'SKHTAyCJnf6a94Wz';
3$path = 'https://paygatedirect.com/v2/';
4$requestType = 'webpay'; // possible values: charge, refund, pay...
5$requestUrl = $path . $requestType;
6// array for parametres
7$bodyRequestArray = array(
8 'currency' => "USD",
9 'serviceId' => "736",
10 //'cardNumber' => "4777777777777777", // Without spaces, for example, 4111111111111111
11 //'expMonth' => "04", // 2 digits, for example, '04'
12 //'expYear' => "21", // 2 digits, for example, '20'
13 //'cardHolder' => "TEST",
14 //'cvc' => "123",
15 'orderId' => "103",
16 'amount' => "3500.45",
17 'description' => "DESCRIPTION"
18);
19
20$body = http_build_query($bodyRequestArray);
21
22echo '<pre>';
23print_r($body);
24echo '</pre>';
25
26$signature = getSignature($body, $secretKey);
27
28$ch = curl_init();
29curl_setopt($ch, CURLOPT_URL, $requestUrl);
30curl_setopt($ch, CURLOPT_POST, 1);
31curl_setopt($ch, CURLOPT_POSTFIELDS, $body); //Post Fields
32curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
33$headers = array(
34 'signature:'.$signature
35);
36curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
37$server_output = curl_exec($ch);
38curl_close ($ch);
39function getSignature($body, $secretKey){
40 // create signature
41 $hash = hash_hmac('sha256', $body, $secretKey, false);
42 return base64_encode($hash);
43}
44
45?>
46<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
47<html>
48 <head>
49 <title></title>
50 <meta name="" content="">
51 </head>
52 <body>
53 <?php
54 echo $server_output;
55 ?>
56 </body>
57</html>