1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
payment.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\Controller;
4
5use Bitrix\Main\Engine\AutoWire\ExactParameter;
6use Bitrix\Main\Engine\Response\DataType\Page;
7use Bitrix\Main\Error;
8use Bitrix\Main\Result;
9use Bitrix\Main\UI\PageNavigation;
10use Bitrix\Sale;
11use Bitrix\Sale\Helpers\Order\Builder\SettingsContainer;
12use Bitrix\Sale\PaymentCollection;
13use Bitrix\Sale\PaySystem\PaymentAvailablesPaySystems;
14
20class Payment extends Controller
21{
22 public function getPrimaryAutoWiredParameter()
23 {
24 return new ExactParameter(
25 Sale\Payment::class,
26 'payment',
27 function($className, $id)
28 {
30
32 $paymentClass = $registry->getPaymentClassName();
33
34 $iterator = $paymentClass::getList([
35 'select' => [
36 'ORDER_ID',
37 ],
38 'filter' => [
39 'ID' => $id,
40 ],
41 ]);
42
43 $row = $iterator->fetch();
44 if ($row)
45 {
47 $orderClass = $registry->getOrderClassName();
48
49 $order = $orderClass::load($row['ORDER_ID']);
50 $payment = $order->getPaymentCollection()->getItemById($id);
51 if ($payment)
52 {
53 return $payment;
54 }
55 }
56 else
57 {
58 $this->addError(new Error('payment is not exists', 200640400001));
59 }
60
61 return null;
62 }
63 );
64 }
65
66 //region Actions
67 public function getFieldsAction()
68 {
70
71 return [
72 'PAYMENT' => $entity->prepareFieldInfos($entity->getFields()),
73 ];
74 }
75
76 public function modifyAction($fields)
77 {
78 $builder = $this->getBuilder();
79 $builder->buildEntityPayments($fields);
80
81 if (!$builder->getErrorsContainer()->getErrorCollection()->isEmpty())
82 {
83 $this->addErrors($builder->getErrorsContainer()->getErrors());
84
85 return null;
86 }
87
88 $order = $builder->getOrder();
89
90 $result = $order->save();
91 if (!$result->isSuccess())
92 {
93 $this->addErrors($result->getErrors());
94
95 return null;
96 }
97
98 //TODO: return $payment->toArray();
99 return [
100 'PAYMENTS' => $this->toArray($order)['ORDER']['PAYMENTS'],
101 ];
102 }
103
104 public function addAction(array $fields)
105 {
106 $data = [];
107 $data['ORDER']['ID'] = $fields['ORDER_ID'];
108 $data['ORDER']['PAYMENTS'] = [$fields];
109
110 $builder = $this->getBuilder(
112 'deletePaymentIfNotExists' => false,
113 ])
114 );
115
116 $builder->buildEntityPayments($data);
117
118 if (!$builder->getErrorsContainer()->getErrorCollection()->isEmpty())
119 {
120 $this->addErrors($builder->getErrorsContainer()->getErrors());
121
122 return null;
123 }
124
125 $order = $builder->getOrder();
126 $idx = 0;
127 $collection = $order->getPaymentCollection();
129 foreach ($collection as $payment)
130 {
131 if ($payment->getId() <= 0)
132 {
133 $idx = $payment->getInternalIndex();
134 break;
135 }
136 }
137
138 $result = $order->save();
139 if (!$result->isSuccess())
140 {
141 $this->addErrors($result->getErrors());
142
143 return null;
144 }
145
147 $entity = $order->getPaymentCollection()->getItemByIndex($idx);
148
149 return [
150 'PAYMENT' => $this->get($entity),
151 ];
152 }
153
154 public function updateAction(\Bitrix\Sale\Payment $payment, array $fields)
155 {
156 $data = [];
157
158 $fields['ID'] = $payment->getId();
159 $fields['ORDER_ID'] = $payment->getOrderId();
160
161 $data['ORDER']['ID'] = $fields['ORDER_ID'];
162 $data['ORDER']['PAYMENTS'] = [$fields];
163
164 $builder = $this->getBuilder(
165 new SettingsContainer([
166 'deletePaymentIfNotExists' => false,
167 ])
168 );
169 $builder->buildEntityPayments($data);
170
171 if (!$builder->getErrorsContainer()->getErrorCollection()->isEmpty())
172 {
173 $this->addErrors($builder->getErrorsContainer()->getErrors());
174
175 return null;
176 }
177
178 $order = $builder->getOrder();
179
180 $result = $order->save();
181 if (!$result->isSuccess())
182 {
183 $this->addErrors($result->getErrors());
184
185 return null;
186 }
187 if ($result->hasWarnings())
188 {
189 $this->addErrors($result->getWarnings());
190
191 return null;
192 }
193
195 $entity = $order->getPaymentCollection()->getItemById($payment->getId());
196
197 return [
198 'PAYMENT' => $this->get($entity),
199 ];
200 }
201
203 {
204 $result = $payment->delete();
205
206 return $this->save($payment, $result);
207 }
208
210 {
211 return [
212 'PAYMENT' => $this->get($payment),
213 ];
214 }
215
216 public function listAction(
217 PageNavigation $pageNavigation,
218 array $select = [],
219 array $filter = [],
220 array $order = [],
221 bool $__calculateTotalCount = true
222 ): Page
223 {
224 $select = empty($select) ? ['*'] : $select;
225 $order = empty($order) ? ['ID' => 'ASC'] : $order;
226
227 $runtime = [
228 new \Bitrix\Main\Entity\ReferenceField(
229 'PAY_SYSTEM',
230 '\Bitrix\Sale\Internals\PaySystemActionTable',
231 ['=this.PAY_SYSTEM_ID' => 'ref.ID']
232 )
233 ];
234
236 'select' => $select,
237 'filter' => $filter,
238 'order' => $order,
239 'offset' => $pageNavigation->getOffset(),
240 'limit' => $pageNavigation->getLimit(),
241 'runtime' => $runtime,
242 'count_total' => $__calculateTotalCount,
243 ]);
244 $payments = $iterator->fetchAll();
245 $totalCount = $__calculateTotalCount ? $iterator->getCount() : 0;
246
247 return new Page('payments', $payments, $totalCount);
248 }
249
251 {
252 return $payment->getOrderId();
253 }
254
256 {
257 return $payment->getPaymentSystemId();
258 }
259
261 {
262 return $payment->getPaymentSystemName();
263 }
264
266 {
267 return $payment->getPersonTypeId();
268 }
269
271 {
272 return $payment->getSum();
273 }
274
276 {
277 return $payment->getSumPaid();
278 }
279
281 {
282 return $payment->isInner() ? 'Y' : 'N';
283 }
284
286 {
287 return $payment->isMarked() ? 'Y' : 'N';
288 }
289
291 {
292 return $payment->isPaid() ? 'Y' : 'N';
293 }
294
296 {
297 return $payment->isReturn() ? 'Y' : 'N';
298 }
299
300 public function setPaidAction(Sale\Payment $payment, $value)
301 {
302 $result = $payment->setPaid($value);
303 if ($result->isSuccess())
304 {
305 $this->save($payment, $result);
306 }
307
308 if (!$result->isSuccess())
309 {
310 $this->addErrors($result->getErrors());
311
312 return null;
313 }
314
315 return true;
316 }
317/*
318 public function setAccountNumberAction(\Bitrix\Sale\Payment $payment, $id)
319 {
320 $r = $payment->setAccountNumber($id);
321 return $this->save($payment, $r);
322 }
323*/
324 public function setReturnAction(Sale\Payment $payment, $value)
325 {
326 $result = $payment->setReturn($value);
327
328 return $this->save($payment, $result);
329 }
330
341 {
343 $errors = $result->getErrors();
344 if (!empty($errors))
345 {
346 $this->addErrors($errors);
347
348 return null;
349 }
350
351 return true;
352 }
353
365 {
367 $errors = $result->getErrors();
368 if (!empty($errors))
369 {
370 $this->addErrors($errors);
371
372 return null;
373 }
374
375 return true;
376 }
377 //endregion
378
379 private function save(Sale\Payment $payment, Result $r)
380 {
381 if (!$r->isSuccess())
382 {
383 $this->addErrors($r->getErrors());
384
385 return null;
386 }
387 else
388 {
390 $collection = $payment->getCollection();
391 $r = $collection->getOrder()->save();
392 if (!$r->isSuccess())
393 {
394 $this->addErrors($r->getErrors());
395
396 return null;
397 }
398 }
399
400 return $r->isSuccess();
401 }
402
403 protected function get(Sale\Payment $payment, array $fields=[])
404 {
405 $payments = $this->toArray($payment->getCollection()->getOrder(), $fields)['ORDER']['PAYMENTS'];
406 foreach ($payments as $item)
407 {
408 if ($item['ID'] == $payment->getId())
409 {
410 return $item;
411 }
412 }
413
414 return [];
415 }
416
417 static public function prepareFields($fields)
418 {
419 return
420 isset($fields['PAYMENTS'])
421 ? ['PAYMENT' => $fields['PAYMENTS']]
422 : []
423 ;
424 }
425
426 protected function checkPermissionEntity($name)
427 {
428 if (
429 $name === 'getorderid'
430 || $name === 'getpaymentsystemid'
431 || $name === 'getpaymentsystemname'
432 || $name === 'getpersontypeid'
433 || $name === 'getsum'
434 || $name === 'getsumpaid'
435 || $name === 'isinner'
436 || $name === 'ismarked'
437 || $name === 'isnarked'
438 || $name === 'ispaid'
439 || $name === 'isreturn'
440 )
441 {
442 $result = $this->checkReadPermissionEntity();
443 }
444 elseif (
445 $name === 'setpaid'
446 || $name === 'setavailablepaysystems'
447 || $name === 'clearavailablepaysystems'
448 || $name === 'setreturn'
449 )
450 {
451 $result = $this->checkModifyPermissionEntity();
452 }
453 else
454 {
455 $result = parent::checkPermissionEntity($name);
456 }
457
458 return $result;
459 }
460}
addError(Error $error)
Определения controller.php:1070
addErrors(array $errors)
Определения controller.php:1083
getPrimaryAutoWiredParameter()
Определения controller.php:334
Определения error.php:15
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[], bool $__calculateTotalCount=true)
Определения payment.php:216
static prepareFields($fields)
Определения payment.php:417
getSumPaidAction(Sale\Payment $payment)
Определения payment.php:275
isInnerAction(Sale\Payment $payment)
Определения payment.php:280
setPaidAction(Sale\Payment $payment, $value)
Определения payment.php:300
getPaymentSystemIdAction(Sale\Payment $payment)
Определения payment.php:255
checkPermissionEntity($name)
Определения payment.php:426
setAvailablePaySystemsAction(Sale\Payment $payment, array $paySystemIds)
Определения payment.php:364
modifyAction($fields)
Определения payment.php:76
getPersonTypeIdAction(Sale\Payment $payment)
Определения payment.php:265
getPaymentSystemNameAction(Sale\Payment $payment)
Определения payment.php:260
getFieldsAction()
Определения payment.php:67
isMarkedAction(Sale\Payment $payment)
Определения payment.php:285
isReturnAction(Sale\Payment $payment)
Определения payment.php:295
getSumAction(Sale\Payment $payment)
Определения payment.php:270
clearAvailablePaySystemsAction(Sale\Payment $payment)
Определения payment.php:340
getAction(\Bitrix\Sale\Payment $payment)
Определения payment.php:209
setReturnAction(Sale\Payment $payment, $value)
Определения payment.php:324
getOrderIdAction(Sale\Payment $payment)
Определения payment.php:250
isPaidAction(Sale\Payment $payment)
Определения payment.php:290
deleteAction(\Bitrix\Sale\Payment $payment)
Определения payment.php:202
static setBindings(int $paymentId, array $paySystemIds)
Определения paymentavailablespaysystems.php:41
Определения payment.php:19
static getList(array $parameters=[])
Определения payment.php:1235
static getInstance($type)
Определения registry.php:183
const REGISTRY_TYPE_ORDER
Определения registry.php:16
$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
$result
Определения get_property_values.php:14
$entity
$errors
Определения iblock_catalog_edit.php:74
$select
Определения iblock_catalog_list.php:194
$filter
Определения iblock_catalog_list.php:54
$name
Определения menu_edit.php:35
Определения aliases.php:54
$payment
Определения payment.php:14
$order
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$totalCount
Определения subscription_card_product.php:51
$iterator
Определения yandex_run.php:610
$fields
Определения yandex_run.php:501