/
Method.php
2079 lines (1984 loc) · 101 KB
/
Method.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace Df\Payment;
use Df\Config\Source\NoWhiteBlack as NWB;
use Df\Core\Exception as DFE;
use Df\Core\ICached;
use Df\Payment\Block\Info as bInfo;
use Df\Payment\Init\Action as InitAction;
use Magento\Framework\App\Area;
use Magento\Framework\App\ScopeInterface;
use Magento\Framework\DataObject as _DO;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\LocalizedException as LE;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\ObjectManager\NoninterceptableInterface as INonInterceptable;
use Magento\Payment\Model\Info as I;
use Magento\Payment\Model\InfoInterface as II;
use Magento\Payment\Model\MethodInterface;
use Magento\Quote\Api\Data\CartInterface as ICart;
use Magento\Quote\Model\Quote as Q;
use Magento\Quote\Model\Quote\Payment as QP;
use Magento\Sales\Model\Order as O;
use Magento\Sales\Model\Order\Payment as OP;
use Magento\Sales\Model\Order\Payment\Transaction as T;
use Magento\Store\Model\Store;
use \Throwable as Th; # 2023-08-02 "Treat `\Throwable` similar to `\Exception`": https://github.com/mage2pro/core/issues/311
/**
* 2016-02-08
* 2017-03-30
* Каждый потомок Method является объектом-одиночкой: @see \Df\Payment\Method::sg(),
* но вот info instance в него может устанавливаться разный: @see \Df\Payment\Method::setInfoInstance()
* Так происходит, например, в методе @see \Df\Payment\Observer\DataProvider\SearchResult::execute()
* https://github.com/mage2pro/core/blob/2.4.13/Payment/Observer/DataProvider/SearchResult.php#L52-L65
* Аналогично, в Method может устанавливаться разный store: @see \Df\Payment\Method::setStore()
* Поэтому будьте осторожны с кэшированием внутри Method!
* 2017-11-11
* I disable the `\Interceptor` target classes generation for this source class and all its descendants.
* "How to disable the `\Interceptor` target class generation for a particular source class?"
* https://mage2.pro/t/4914
* I useit to overcome issues like:
* 1) «Class Dfe\IPay88\Method\Interceptor may not inherit from final class (Dfe\IPay88\Method)
* in generated/code/Dfe/IPay88/Method/Interceptor.php on line 7:
* https://mage2.pro/t/4904
* 2) «Class Dfe\TwoCheckout\Method\Interceptor may not inherit from final class (Dfe\TwoCheckout\Method)»
* https://mage2.pro/t/4892
* 3) «Cannot call private Dfe\IPay88\Method::__construct()
* in generated/code/Dfe/IPay88/Method/Interceptor.php» https://mage2.pro/t/topic/4913
* @see \Dfe\GingerPaymentsBase\Method
* @see \Df\PaypalClone\Method
* @see \Df\StripeClone\Method
* @see \Dfe\ACH\Method
* @see \Dfe\CheckoutCom\Method
* @see \Dfe\Klarna\Method
* @see \Dfe\Qiwi\Method
* @see \Dfe\TwoCheckout\Method
*/
abstract class Method implements ICached, INonInterceptable, MethodInterface {
/**
* 2016-11-15
* 2017-02-08
* Замечание №1
* The result should be in the basic monetary unit (like dollars), not in fractions (like cents).
* Замечание №2
* Я пришёл к выводу, что у КАЖДОГО платёжного сервиса имеются ограничения на приём платежей.
* Поэтому пусть КАЖДЫЙ платёжный модуль явно декларирует эти ограничения.
* Допустимы следующие форматы результата:
* 1) null или [] — отсутствие лимитов.
* 2) [min, max] — общие лимиты для всех валют
* 3) callable — лимиты вычисляются динамически для конкретной валюты
* 4) ['USD' => [min, max], '*' => [min, max]] — лимиты заданы с таблицей,
* причём '*' — это лимиты по умолчанию.
* В случаях №2 и №4 min и/или max может быть равно null: это означает отсутствие лимита.
* @used-by self::isAvailable()
* @see \Dfe\GingerPaymentsBase\Method::amountLimits()
* @see \Dfe\ACH\Method::amountLimits()
* @see \Dfe\AllPay\Method::amountLimits()
* @see \Dfe\AlphaCommerceHub\Method::amountLimits()
* @see \Dfe\CheckoutCom\Method::amountLimits()
* @see \Dfe\Dragonpay\Method::amountLimits()
* @see \Dfe\IPay88\Method::amountLimits()
* @see \Dfe\Klarna\Method::amountLimits()
* @see \Dfe\Moip\Method::amountLimits()
* @see \Dfe\Omise\Method::amountLimits()
* @see \Dfe\Paymill\Method::amountLimits()
* @see \Dfe\PostFinance\Method::amountLimits()
* @see \Dfe\Qiwi\Method::amountLimits()
* @see \Dfe\Robokassa\Method::amountLimits()
* @see \Dfe\SecurePay\Method::amountLimits()
* @see \Dfe\Spryng\Method::amountLimits()
* @see \Dfe\Square\Method::amountLimits()
* @see \Dfe\Stripe\Method::amountLimits()
* @see \Dfe\TwoCheckout\Method::amountLimits()
* @see \Dfe\Vantiv\Method::amountLimits()
* @see \Dfe\YandexKassa\Method::amountLimits()
* @return null|[]|\Closure|array(int|float|null)|array(string => array(int|float|null))
*/
abstract protected function amountLimits();
/**
* 2016-02-15
* @override
* How is a payment method's acceptPayment() used? https://mage2.pro/t/715
* @see \Magento\Payment\Model\MethodInterface::acceptPayment()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L304-L312
* @see \Magento\Payment\Model\Method\AbstractMethod::acceptPayment()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L696-L713
* 2016-05-09
* A «Flagged» payment can be handled the same way as an «Authorised» payment: we can «capture» or «void» it.
* @param II|I|OP $p
*/
final function acceptPayment(II $p):bool {
# 2016-03-15
# The obvious `$this->charge($payment)` is not quite correct, because no invoice will be created in such case.
$p->capture();
return true;
}
/**
* 2016-08-14
* 2017-01-10
* Этот метод служит единой точкой входа для всех платёжных транзакций нашего класса.
* Сведение их в единую точку позволяет нам централизованно:
* 1) Отфлильтровывать случаи выполнения транзакций из webhooks
* (в этом случае мы не обращаемся к API платёжной системы,
* потому что на стороне платёжной системы транзакция уже проведена, о чём мы и получили оповещение в webhook).
* 2) Обрабатывать исключительные ситуации.
* При этом каждый платёжный модуль может иметь свои индивидуальные особенности
* обработки исключительных ситуаций, а здесь мы лишь выполняем общую, универсальную часть такой обработки.
* 3) Инициализировать библиотеку платёжной системы.
* @used-by self::authorize()
* @used-by self::capture()
* @used-by self::refund()
* @used-by self::void()
* @used-by \Df\Payment\Init\Action::action()
* @param string|\Closure $f
* @return mixed
*/
final function action($f, bool $log = true) {
$result = null; /** @var mixed $result */
if (!$this->ii(self::WEBHOOK_CASE)) {
dfp_sentry_tags($this);
df_sentry_tags($this, ['Payment Action' => $actionS = df_caller_f()]); /** @var string $actionS */
try {
$this->s()->init();
# 2017-01-10 Такой код корректен, проверял: https://3v4l.org/Efj63
$result = call_user_func($f instanceof \Closure ? $f : [$this, $f]);
/**
* 2017-01-31
* В настоящее время опция «Log the API requests and responses?»
* присутствует у модулей allPay и SecurePay:
* 1) allPay: https://github.com/mage2pro/allpay/blob/1.1.25/etc/adminhtml/system.xml?ts=4#L413-L426
* 2) SecurePay: https://github.com/mage2pro/securepay/blob/1.1.17/etc/adminhtml/system.xml?ts=4#L156-L169
* У остальных моих платёжных модулей этой опции пока нет,
* там функциональность логирования пока включена намертво.
* 2017-02-01
* До сегодняшнего дня Stripe-подобные модули для каждой платёжной операции
* создавали как минимум (не считая webhooks) 3 записи в логах:
* 1) Stripe: getConfigPaymentAction
* 2) [Stripe] chargeNew
* 3) Stripe: capture
* №1 и №3 создавались как раз отсюда, из action()
* Нам не нужно так много записей для единственной операции,
* поэтому добавил сейчас возможность отключать логирование в action().
*/
if ($log && $this->needLogActions() && $this->s()->log()) {
df_sentry($this, "{$this->titleB()}: $actionS");
}
}
catch (Th $th) {
# 2017-01-10
# Конвертация исключительных ситуаций библиотеки платёжной системы в наши.
# Исключительные ситуации библиотеки платёжной системы имеют свою внутреннуюю структуру,
# да и их диагностические сообщения — это не всегда то, что нам нужно.
# По этой причине мы их конвертируем в свои.
# Пока данная функциональность используется модулем Stripe.
df_log($th = $this->convertException($th));
/**
* 2016-03-17
* Чтобы система показала наше сообщение вместо общей фразы типа
* «We can't void the payment right now», надо вернуть объект именно класса
* @uses \Magento\Framework\Exception\LocalizedException
* https://mage2.pro/t/945
* https://github.com/magento/magento2/blob/2.1.0/app/code/Magento/Sales/Controller/Adminhtml/Order/VoidPayment.php#L20-L30
* 2017-09-27
* Previously, I had the following code here: throw df_lx($e);
* It triggered a false positive of the Magento Marketplace code validation tool:
* «Namespace for df_le class is not specified»:
* https://github.com/mage2pro/core/issues/27
* https://github.com/magento/marketplace-eqp/issues/45
* So I write it in the 2 lines as a workaround: $e = df_lx($e); throw $e;
* 2022-11-10 @noinspection PhpUnnecessaryLocalVariableInspection
*/
$th = df_lx($th); throw $th;
}
}
return $result;
}
/**
* 2016-09-07
* Конвертирует денежную величину (в валюте платежа) из обычного числа в формат платёжной системы.
* В частности, некоторые платёжные системы хотят денежные величины в копейках (Checkout.com),
* обязательно целыми (allPay) и т.п.
* 2016-09-08 Эта операция является обратной по отношению к @see amountParse()
* @used-by \Df\Payment\ConfigProvider::config()
* @used-by \Df\Payment\Operation::amountFormat()
* @used-by \Df\StripeClone\Method::_refund()
* @used-by \Df\StripeClone\Method::charge()
* @see \Dfe\AlphaCommerceHub\Method::amountFormat()
* @see \Dfe\Dragonpay\Method::amountFormat()
* @see \Dfe\IPay88\Method::amountFormat()
* @see \Dfe\Qiwi\Method::amountFormat()
* @see \Dfe\Robokassa\Method::amountFormat()
* @see \Dfe\SecurePay\Method::amountFormat()
* @see \Dfe\TwoCheckout\Method::amountFormat()
* @see \Dfe\YandexKassa\Method::amountFormat()
* @return float|int|string
*/
function amountFormat(float $a) {return round($a * $this->amountFactor());}
/**
* 2016-09-08
* Конвертирует денежную величину из формата платёжной системы в обычное число.
* Обратная операция по отношению к @see amountFormat()
* @used-by dfp_refund()
* @used-by \Dfe\GingerPaymentsBase\Block\Info::btInstructions()
* @used-by \Dfe\Stripe\Method::amountLimits()
* @param float|int|string $a
*/
final function amountParse($a):float {return $a / $this->amountFactor();}
/**
* 2016-02-15
* @override
* How is a payment method's assignData() used? https://mage2.pro/t/718
* @see \Magento\Payment\Model\MethodInterface::assignData()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L304-L312
* @see \Magento\Payment\Model\Method\AbstractMethod::assignData()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L762-L797
* ISSUES with @see \Magento\Payment\Model\Method\AbstractMethod::assignData():
* 1) The @see \Magento\Payment\Model\Method\AbstractMethod::assignData() method
* can be simplified: https://mage2.pro/t/719
* 2) The @see \Magento\Payment\Model\Method\AbstractMethod::assignData() method
* has a wrong PHPDoc declaration: https://mage2.pro/t/720
* 2022-10-19
* We can use `final` in the method's signature despite if M2 code generation
* because the class implements @see INonInterceptable.
* @used-by self::isAvailable()
*/
final function assignData(_DO $o):self {
/**
* 2016-05-03
* https://mage2.pro/t/718/3
* Раньше тут стояло:
* $this->ii()->addData($data->getData());
* Это имитировало аналогичный код метода
* @see \Magento\Payment\Model\Method\AbstractMethod::assignData()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L772-L776
* if (is_array($data)) {
* $this->getInfoInstance()->addData($data);
* }
* elseif ($data instanceof \Magento\Framework\DataObject) {
* $this->getInfoInstance()->addData($data->getData());
* }
* Однако из новой версии метода
* @see \Magento\Payment\Model\Method\AbstractMethod::assignData()
* этот код пропал:
* https://github.com/magento/magento2/blob/ee6159/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L763-L792
* https://github.com/magento/magento2/commit/e4225bd7
*
* Раньше (до https://github.com/magento/magento2/commit/e4225bd7 )
* дополнительные данные приходили в $data->getData(),
* однако теперь они упакованы внутрь additional_data.
* @var array(string => mixed) $iia
*/
$iia = $o['additional_data'] ?: $o->getData();
foreach ($this->iiaKeys() as $k) {/** @var string $k */
if (!is_null($v = dfa($iia, $k))) {/** @var string|null $v */
$this->iiaSet($k, $v);
}
}
/**
* 2017-10-12
* I have removed the `payment_method_assign_data`
* and `payment_method_assign_data_{$this->getCode()}` events triggering, because
* 1) I do not use them
* 2) The M2 core does not use them for my modules.
* It uses it for Vault: @see \Magento\Vault\Observer\VaultEnableAssigner::execute()
* But I do not use the core's Vault.
* 3) Now I call assignData() one more time manually: @see \Df\Payment\Method::isAvailable(),
* and I do not want the same events were triggered mutiple times.
* The removed code is here:
* https://github.com/mage2pro/core/blob/3.1.1/Payment/Method.php#L286-L300
* df_dispatch("payment_method_assign_data_{$this->getCode()}", $eventParams = [
* AssignObserver::METHOD_CODE => $this,
* 'payment_model' => $this->ii(),
* AssignObserver::DATA_CODE => $data
* ]);
* df_dispatch('payment_method_assign_data', $eventParams);
*/
return $this;
}
/**
* 2016-02-15
* @override
* @see \Magento\Payment\Model\MethodInterface::authorize()
* @used-by \Magento\Sales\Model\Order\Payment\Operations\AuthorizeOperation::authorize()
* https://github.com/magento/magento2/blob/2.1.5/app/code/Magento/Sales/Model/Order/Payment/Operations/AuthorizeOperation.php#L45
* How is a payment method's authorize() used? https://mage2.pro/t/707
* 2016-09-05
* Отныне валюта платёжных транзакций настраивается администратором опцией
* «Mage2.PRO» → «Payment» → <...> → «Payment Currency»
* @see \Df\Payment\Currency::iso3()
* 2016-08-19
* Со вчерашнего для мои платёжные модули выполняют платёжные транзакции
* не в учётной валюте системы, а в валюте заказа (т.е., витринной валюте).
* Однако это привело к тому, что операция авторизации
* стала помечать заказы (платежи) как «Suspected Fraud» (STATUS_FRAUD).
* Это происходит из-за кода метода
* @see \Magento\Sales\Model\Order\Payment\Operations\AuthorizeOperation::authorize()
* $isSameCurrency = $payment->isSameCurrency();
* if (!$isSameCurrency || !$payment->isCaptureFinal($amount)) {
* $payment->setIsFraudDetected(true);
* }
*
* Метод @see \Magento\Sales\Model\Order\Payment::isSameCurrency() работает так:
* return
* !$this->getCurrencyCode()
* || $this->getCurrencyCode() == $this->getOrder()->getBaseCurrencyCode()
* ;
* По умолчанию $this->getCurrencyCode() возвращает null,
* и поэтому isSameCurrency() возвращает true.
* Magento, получается, думает, что платёж выполняется в учёной валюте системы,
* но вызов $payment->isCaptureFinal($a) вернёт false,
* потому что $a — размер платежа в учётной валюте системы, а метод устроен так:
* @see \Magento\Sales\Model\Order\Payment::isCaptureFinal()
* $total = $this->getOrder()->getTotalDue();
* return
* $this->amountFormat($total, true)
* ==
* $this->amountFormat($amountToCapture, true)
* ;
* Т.е. метод сравнивает размер подлежащей оплате стоимости заказа в валюте заказа
* с размером текущего платежа, который в учётной валюте системы,
* и поэтому вот метод возвращает false.
* Самым разумным решением этой проблемы мне показалось ручное убирание флага IsFraudDetected
* 2017-04-08
* Отныне аргумент $a намеренно игнорируем с целью упрощения системы,
* потому что это значение мы можем получить в любой удобный момент самостоятельно
* посредством @see dfp_due()
* 2021-07-01
* $a is a string because it is a result of the @see \Magento\Sales\Model\Order\Payment::formatAmount() call:
* $amount = $payment->formatAmount($amount, true);
* https://github.com/magento/magento2/blob/2.3.5-p2/app/code/Magento/Sales/Model/Order/Payment/Operations/AuthorizeOperation.php#L36
* 2022-10-19
* We can use `final` in the method's signature despite if M2 code generation
* because the class implements @see INonInterceptable.
* @param string|float $a
* В спецификации PHPDoc интерфейса указано, что метод должен возвращать $this,
* но реально возвращаемое значение ядром не используется.
*/
final function authorize(II $i, $a):self {return $this->action(function() use($i) {
if ($i instanceof OP) {
$i->setIsFraudDetected(false);
}
$this->charge(false);
return $this;
});}
/**
* 2016-02-09
* @override
* https://mage2.pro/t/644
* The method canAuthorize() should be removed from the interface
* @see \Magento\Payment\Model\MethodInterface,
* because it is used only by a particular interface's implementation
* @see \Magento\Payment\Model\Method\AbstractMethod
* and by vault payment methods.
*
* @see \Magento\Payment\Model\MethodInterface::canAuthorize()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L63-L69
* @see \Magento\Payment\Model\Method\AbstractMethod::canAuthorize()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L297-L306
*/
final function canAuthorize():bool {df_should_not_be_here(); return false;}
/**
* 2016-02-09
* @override
* https://mage2.pro/tags/capture
* Важно для витрины вернуть true, чтобы
* @see Df_Payment_Model_Action_Confirm::process() и другие аналогичные методы
* (например, @see Df_Alfabank_Model_Action_CustomerReturn::process())
* могли вызвать @see Mage_Sales_Model_Order_Invoice::capture().
*
* Для административной части возвращайте true только в том случае,
* если метод оплаты реально поддерживает операцию capture
* (т.е. имеет класс Df_XXX_Model_Request_Capture).
* Реализация этого класса позволит проводить двуступенчатую оплату:
* резервирование средств непосредственно в процессе оформления заказа
* и снятие средств посредством нажатия кнопки «Принять оплату» («Capture»)
* на административной странице счёта.
*
* Обратите внимание, что двуступенчатая оплата
* имеет смысл не только для дочернего данному класса @see Df_Payment_Model_Method_WithRedirect,
* но и для других прямых детей класса @see Df_Payment_Model_Method.
* @todo Например, правильным будет сделать оплату двуступенчатой для модуля «Квитанция Сбербанка»,
* потому что непосредственно по завершению заказа
* неправильно переводить счёт в состояние «Оплачен»
* (ведь он не оплачен! покупатель получил просто ссылку на квитанцию и далеко неочевидно,
* что он оплатит эту квитанцию).
* Вместо этого правильно будет оставлять счёт в открытом состоянии
* и переводить его в оплаченное состояние только после оплаты.
*
* @see \Magento\Payment\Model\MethodInterface::canCapture()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L71-L77
* @see \Magento\Payment\Model\Method\AbstractMethod::canCapture()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L308-L317
*
* USAGES
* How is payment method's canCapture() used? https://mage2.pro/t/645
* How is @see \Magento\Sales\Model\Order\Payment::canCapture() used? https://mage2.pro/t/650
*
* 2016-09-30
* Сегодня заметил, что метод @uses \Magento\Framework\App\State::getAreaCode()
* стал возвращать значение @see \Magento\Framework\App\Area::AREA_WEBAPI_REST
* при выполнении платежа на витрине.
*
* 2016-09-30
* Используемые константы присутствуют уже в релизе 2.0.0, потому использовать их безопасно:
* https://github.com/magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/App/Area.php
*
* 2017-12-07
* 1) @used-by \Magento\Sales\Model\Order\Payment::canCapture():
* if (!$this->getMethodInstance()->canCapture()) {
* return false;
* }
* https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Sales/Model/Order/Payment.php#L246-L269
* https://github.com/magento/magento2/blob/2.2.1/app/code/Magento/Sales/Model/Order/Payment.php#L277-L301
* 2) @used-by \Magento\Sales\Model\Order\Payment::_invoice():
* protected function _invoice() {
* $invoice = $this->getOrder()->prepareInvoice();
* $invoice->register();
* if ($this->getMethodInstance()->canCapture()) {
* $invoice->capture();
* }
* $this->getOrder()->addRelatedObject($invoice);
* return $invoice;
* }
* https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Sales/Model/Order/Payment.php#L509-L526
* https://github.com/magento/magento2/blob/2.2.1/app/code/Magento/Sales/Model/Order/Payment.php#L542-L560
* 3) @used-by \Magento\Sales\Model\Order\Payment\Operations\AbstractOperation::invoice():
* protected function invoice(OrderPaymentInterface $payment) {
* $invoice = $payment->getOrder()->prepareInvoice();
* $invoice->register();
* if ($payment->getMethodInstance()->canCapture()) {
* $invoice->capture();
* }
* $payment->getOrder()->addRelatedObject($invoice);
* return $invoice;
* }
* https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Sales/Model/Order/Payment/Operations/AbstractOperation.php#L56-L75
* https://github.com/magento/magento2/blob/2.2.1/app/code/Magento/Sales/Model/Order/Payment/Operations/AbstractOperation.php#L59-L78
* @see \Df\StripeClone\Method::canCapture()
* @see \Dfe\AlphaCommerceHub\Method::canCapture()
* @see \Dfe\CheckoutCom\Method::canCapture()
* @see \Dfe\TwoCheckout\Method::canCapture()
*/
function canCapture():bool {return df_area_code_is(Area::AREA_FRONTEND, Area::AREA_WEBAPI_REST);}
/**
* 2016-02-10
* @override
* https://mage2.pro/tags/capture
* https://mage2.pro/t/658
* The @see \Magento\Payment\Model\MethodInterface::canCaptureOnce() is never used
* @see \Magento\Payment\Model\MethodInterface::canCaptureOnce()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L87-L93
* @see \Magento\Payment\Model\Method\AbstractMethod::canCaptureOnce()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L330-L339
*/
final function canCaptureOnce():bool {df_should_not_be_here(); return false;}
/**
* 2016-02-09
* @override
* https://mage2.pro/tags/capture
*
* @see \Magento\Payment\Model\MethodInterface::canCapturePartial()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L79-L85
* @see \Magento\Payment\Model\Method\AbstractMethod::canCapturePartial()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L325-L328
*
* USAGES
* How is payment method's canCapturePartial() used?
* https://mage2.pro/t/648
*
* How is @see \Magento\Sales\Model\Order\Payment::canCapturePartial() used?
* https://mage2.pro/t/649
*
* @used-by \Magento\Sales\Model\Order\Payment::canCapturePartial()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Sales/Model/Order/Payment.php#L302-L305
*
* 2017-02-08
* @see \Dfe\CheckoutCom\Method::canCapturePartial()
* @see \Dfe\Omise\Method::canCapturePartial()
* @see \Dfe\Spryng\Method::canCapturePartial()
* @see \Dfe\Stripe\Method::canCapturePartial()
* @see \Dfe\TBCBank\Method::canCapturePartial()
*/
function canCapturePartial():bool {return false;}
/**
* 2016-02-15
* @override
* "How is a payment method's cancel() used?" https://mage2.pro/t/710
* @see \Magento\Payment\Model\MethodInterface::cancel()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L279-L286
* @see \Magento\Payment\Model\Method\AbstractMethod::cancel()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L658-L669
* 2022-10-19
* We can use `final` in the method's signature despite if M2 code generation
* because the class implements @see INonInterceptable.
*/
final function cancel(II $payment):self {return $this;}
/**
* 2016-02-10
* @override
* "How is a payment method's canEdit() used?" https://mage2.pro/t/672
* "How is \Magento\Sales\Model\Order::canEdit() implemented and used?" https://mage2.pro/t/673
* @see \Magento\Payment\Model\MethodInterface::canEdit()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L133-L139
* @see \Magento\Payment\Model\Method\AbstractMethod::canEdit()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L395-L404
*/
final function canEdit():bool {return true;}
/**
* 2016-02-11
* @override
* https://mage2.pro/tags/payment-transaction
* @see \Magento\Payment\Model\MethodInterface::canFetchTransactionInfo()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L141-L147
* @see \Magento\Payment\Model\Method\AbstractMethod::canFetchTransactionInfo()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L406-L415
* USAGES
* https://mage2.pro/t/676
* How is a payment method's canFetchTransactionInfo() used?
* How is @see \Magento\Sales\Model\Order\Payment::canFetchTransactionInfo() implemented and used?
* https://mage2.pro/t/677
*/
final function canFetchTransactionInfo():bool {return false;}
/**
* 2016-02-09
* @override
* "The method canOrder() should be removed from the interface \Magento\Payment\Model\MethodInterface
* because it is not used outside of a particular interface's implementation" https://mage2.pro/t/640
* @see \Magento\Payment\Model\Method\AbstractMethod
* @see \Magento\Payment\Model\MethodInterface::canOrder()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L55-L61
* @see \Magento\Payment\Model\Method\AbstractMethod::canOrder()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L286-L295
*/
final function canOrder():bool {df_should_not_be_here(); return false;}
/**
* 2016-02-10
* @override
* Результат метода говорит системе о том, поддерживает ли способ оплаты
* автоматизированный возврат оплаты покупателю.
* https://mage2.pro/tags/refund
* @see \Magento\Payment\Model\MethodInterface::canRefund()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L95-L101
* @see \Magento\Payment\Model\Method\AbstractMethod::canRefund()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L341-L350
* USAGES
* "How is a payment method's canRefund() used?" https://mage2.pro/t/659
* 2017-12-06
* 1) @used-by \Magento\Sales\Model\Order\Payment::canRefund():
* public function canRefund() {
* return $this->getMethodInstance()->canRefund();
* }
* https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Sales/Model/Order/Payment.php#L271-L277
* https://github.com/magento/magento2/blob/2.2.1/app/code/Magento/Sales/Model/Order/Payment.php#L303-L309
* 2) @used-by \Magento\Sales\Model\Order\Payment::refund()
* $gateway = $this->getMethodInstance();
* $invoice = null;
* if ($gateway->canRefund()) {
* <...>
* }
* https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Sales/Model/Order/Payment.php#L617-L654
* https://github.com/magento/magento2/blob/2.2.1/app/code/Magento/Sales/Model/Order/Payment.php#L655-L698
* 3) @used-by \Magento\Sales\Model\Order\Invoice\Validation\CanRefund::canPartialRefund()
* private function canPartialRefund(MethodInterface $method, InfoInterface $payment) {
* return $method->canRefund() &&
* $method->canRefundPartialPerInvoice() &&
* $payment->getAmountPaid() > $payment->getAmountRefunded();
* }
* https://github.com/magento/magento2/blob/2.2.1/app/code/Magento/Sales/Model/Order/Invoice/Validation/CanRefund.php#L84-L94
* It is since Magento 2.2: https://github.com/magento/magento2/commit/767151b4
* @see \Df\StripeClone\Method::canRefund()
* @see \Dfe\AlphaCommerceHub\Method::canRefund()
* @see \Dfe\CheckoutCom\Method::canRefund()
* @see \Dfe\SecurePay\Method::canRefund()
* @see \Dfe\TwoCheckout\Method::canRefund()
*/
function canRefund():bool {return false;}
/**
* 2016-02-10
* @override
* https://mage2.pro/tags/refund
* @see \Magento\Payment\Model\MethodInterface::canRefundPartialPerInvoice()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L103-L109
* @see \Magento\Payment\Model\Method\AbstractMethod::canRefundPartialPerInvoice()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L352-L361
* USAGES
* "How is a payment method's canRefundPartialPerInvoice() used?" https://mage2.pro/t/663
* 2017-02-08
* @see \Df\StripeClone\Method::canRefundPartialPerInvoice()
* @see \Dfe\CheckoutCom\Method::canRefundPartialPerInvoice()
* @see \Dfe\TwoCheckout\Method::canRefundPartialPerInvoice()
*/
function canRefundPartialPerInvoice():bool {return false;}
/**
* 2016-02-15
* @override
* "How is a payment method's canReviewPayment() used?" https://mage2.pro/t/714
* 2016-03-08
* http://stackoverflow.com/a/12814128
* «Magento's Order View block will check $order->canReviewPayment()
* which will look at the _canReviewPayment variable on the payment method,
* and if true, display two buttons on the Order View :
* "Accept Payment" and "Deny Payment".»
* @see \Magento\Payment\Model\MethodInterface::canReviewPayment()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L297-L302
* @see \Magento\Payment\Model\Method\AbstractMethod::canReviewPayment()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L688-L696
* 2017-02-08
* @see \Df\StripeClone\Method::canReviewPayment()
* @see \Dfe\CheckoutCom\Method::canReviewPayment()
*/
function canReviewPayment():bool {return false;}
/**
* 2016-02-10
* @override
* The same as @see \Df\Payment\Method::canUseInternal(), but it is used for the frontend only.
* https://mage2.pro/t/671
* https://mage2.pro/tags/payment-can-use
* @see \Magento\Payment\Model\MethodInterface::canUseCheckout()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L126-L131
* @see \Magento\Payment\Model\Method\AbstractMethod::canUseCheckout()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L156-L161
*/
final function canUseCheckout():bool {return true;}
/**
* 2016-02-11
* 2017-03-04
* Этот метод решает, должен ли способ оплаты быть доступен для конкретной страны покупателя.
* Страна покупателя вычисляется методом
* @see \Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider::getCountry()
* public function getCountry(Quote $quote)
* {
* $address = $quote->getBillingAddress() ? : $quote->getShippingAddress();
* return (!empty($address) && !empty($address->getCountry()))
* ? $address->getCountry()
* : $this->directoryHelper->getDefaultCountry();
* }
* https://github.com/magento/magento2/blob/58edd7f2/app/code/Magento/Payment/Model/Checks/CanUseForCountry/CountryProvider.php#L33-L45
* @override
* @see \Magento\Payment\Model\MethodInterface::canUseForCountry()
* @used-by \Df\Payment\Plugin\Model\Checks\CanUseForCountry::aroundIsApplicable()
* @used-by \Magento\Payment\Model\Checks\CanUseForCountry::isApplicable()
* How is a payment method's canUseForCountry() used? https://mage2.pro/t/682
* @param string $c 2022-11-26 We can not declare the argument's type because it is undeclared in the overriden method.
*/
final function canUseForCountry($c):bool {return $this->canUseForCountryP($c);}
/**
* 2017-12-13
* "Provide an ability to the Magento backend users (merchants) to set up country restrictions separately
* for each AlphaCommerceHub's payment option (bank cards, PayPal, POLi Payments, etc.)":
* https://github.com/mage2pro/alphacommercehub/issues/85
* @used-by self::canUseForCountry()
* @used-by \Df\Payment\Settings::applicableForQuoteByCountry()
*/
final function canUseForCountryP(string $c, string $p = ''):bool {
$p = !$p ? $p : df_add_ds_right($p);
return NWB::is($this->s("{$p}country_restriction"), $c, df_csv_parse($this->s("{$p}countries")));
}
/**
* 2016-02-11
* @override
* How is a payment method's canUseForCurrency() used? https://mage2.pro/t/684
* @see \Magento\Payment\Model\MethodInterface::canUseForCurrency()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L192-L199
* @see \Magento\Payment\Model\Method\AbstractMethod::canUseForCurrency()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L484-L494
* @param string $c 2022-11-26 We can not declare the argument's type because it is undeclared in the overriden method.
*/
final function canUseForCurrency($c):bool {return true;}
/**
* 2016-02-10
* @override
* Place in your custom canUseInternal() method a custom logic to decide
* whether the payment method need to be shown to a customer on the checkout screen.
* By default there is no custom login and the method just returns true.
* https://mage2.pro/t/670
* https://mage2.pro/tags/payment-can-use
* @see \Magento\Payment\Model\MethodInterface::canUseInternal()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L118-L124
* @see \Magento\Payment\Model\Method\AbstractMethod::canUseInternal()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L149-L154
*/
final function canUseInternal():bool {return true;}
/**
* 2016-02-10
* @override
* Результат метода говорит системе о том, поддерживает ли способ оплаты
* автоматизированное разблокирование (возврат покупателю)
* ранее зарезервированных (но не снятых со счёта покупателя) средств
* https://mage2.pro/tags/void
*
* @see \Magento\Payment\Model\MethodInterface::canVoid()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L111-L116
* @see \Magento\Payment\Model\Method\AbstractMethod::canVoid()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L363-L372
*
* USAGES
* "How is a payment method's canVoid() used?" https://mage2.pro/t/666
* How is @see \Magento\Sales\Model\Order\Payment::canVoid() implemented and used?
* https://mage2.pro/t/667
*
* 2017-12-08
* @used-by \Magento\Sales\Model\Order\Payment::canVoid():
* public function canVoid() {
* if (null === $this->_canVoidLookup) {
* $this->_canVoidLookup = (bool)$this->getMethodInstance()->canVoid();
* if ($this->_canVoidLookup) {
* $authTransaction = $this->getAuthorizationTransaction();
* $this->_canVoidLookup = (bool)$authTransaction && !(int)$authTransaction->getIsClosed();
* }
* }
* return $this->_canVoidLookup;
* }
* https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Sales/Model/Order/Payment.php#L528-L543
* https://github.com/magento/magento2/blob/2.2.1/app/code/Magento/Sales/Model/Order/Payment.php#L562-L578
* @see \Df\StripeClone\Method::canVoid()
* @see \Dfe\AlphaCommerceHub\Method::canVoid()
* @see \Dfe\CheckoutCom\Method::canVoid()
*/
function canVoid():bool {return false;}
/**
* 2016-02-15
* @override
* How is a payment method's capture() used? https://mage2.pro/t/708
*
* Используется только отсюда:
* @used-by \Magento\Sales\Model\Order\Payment\Operations\CaptureOperation::capture()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Sales/Model/Order/Payment/Operations/CaptureOperation.php#L76-L82
* Параметр $payment можно игнорировать, потому что он уже доступен в виде свойства объекта.
*
* $a содержит значение в учётной валюте системы.
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Sales/Model/Order/Payment/Operations/CaptureOperation.php#L37-L37
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Sales/Model/Order/Payment/Operations/CaptureOperation.php#L76-L82
*
* @see \Magento\Payment\Model\MethodInterface::capture()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L259-L267
* @see \Magento\Payment\Model\Method\AbstractMethod::capture()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L621-L638
*
* 2017-04-08
* Отныне аргумент $a намеренно игнорируем с целью упрощения системы,
* потому что это значение мы можем получить в любой удобный момент самостоятельно
* посредством @see dfp_due()
*
* 2021-07-01
* $a is a string because it is a result of the @see \Magento\Sales\Model\Order\Payment::formatAmount() call:
* $amountToCapture = $payment->formatAmount($invoice->getBaseGrandTotal());
* https://github.com/magento/magento2/blob/2.3.5-p2/app/code/Magento/Sales/Model/Order/Payment/Operations/CaptureOperation.php#L37
*
* 2022-10-19
* We can use `final` in the method's signature despite if M2 code generation
* because the class implements @see INonInterceptable.
*
* @param II|I|OP $payment
* @param string|float $a
* В спецификации PHPDoc интерфейса указано, что метод должен возвращать $this,
* но реально возвращаемое значение ядром не используется.
* @uses charge()
*/
final function capture(II $payment, $a):self {$this->action('charge'); return $this;}
/**
* 2016-08-20
* 2016-09-05
* Отныне валюта платёжных транзакций настраивается администратором опцией
* «Mage2.PRO» → «Payment» → <...> → «Payment Currency»
* 2017-02-08 Конвертирует $a из учётной валюты в валюту платежа.
* @see \Df\Payment\Currency::iso3()
* @used-by dfp_due()
* @used-by self::_void()
* @used-by self::refund()
* @uses \Df\Payment\Currency::fromBase()
*/
final function cFromBase(float $a):float {return $this->convert($a);}
/**
* 2016-09-07 The payment currency code for the current order or quote.
* @used-by self::amountFormat()
* @used-by \Dfe\AlphaCommerceHub\Method::amountFormat()
* @used-by \Dfe\TBCBank\Facade\Charge::capturePreauthorized()
*/
final function cPayment():string {return dfc($this, function() {return $this->currency()->oq($this->oq());});}
/**
* 2016-09-08
* 2017-02-08 Конвертирует $a из валюты платежа в учётную.
* @used-by dfp_refund()
* @uses \Df\Payment\Currency::toBase()
*/
final function cToBase(float $a):float {return $this->convert($a);}
/**
* 2016-09-08
* 2017-02-08 Конвертирует $a из валюты платежа в валюту заказа.
* 2022-11-26 @deprecated It is unused.
* @uses \Df\Payment\Currency::toOrder()
*/
final function cToOrder(float $a):float {return $this->convert($a);}
/**
* 2016-02-15
* @override
* "How is a payment method's denyPayment() used?" https://mage2.pro/t/716
* @see \Magento\Payment\Model\MethodInterface::denyPayment()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L314-L322
* @see \Magento\Payment\Model\Method\AbstractMethod::denyPayment()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L715-L730
* 2017-02-08
* @see \Df\StripeClone\Method::denyPayment()
* @see \Dfe\CheckoutCom\Method::denyPayment()
* @param II|I|OP $p
*/
function denyPayment(II $p):bool {return false;}
/**
* 2016-02-11
* 2022-11-26 We can not declare the $transId argument type because it is undeclared in the overriden method.
* @override
* @see \Magento\Payment\Model\MethodInterface::fetchTransactionInfo()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L149-L158
* @see \Magento\Payment\Model\Method\AbstractMethod::fetchTransactionInfo()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L417-L428
* USAGES
* "How is a payment method's fetchTransactionInfo() used?" https://mage2.pro/t/678
* @param string $transId
* @return array(string => mixed)
*/
final function fetchTransactionInfo(II $p, $transId):array {return [];}
/**
* 2016-02-08
* @override
* @see \Magento\Payment\Model\MethodInterface::getCode()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L17-L23
* @see \Magento\Payment\Model\Method\AbstractMethod::getCode()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L496-L508
*/
final function getCode():string {return self::codeS();}
/**
* 2016-02-15
* @override
* "How is a payment method's getConfigData() used?" https://mage2.pro/t/717
* @see \Magento\Payment\Model\MethodInterface::getConfigData()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L324-L332
* @see \Magento\Payment\Model\Method\AbstractMethod::getConfigData()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L742-L760
* @param string $k 2022-11-26 We can not declare the argument's type because it is undeclared in the overriden method.
* @param null|string|int|ScopeInterface $storeId [optional]
* @return string|null
*/
final function getConfigData($k, $storeId = null) {
static $map = [
/**
* 2016-02-16
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Config.php#L85-L105
* @uses \Df\Payment\Method::isActive()
*/
'active' => 'isActive'
/** 2016-03-08 @uses \Df\Payment\Method::cardTypes() */
,'cctypes' => 'cardTypes'
/**
* 2016-03-15
* @uses \Df\Payment\Method::getConfigPaymentAction()
* Добавил, потому что в одном месте ядра 'payment_action' используется напрямую:
* https://github.com/magento/magento2/blob/2.1.0/app/code/Magento/Sales/Model/Order/Payment.php#L339-L340
*/
,'payment_action' => 'getConfigPaymentAction'
/**
* 2016-02-16
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Helper/Data.php#L265-L274
* @uses \Df\Payment\Method::getTitle()
*/
,'title' => 'getTitle'
];
return isset($map[$k]) ? call_user_func([$this, $map[$k]], $storeId) : $this->s($k);
}
/**
* 2016-02-15 How is a payment method's getConfigPaymentAction() used? https://mage2.pro/t/724
* 2017-11-06 We really need to cache the result with @uses dfc(), because the method is called 3 times.
* @override
* @see \Magento\Payment\Model\MethodInterface::getConfigPaymentAction()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L374-L381
* @see \Magento\Payment\Model\Method\AbstractMethod::getConfigPaymentAction()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L854-L864
* ----
* 1) @used-by \Df\StripeClone\Method::isInitializeNeeded()
* 2) @used-by \Magento\Sales\Model\Order\Payment::place()
* $action = $methodInstance->getConfigPaymentAction();
* https://github.com/magento/magento2/blob/2.2.0/app/code/Magento/Sales/Model/Order/Payment.php#L354
* 3) @used-by \Magento\Sales\Model\Order\Payment::place()
* $methodInstance->initialize($methodInstance->getConfigData('payment_action'), $stateObject);
* https://github.com/magento/magento2/blob/2.2.0/app/code/Magento/Sales/Model/Order/Payment.php#L359-L360
* 'payment_action' => 'getConfigPaymentAction'
* https://github.com/mage2pro/core/blob/3.2.31/Payment/Method.php#L898-L904
* ----
* @see \Dfe\CheckoutCom\Method::getConfigPaymentAction()
*/
function getConfigPaymentAction():string {return dfc($this, function() {return InitAction::sg($this)->action();});}
/**
* 2016-02-08
* @override
* @see \Magento\Payment\Model\MethodInterface::getFormBlockType()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/MethodInterface.php#L25-L32
* @see \Magento\Payment\Model\Method\AbstractMethod::getFormBlockType()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Model/Method/AbstractMethod.php#L510-L518
*
* USAGE
* "How is a payment method's getFormBlockType() used?" https://mage2.pro/t/691
* @used-by \Magento\Payment\Helper\Data::getMethodFormBlock()
* https://github.com/magento/magento2/blob/6ce74b2/app/code/Magento/Payment/Helper/Data.php#L174
*
* 2017-08-24
* The method is used in the following scenarios:
* 1) Backend ordering
* 2) Frontend multishipping
*
* @used-by \Magento\Payment\Helper\Data::getMethodFormBlock():
* public function getMethodFormBlock(MethodInterface $method, LayoutInterface $layout) {
* $block = $layout->createBlock($method->getFormBlockType(), $method->getCode());
* $block->setMethod($method);
* return $block;
* }
* https://github.com/magento/magento2/blob/2.2.0-rc2.1/app/code/Magento/Payment/Helper/Data.php#L169-L181
*
* The @see \Magento\Payment\Helper\Data::getMethodFormBlock() method is used only by
* @see \Magento\Payment\Block\Form\Container::_prepareLayout():
* protected function _prepareLayout() {
* foreach ($this->getMethods() as $method) {
* $this->setChild(
* 'payment.method.' . $method->getCode(),
* $this->_paymentHelper->getMethodFormBlock($method, $this->_layout)
* );
* }
* return parent::_prepareLayout();
* }
* https://github.com/magento/magento2/blob/2.2.0-rc2.1/app/code/Magento/Payment/Block/Form/Container.php#L67-L85
*/
final function getFormBlockType():string {return df_con_hier($this, \Df\Payment\Block\Multishipping::class);}
/**
* 2016-02-11
* @override
* @see \Magento\Payment\Model\MethodInterface::getInfoBlockType()
* How is a payment method's getInfoBlockType() used? https://mage2.pro/t/687
* @used-by \Magento\Payment\Helper\Data::getInfoBlock():
* public function getInfoBlock(InfoInterface $info, LayoutInterface $layout = null) {
* $layout = $layout ?: $this->_layout;
* $blockType = $info->getMethodInstance()->getInfoBlockType();
* $block = $layout->createBlock($blockType);
* $block->setInfo($info);
* return $block;
* }
* https://github.com/magento/magento2/blob/2.2.0-RC1.6/app/code/Magento/Payment/Helper/Data.php#L182-L196
* 2016-08-29 The method is called only one time, so it does not need to cache own result.
* 2017-01-13
* Задействовал @uses df_con_hier(), чтобы подхватывать @see \Df\StripeClone\Block\Info