· 5 years ago · Jun 09, 2020, 06:46 PM
1################### https://www.dotpay.pl/developer/doc/api_payment/ ######################################################################
2#
3# Exemplary function (PHP) generating the correct payment redirection (POST / GET) to Dotpay payment api with parametr 'chk' (checksum).
4# You enter the payment data in the parameter: $ParametersArray.
5#
6#
7# Dotpay Sp. z o.o.
8# Tech Customer Service: tech@dotpay.pl
9# Date: 2020-02-11
10#
11##############################################################################################################################################
12
13
14/** --------- BASE CONFIG --------- **/
15
16// Your Dotpay ID shop (6 digits)
17 $DotpayId = "764458";
18
19// PIN for Your Dotpay ID (copy this from your dotpay panel carefully, without space)
20 $DotpayPin = "xpAbWQw47Vpg0vsbtrpuHrqzfN3JRJEc";
21
22// Dotpay Environment, available: "test" or "production"
23 $Environment = "test";
24
25//Redirection method: POST or GET ; recommended method is "POST"
26 $RedirectionMethod = "POST";
27
28/** --------- end config --------- **/
29
30
31
32// ** ----------------------- SAMPLE DATA ------------------------- **/
33
34/* ## SAMPLE PAYMENT DATA IN ## */
35 // Note! You can use more parameters if You need
36 // You must give at least: 'amount', 'currency', 'description' (and of course ID and PIN in the configuration of this script)
37 // see more: https://www.dotpay.pl/developer/doc/api_payment/en/index.html#tabela-1-podstawowe-parametry-przesylane-do-serwisu-dotpay
38 // and: https://www.dotpay.pl/developer/doc/api_payment/en/index.html#tabela-2-dodatkowe-parametry-przesylane-do-serwisu-dotpay
39
40// ------
41$ParametersArray = array(
42
43 "api_version" => "dev",
44 "amount" => $cena,
45 "currency" => "PLN",
46 "description" => $_GET['purchase'],
47 "url" => $link.'gotowe.php?c='.$_GET['purchase'].'&st='.$sc,
48 "type" => "0",
49 "buttontext" => "Wróć aby odebrać produkt",
50 "urlc" => "https://www.example.com/urlc_receiver.php",
51 "control" => "M1231MzaUdLQWR3",
52 "firstname" => $pr['name'],
53 "lastname" => $pr['secondname'],
54 "email" => $pr['email'],
55 "country" => "POL",
56 "ignore_last_payment_channel" => 1
57);
58
59// ** ----------------------- SAMPLE DATA end ------------------------- **/
60
61
62
63## CALCULATE CHECKSUM - CHK
64
65function GenerateChk($DotpayId, $DotpayPin, $ParametersArray)
66
67{
68 $ParametersArray['id'] = $DotpayId;
69
70 $CHkInputString = $DotpayPin.
71 (isset($ParametersArray['api_version']) ? $ParametersArray['api_version'] : null).
72 (isset($ParametersArray['lang']) ? $ParametersArray['lang'] : null).
73 (isset($ParametersArray['id']) ? $ParametersArray['id'] : null).
74 (isset($ParametersArray['amount']) ? $ParametersArray['amount'] : null).
75 (isset($ParametersArray['currency']) ? $ParametersArray['currency'] : null).
76 (isset($ParametersArray['description']) ? $ParametersArray['description'] : null).
77 (isset($ParametersArray['control']) ? $ParametersArray['control'] : null).
78 (isset($ParametersArray['channel']) ? $ParametersArray['channel'] : null).
79 (isset($ParametersArray['url']) ? $ParametersArray['url'] : null).
80 (isset($ParametersArray['type']) ? $ParametersArray['type'] : null).
81 (isset($ParametersArray['buttontext']) ? $ParametersArray['buttontext'] : null).
82 (isset($ParametersArray['urlc']) ? $ParametersArray['urlc'] : null).
83 (isset($ParametersArray['firstname']) ? $ParametersArray['firstname'] : null).
84 (isset($ParametersArray['lastname']) ? $ParametersArray['lastname'] : null).
85 (isset($ParametersArray['email']) ? $ParametersArray['email'] : null).
86 (isset($ParametersArray['country']) ? $ParametersArray['country'] : null).
87 (isset($ParametersArray['ignore_last_payment_channel']) ? $ParametersArray['ignore_last_payment_channel'] : null);
88
89 return hash('sha256',$CHkInputString);
90}
91
92
93
94## GENERATE FORM TO DOTPAY
95
96function GenerateChkDotpayRedirection($DotpayId, $DotpayPin, $Environment, $RedirectionMethod, $ParametersArray)
97{
98 $ChkValue = GenerateChk($DotpayId, $DotpayPin, $ParametersArray);
99
100 if ($Environment == 'production') {
101 $EnvironmentAddress = 'https://ssl.dotpay.pl/t2/';
102 } elseif ($Environment == 'test') {
103 $EnvironmentAddress = 'https://ssl.dotpay.pl/test_payment/';
104 }
105
106 if ($RedirectionMethod == 'POST') {
107 $RedirectionCode = '<form action="'.$EnvironmentAddress.'" method="POST" id="dotpay_redirection_form" accept-charset="UTF-8">'.PHP_EOL;
108 $RedirectionCode .= "\t".'<input name="id" value="'.$DotpayId.'" type="hidden"/>'.PHP_EOL;
109
110 foreach ($ParametersArray as $key => $value)
111 {
112 $RedirectionCode .= "\t".'<input name="'.$key.'" value="'.$value.'" type="hidden"/>'.PHP_EOL;
113 }
114 $RedirectionCode .= "\t".'<input name="chk" value="'.$ChkValue.'" type="hidden"/>'.PHP_EOL;
115 $RedirectionCode .= '</form>'.PHP_EOL.'<button id="dotpay_redirection_button" class="btn btn-primary btn-block mt-5 mb-5" type="submit" form="dotpay_redirection_form" value="Submit">Przejdź do płatności</button>'.PHP_EOL;
116
117 return $RedirectionCode;
118
119 } elseif ($RedirectionMethod == 'GET') {
120 $RedirectionCode = $EnvironmentAddress.'?';
121
122 foreach ($ParametersArray as $key => $value)
123 {
124 $RedirectionCode .= $key.'='.rawurlencode($value).'&';
125 }
126
127 $RedirectionCode .= 'id='.$DotpayId;
128 $RedirectionCode .= '&chk='.$ChkValue;
129
130 return '<a href="'.$RedirectionCode.'">Link to Pay</a>';
131 }
132}