1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
result_rec.php
См. документацию.
1<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();?><?
2include(GetLangFileName(dirname(__FILE__)."/", "/payment.php"));
3if(!function_exists("bx_hmac"))
4{
5 function bx_hmac($algo, $data, $key, $raw_output = false)
6 {
7 $algo = mb_strtolower($algo);
8 $pack = "H".mb_strlen($algo("test"));
9 $size = 64;
10 $opad = str_repeat(chr(0x5C), $size);
11 $ipad = str_repeat(chr(0x36), $size);
12
13 if (mb_strlen($key) > $size) {
14 $key = str_pad(pack($pack, $algo($key)), $size, chr(0x00));
15 } else {
16 $key = str_pad($key, $size, chr(0x00));
17 }
18
19 $lenKey = mb_strlen($key) - 1;
20 for ($i = 0; $i < $lenKey; $i++) {
21 $opad[$i] = $opad[$i] ^ $key[$i];
22 $ipad[$i] = $ipad[$i] ^ $key[$i];
23 }
24
25 $output = $algo($opad.pack($pack, $algo($ipad.$data)));
26 return ($raw_output) ? pack($pack, $output) : $output;
27 }
28}
29
30$p_terminal = $_POST["TERMINAL"];
31$p_trtype = $_POST["TRTYPE"];
32$p_order = $_POST["ORDER"];
33$p_amount = $_POST["AMOUNT"];
34$p_currency = $_POST["CURRENCY"];
35$p_action = $_POST["ACTION"];
36$p_rc = $_POST["RC"];
37$p_approval = $_POST["APPROVAL"];
38$p_rrn = $_POST["RRN"];
39$p_int_ref = $_POST["INT_REF"];
40$p_tm = $_POST["TIMESTAMP"];
41$p_cardbin = $_POST["CARDBIN"];
42$p_nonce = $_POST["NONCE"];
43$p_sign = $_POST["P_SIGN"];
44$p_extcode = $_POST["EXTCODE"];
45
46$bError = true;
47
49
50if($mac <> '' && $arOrder = CSaleOrder::GetByID(intval($p_order)))
51{
52 CSalePaySystemAction::InitParamArrays($arOrder, $arOrder["ID"]);
53
55 $amount = number_format($amount, 2, ".", "");
57 if($currency == '')
58 $currency = "UAH";
59
61 if(mb_strlen($order) < 6)
62 {
63 $n = 6 - mb_strlen($order);
64 for($i = 0; $i < $n; $i++)
65 $order = "0".$order;
66 }
67
72
73 $PAY_OK = str_replace("#ID#", $arOrder["ID"], CSalePaySystemAction::GetParamValue("PAY_OK"));
74 $PAY_ERROR = str_replace("#ID#", $arOrder["ID"], CSalePaySystemAction::GetParamValue("PAY_ERROR"));
75 $ALLOW_DELIVERY = CSalePaySystemAction::GetParamValue("ALLOW_DELIVERY");
76
77 if(CSalePaySystemAction::GetParamValue("IS_TEST") <> '')
78 $server_url = "/cgi-bin/cgi_test";
79 else
80 $server_url = "/cgi-bin/cgi_link";
81
82 $key = pack("H*", $mac);
83
84 $sign = ToUpper(bx_hmac("sha1",
85 ($p_rrn <> '' ? mb_strlen($p_rrn).$p_rrn : "-").
86 ($p_int_ref <> '' ? mb_strlen($p_int_ref).$p_int_ref : "-").
87 ($p_terminal <> '' ? mb_strlen($p_terminal).$p_terminal : "-").
88 ($p_trtype <> '' ? mb_strlen($p_trtype).$p_trtype : "-").
89 ($p_order <> '' ? mb_strlen($p_order).$p_order : "-").
90 ($p_amount <> '' ? mb_strlen($p_amount).$p_amount : "-").
91 ($p_currency <> '' ? mb_strlen($p_currency).$p_currency : "-").
92 ($p_action <> '' ? mb_strlen($p_action).$p_action : "-").
93 ($p_rc <> '' ? mb_strlen($p_rc).$p_rc : "-").
94 ($p_approval <> '' ? mb_strlen($p_approval).$p_approval : "-").
95 ($p_tm <> '' ? mb_strlen($p_tm).$p_tm : "-").
96 ($p_nonce <> '' ? mb_strlen($p_nonce).$p_nonce : "-")
97 ,
98 $key
99 ));
100
101 $strPS_STATUS_DESCRIPTION = "";
102 $strPS_STATUS_DESCRIPTION .= "ACTION: ".$p_action."; ";
103 $strPS_STATUS_DESCRIPTION .= "RC: ".$p_rc."; ";
104 $strPS_STATUS_DESCRIPTION .= "APPROVAL: ".$p_approval."; ";
105 $strPS_STATUS_DESCRIPTION .= "RRN: ".$p_rrn."; ";
106 $strPS_STATUS_DESCRIPTION .= "INT_REF: ".$p_int_ref."; ";
107
109 "PS_STATUS" => "N",
110 "PS_STATUS_CODE" => $p_action,
111 "PS_STATUS_DESCRIPTION" => $strPS_STATUS_DESCRIPTION,
112 "PS_STATUS_MESSAGE" => "",
113 "PS_SUM" => $p_amount,
114 "PS_CURRENCY" => $p_currency,
115 "PS_RESPONSE_DATE" => Date(CDatabase::DateFormatToPHP(CLang::GetDateFormat("FULL", LANG))),
116 );
117 if($p_extcode <> '' && $p_extcode != "NONE")
118 $arFields["PS_STATUS_MESSAGE"] .= GetMessage("EXTCODE_".$p_extcode).". ";
119
120 if($sign == $p_sign)
121 {
122 if($p_action == "0" && $p_rc = "00")
123 {
124 if(DoubleVal($p_amount) == DoubleVal($arOrder["PRICE"]) && $p_currency == $currency)
125 {
126 echo $PAY_OK;
127 $bError = false;
128 $arFields["PS_STATUS"] = "Y";
129
130 if($arOrder["PAYED"] != "Y")
131 CSaleOrder::PayOrder($arOrder["ID"], "Y", true, true);
132 if($arOrder["ALLOW_DELIVERY"] != "Y" && $ALLOW_DELIVERY == "Y")
133 CSaleOrder::DeliverOrder($arOrder["ID"], "Y");
134
135 $trtype = 21;
136 $time = gmdate("YmdHis", time());
137 $var = unpack("H*r", ToUpper(mb_substr(md5(uniqid(30)), 0, 8)));
138 $nonce = $var[r];
139
140 $signew = bx_hmac("sha1",
141 mb_strlen($order).$order.
142 mb_strlen($amount).$amount.
143 mb_strlen($currency).$currency.
144 mb_strlen($p_rrn).$p_rrn.
145 mb_strlen($p_int_ref).$p_int_ref.
146 mb_strlen($trtype).$trtype.
147 mb_strlen($terminal).$terminal.
148 mb_strlen($time).$time.
149 mb_strlen($nonce).$nonce
150 ,
151 $key
152 );
153
154 $res = "";
155 $res .= "TRTYPE=".$trtype;
156 $res .= "&ORDER=".$order;
157 $res .= "&AMOUNT=".$amount;
158 $res .= "&CURRENCY=".$currency;
159 $res .= "&RRN=".$p_rrn;
160 $res .= "&INT_REF=".$p_int_ref;
161 $res .= "&TERMINAL=".$terminal;
162 $res .= "&TIMESTAMP=".$time;
163 $res .= "&NONCE=".$nonce;
164 $res .= "&EMAIL=".$email;
165 $res .= "&LANG=";
166 $res .= "&P_SIGN=".$signew;
167
168 $header = "POST ".$server_url." HTTP/1.0\r\n";
169 $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
170 $header .= "Content-Length: ".mb_strlen($res) . "\r\n\r\n";
171
172 $fp = fsockopen("ssl://3ds.eximb.com", 443, $errno, $errstr, 60);
173 if($fp)
174 fputs ($fp, $header.$res);
175 fclose ($fp);
176 }
177 else
178 $arFields["PS_STATUS_MESSAGE"] .= GetMessage("ERROR_SUM").". ";
179 }
180 }
181 else
182 $arFields["PS_STATUS_MESSAGE"] .= GetMessage("ERROR_CHECKSUM")."";
183
184 if($bError)
185 echo $PAY_ERROR;
186
187 CSaleOrder::Update($arOrder["ID"], $arFields);
188}
189?>
static GetParamValue($key, $defaultValue=null)
Определения pay_system_action.php:76
static Update($ID, $arFields, $bDateUpdate=true)
Определения order.php:140
$arFields
Определения dblapprove.php:5
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$output
Определения options.php:436
ToUpper($str)
Определения tools.php:2247
GetMessage($name, $aReplace=null)
Определения tools.php:3397
GetLangFileName($before, $after, $lang=false)
Определения tools.php:3428
$order
Определения payment.php:8
$nonce
Определения payment.php:64
else $server_url
Определения payment.php:56
$time
Определения payment.php:61
$merchant
Определения payment.php:47
$var
Определения payment.php:63
$sign
Определения payment.php:69
if(mb_strlen($order)< 6) $desc
Определения payment.php:44
$email
Определения payment.php:49
$trtype
Определения payment.php:58
$mac
Определения payment.php:51
if(!function_exists("bx_hmac")) $amount
Определения payment.php:30
$terminal
Определения payment.php:48
$p_currency
Определения result_rec.php:34
$p_cardbin
Определения result_rec.php:41
$p_rc
Определения result_rec.php:36
$p_trtype
Определения result_rec.php:31
$p_sign
Определения result_rec.php:43
$p_rrn
Определения result_rec.php:38
$p_approval
Определения result_rec.php:37
$p_action
Определения result_rec.php:35
$p_order
Определения result_rec.php:32
$bError
Определения result_rec.php:46
$p_nonce
Определения result_rec.php:42
$p_tm
Определения result_rec.php:40
$p_amount
Определения result_rec.php:33
$p_int_ref
Определения result_rec.php:39
$mac
Определения result_rec.php:48
if(!function_exists("bx_hmac")) $p_terminal
Определения result_rec.php:30
$p_extcode
Определения result_rec.php:44
if(empty($signedUserToken)) $key
Определения quickway.php:257
die
Определения quickway.php:367
$i
Определения factura.php:643
$currency
Определения template.php:266
$n
Определения update_log.php:107