· 6 years ago · Dec 20, 2019, 12:32 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", // digits and dot ('.'), for example, '3500.45'
17 'description' => "DESCRIPTION"
18);
19
20$body = http_build_query($bodyRequestArray);
21$signature = getSignature($body, $secretKey);
22
23$ch = curl_init();
24curl_setopt($ch, CURLOPT_URL, $requestUrl);
25curl_setopt($ch, CURLOPT_POST, 1);
26curl_setopt($ch, CURLOPT_POSTFIELDS, $body); //Post Fields
27curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
28$headers = array(
29 'signature:'.$signature
30);
31curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
32$server_output = curl_exec($ch);
33curl_close ($ch);
34function getSignature($body, $secretKey){
35 // create signature
36 $hash = hash_hmac('sha256', $body, $secretKey, false);
37 return base64_encode($hash);
38}
39
40?>
41<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
42<html>
43 <head>
44 <title></title>
45 <meta name="" content="">
46 </head>
47 <body>
48 <?php
49 echo $server_output;
50 ?>
51 </body>
52</html>