Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
compatibilityhandler.php
1<?php
2
4
12
13Loc::loadMessages(__FILE__);
14
20{
25 public function getPaymentIdFromRequest(Request $request)
26 {
27 return array();
28 }
29
34 protected function isTestMode(Payment $payment = null)
35 {
36 return false;
37 }
38
42 protected function getUrlList()
43 {
44 return array();
45 }
46
52 public function initiatePay(Payment $payment, Request $request = null)
53 {
54 $result = new ServiceResult();
55
56 $this->getParamsBusValue($payment);
57
58 if ($this->initiateMode == self::STREAM)
59 {
60 $this->includeFile('payment.php');
61 }
62 else if ($this->initiateMode == self::STRING)
63 {
64 ob_start();
65 $content = $this->includeFile('payment.php');
66
67 $buffer = ob_get_contents();
68 if ($buffer <> '')
69 $content = $buffer;
70
71 $result->setTemplate($content);
72 ob_end_clean();
73 }
74
75 if ($this->service->getField('ENCODING') != '')
76 {
77 define("BX_SALE_ENCODING", $this->service->getField('ENCODING'));
78 AddEventHandler('main', 'OnEndBufferContent', array($this, 'OnEndBufferContent'));
79 }
80
81 return $result;
82 }
83
89 public function showTemplate(Payment $payment = null, $template = '')
90 {
91 $result = new ServiceResult();
92
93 $this->getParamsBusValue($payment);
94
95 if ($this->initiateMode == self::STREAM)
96 {
97 $this->includeFile('payment.php');
98 }
99 else if ($this->initiateMode == self::STRING)
100 {
101 ob_start();
102 $content = $this->includeFile('payment.php');
103
104 $buffer = ob_get_contents();
105 if ($buffer <> '')
106 $content = $buffer;
107
108 $result->setTemplate($content);
109 ob_end_clean();
110 }
111
112 if ($this->service->getField('ENCODING') != '')
113 {
114 define("BX_SALE_ENCODING", $this->service->getField('ENCODING'));
115 AddEventHandler('main', 'OnEndBufferContent', array($this, 'OnEndBufferContent'));
116 }
117
118 return $result;
119 }
120
125 public function getParamsBusValue(Payment $payment = null)
126 {
127 $orderId = 0;
128 $orderFields = array();
129 $paymentFields = array();
130 $relatedData = array();
131
132 if ($payment !== null)
133 {
135 $paymentCollection = $payment->getCollection();
136
137 $order = $paymentCollection->getOrder();
138
139 if ($order->getId() > 0)
140 {
141 $orderId = $order->getId();
142 $orderFields = $order->getFieldValues();
143 $paymentFields = $payment->getFieldValues();
144 }
145 }
146
147 if ($orderId <= 0)
148 {
149 $data = Manager::getHandlerDescription($this->service->getField('ACTION_FILE'));
150 $templateParams = $this->getExtraParams();
151
152 $relatedData['TEMPLATE_PARAMS'] = array();
153 foreach ($data['CODES'] as $codeId => $code)
154 {
155 if (array_key_exists($codeId, $templateParams))
156 {
157 $code['VALUE'] = $templateParams[$codeId];
158 $relatedData['TEMPLATE_PARAMS'][$codeId] = $code;
159 }
160 }
161
162 if (isset($templateParams['ORDER']))
163 $orderFields = $templateParams['ORDER'];
164
165 if (isset($templateParams['BASKET_ITEMS']))
166 {
167 $relatedData['BASKET_ITEMS'] = $templateParams['BASKET_ITEMS'];
168 unset($templateParams['BASKET_ITEMS']);
169 }
170
171 if (isset($templateParams['TAX_LIST']))
172 {
173 $relatedData['TAX_LIST'] = $templateParams['TAX_LIST'];
174 unset($templateParams['TAX_LIST']);
175 }
176
177 $paymentFields['PAY_SYSTEM_ID'] = $this->service->getField('ID');
178 }
179
180 \CSalePaySystemAction::InitParamArrays($orderFields, $orderId, '', $relatedData, $paymentFields);
181
182 return $GLOBALS['SALE_INPUT_PARAMS'];
183 }
184
190 public function processRequest(Payment $payment, Request $request)
191 {
192 $this->getParamsBusValue($payment);
193 $this->includeFile('result_rec.php');
194 die();
195 }
196
201 private function includeFile($file)
202 {
203 global $APPLICATION, $USER, $DB;
204 $documentRoot = Application::getDocumentRoot();
205
206 $path = $documentRoot.$this->service->getField('ACTION_FILE').'/'.$file;
207 if (IO\File::isFileExists($path))
208 {
209 $result = require $path;
210 if ($result !== false && $result !== 1)
211 return $result;
212 }
213
214 return '';
215 }
216
221 public function getEntityIds(Request $request)
222 {
223 return array();
224 }
225
229 public function getCurrencyList()
230 {
231 return array();
232 }
233
234 public function getPrice(Payment $payment)
235 {
236 $paySystemId = $payment->getPaymentSystemId();
237 $psData = Manager::getById($paySystemId);
238 $psData['PSA_ACTION_FILE'] = $psData['ACTION_FILE'];
239 $psData['PSA_TARIF'] = $psData['TARIF'];
240
242 $collection = $payment->getCollection();
243
245 $order = $collection->getOrder();
246
248 $shipmentCollection = $order->getShipmentCollection();
249
250 $shipment = null;
251
253 foreach ($shipmentCollection as $item)
254 {
255 if (!$item->isSystem())
256 {
257 $shipment = $item;
258 break;
259 }
260 }
261
263 $propertyCollection = $order->getPropertyCollection();
264
266 $deliveryLocation = $propertyCollection->getDeliveryLocation();
267
268 if ($shipment)
269 return \CSalePaySystemsHelper::getPSPrice($psData, $payment->getSum(), $shipment->getPrice(), $deliveryLocation->getValue());
270
271 return 0;
272 }
273
277 public function isPayableCompatibility()
278 {
279 $documentRoot = Application::getDocumentRoot();
280 $actionFile = $this->service->getField('ACTION_FILE');
281
282 return IO\File::isFileExists($documentRoot.$actionFile.'/tarif.php');
283 }
284
288 public function isCheckableCompatibility()
289 {
290 $documentRoot = Application::getDocumentRoot();
291 $actionFile = $this->service->getField('ACTION_FILE');
292
293 return IO\File::isFileExists($documentRoot.$actionFile.'/result.php');
294 }
295
300 public function check(Payment $payment)
301 {
302 if ($this->isCheckableCompatibility())
303 {
305 $paymentCollection = $payment->getCollection();
306
308 $order = $paymentCollection->getOrder();
309
310 \CSalePaySystemAction::InitParamArrays($order->getFieldValues(), $order->getId(), '', array(), $payment->getFieldValues());
311
312 $res = $this->includeFile('result.php');
313 return $res;
314 }
315
316 return false;
317 }
318
319 protected function includeDescription(): array
320 {
321 $data = array();
322
323 $documentRoot = Application::getDocumentRoot();
324 $handler = $this->service->getField('ACTION_FILE');
325
326 $psTitle = '';
327 $arPSCorrespondence = array();
328
329 $actionFile = $documentRoot.$handler.'/.description.php';
330 if (IO\File::isFileExists($actionFile))
331 {
332 require $actionFile;
333
334 if ($arPSCorrespondence)
335 {
336 $codes = $this->convertCodesToNewFormat($arPSCorrespondence);
337
338 if ($codes)
339 $data = array('NAME' => $psTitle, 'SORT' => 100, 'CODES' => $codes);
340 }
341 }
342
343 if (isset($data["CODES"]) && is_array($data["CODES"]))
344 {
345 $data["CODES"] = $this->filterDescriptionCodes($data["CODES"]);
346 }
347
348 return $data;
349 }
350
355 private function convertCodesToNewFormat(array $arPSCorrespondence)
356 {
357 if ($arPSCorrespondence)
358 {
359 foreach ($arPSCorrespondence as $i => $property)
360 {
361 if ($property['TYPE'] == 'SELECT')
362 {
363 $options = array();
364 foreach ($property['VALUE'] as $code => $value)
365 $options[$code] = $value['NAME'];
366
367 $arPSCorrespondence[$i] = array(
368 'NAME' => $property['NAME'],
369 'INPUT' => array(
370 'TYPE' => 'ENUM',
371 'OPTIONS' => $options
372 ),
373 'SORT' => $property['SORT'],
374 );
375 }
376 else if ($property['TYPE'] == 'FILE')
377 {
378 $arPSCorrespondence[$i] = array(
379 'NAME' => $property['NAME'],
380 'INPUT' => array(
381 'TYPE' => 'FILE'
382 ),
383 'SORT' => $property['SORT'],
384 );
385 }
386 else if ($property['TYPE'] == 'CHECKBOX')
387 {
388 $arPSCorrespondence[$i] = array(
389 'NAME' => $property['NAME'],
390 'INPUT' => array(
391 'TYPE' => 'Y/N'
392 ),
393 'SORT' => $property['SORT'],
394 );
395
396 if (isset($property['VALUE']))
397 {
398 $arPSCorrespondence[$i]['VALUE'] = $property['VALUE'];
399 }
400 }
401
402 if (array_key_exists('DESCR', $property))
403 $arPSCorrespondence[$i]['DESCRIPTION'] = $property['DESCR'];
404
405 if (!isset($arPSCorrespondence[$i]['GROUP']))
406 $arPSCorrespondence[$i]['GROUP'] = (isset($property['GROUP'])) ? $property['GROUP'] : 'PS_OTHER';
407 }
408
409 return $arPSCorrespondence;
410 }
411
412 return array();
413 }
414
418 public function getDemoParams()
419 {
420 $data = array(
421 'ORDER' => array(
422 'ACCOUNT_NUMBER' => 'A1',
423 'DATE_INSERT' => new Type\DateTime(),
424 'CURRENCY' => 'RUB',
425 'SHOULD_PAY' => 2000,
426 'PRICE' => 2000,
427 'SUM_PAID' => 0,
428 ),
429 'TAX_LIST' => array(
430 array(
431 'TAX_NAME' => Loc::getMessage('SALE_COMPATIBILITY_TAX'),
432 'IS_IN_PRICE' => 'Y',
433 'VALUE_MONEY' => 200,
434 'VALUE' => 0.1,
435 'IS_PERCENT' => 10
436 )
437 ),
438 'BASKET_ITEMS' => array(
439 array(
440 'NAME' => Loc::getMessage('SALE_COMPATIBILITY_BASKET_ITEM_NAME'),
441 'IS_VAT_IN_PRICE' => true,
442 'PRICE' => 900,
443 'VAT_RATE' => 0.1,
444 'QUANTITY' => 2,
445 'MEASURE_NAME' => Loc::getMessage('SALE_COMPATIBILITY_BASKET_ITEM_MEASURE'),
446 'CURRENCY' => 'RUB'
447 )
448 ),
449 'SELLER_CITY' => Loc::getMessage('SALE_COMPATIBILITY_BANK_CITY'),
450 'SELLER_BCITY' => Loc::getMessage('SALE_COMPATIBILITY_BANK_CITY'),
451 'SELLER_ADDRESS' => Loc::getMessage('SALE_COMPATIBILITY_BANK_ADDRESS'),
452 'SELLER_PHONE' => '+76589321451',
453 'SELLER_BANK_IBAN' => '1989 000 92',
454 'SELLER_BANK_SWIFT' => '0000000000',
455 'SELLER_BANK_PHONE' => '+76589321451',
456 'SELLER_BANK' => Loc::getMessage('SALE_COMPATIBILITY_BANK_NAME'),
457 'SELLER_RS' => '0000 0000 0000 0000 0000',
458 'SELLER_BANK_ACCNO' => '0000 0000 0000 0000 0000',
459 'SELLER_INN' => '000011112222',
460 'SELLER_EU_INN' => '000011112222',
461 'SELLER_REG' => '1615 00 785',
462 'SELLER_KPP' => '123456789',
463 'SELLER_NAME' => Loc::getMessage('SALE_COMPATIBILITY_COMPANY_NAME'),
464 'SELLER_BIK' => '0123456',
465 'SELLER_BIC' => '0123456',
466 'SELLER_BANK_BLZ' => '0123456',
467 'SELLER_KS' => '1111 1111 1111 1111',
468 'SELLER_BANK_ROUTENO' => '1111 1111 1111 1111',
469 'BUYER_NAME' => Loc::getMessage('SALE_COMPATIBILITY_BUYER_COMPANY_NAME'),
470 'BUYER_INN' => '0123456789',
471 'BUYER_PHONE' => '79091234523',
472 'BUYER_FAX' => '88002000600',
473 'BUYER_ADDRESS' => Loc::getMessage('SALE_COMPATIBILITY_BUYER_COMPANY_ADDRESS'),
474 'BUYER_PAYER_NAME' => Loc::getMessage('SALE_COMPATIBILITY_BUYER_NAME_CONTACT'),
475 'SELLER_DIR_POS' => Loc::getMessage('SALE_COMPATIBILITY_DIRECTOR_POSITION'),
476 'SELLER_DIR' => Loc::getMessage('SALE_COMPATIBILITY_DIRECTOR_NAME'),
477 'SELLER_ACC_POS' => Loc::getMessage('SALE_COMPATIBILITY_ACCOUNTANT_POSITION'),
478 'SELLER_ACC' => Loc::getMessage('SALE_COMPATIBILITY_ACCOUNTANT_NAME'),
479 'SELLER_EMAIL' => 'my@company.com',
480 'COMMENT1' => Loc::getMessage('SALE_COMPATIBILITY_COMMENT1'),
481 'COMMENT2' => Loc::getMessage('SALE_COMPATIBILITY_COMMENT2'),
482 );
483
484 if (Loader::includeModule('crm') && Loader::includeModule('iblock'))
485 {
486 $arFilter = array(
487 'IBLOCK_ID' => intval(\CCrmCatalog::EnsureDefaultExists()),
488 'CHECK_PERMISSIONS' => 'N',
489 '!PROPERTY_TYPE' => 'G'
490 );
491
492 $dbRes = \CIBlockProperty::GetList(array(), $arFilter);
493 while ($arRow = $dbRes->Fetch())
494 $data['BASKET_ITEMS'][0]['PROPERTY_'.$arRow['ID']] = 'test';
495 }
496
497 return $data;
498 }
499
500}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
initiatePay(Payment $payment, Request $request=null)
processRequest(Payment $payment, Request $request)
showTemplate(Payment $payment=null, $template='')
static getHandlerDescription($handler, $psMode=null)
Definition manager.php:546
$GLOBALS['____1444769544']
Definition license.php:1