AbstractMethod.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Model\Method;
  7. use Magento\Framework\App\ObjectManager;
  8. use Magento\Framework\DataObject;
  9. use Magento\Payment\Model\InfoInterface;
  10. use Magento\Payment\Model\MethodInterface;
  11. use Magento\Payment\Observer\AbstractDataAssignObserver;
  12. use Magento\Quote\Api\Data\PaymentMethodInterface;
  13. use Magento\Sales\Model\Order\Payment;
  14. use Magento\Directory\Helper\Data as DirectoryHelper;
  15. /**
  16. * Payment method abstract model
  17. *
  18. * @api
  19. * @SuppressWarnings(PHPMD.ExcessivePublicCount)
  20. * @SuppressWarnings(PHPMD.TooManyFields)
  21. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  22. * @deprecated 100.0.6
  23. * @see \Magento\Payment\Model\Method\Adapter
  24. * @see https://devdocs.magento.com/guides/v2.1/payments-integrations/payment-gateway/payment-gateway-intro.html
  25. * @since 100.0.2
  26. */
  27. abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibleModel implements
  28. MethodInterface,
  29. PaymentMethodInterface
  30. {
  31. const STATUS_UNKNOWN = 'UNKNOWN';
  32. const STATUS_APPROVED = 'APPROVED';
  33. const STATUS_ERROR = 'ERROR';
  34. const STATUS_DECLINED = 'DECLINED';
  35. const STATUS_VOID = 'VOID';
  36. const STATUS_SUCCESS = 'SUCCESS';
  37. /**
  38. * @var string
  39. */
  40. protected $_code;
  41. /**
  42. * @var string
  43. */
  44. protected $_formBlockType = \Magento\Payment\Block\Form::class;
  45. /**
  46. * @var string
  47. */
  48. protected $_infoBlockType = \Magento\Payment\Block\Info::class;
  49. /**
  50. * Payment Method feature
  51. *
  52. * @var bool
  53. */
  54. protected $_isGateway = false;
  55. /**
  56. * Payment Method feature
  57. *
  58. * @var bool
  59. */
  60. protected $_isOffline = false;
  61. /**
  62. * Payment Method feature
  63. *
  64. * @var bool
  65. */
  66. protected $_canOrder = false;
  67. /**
  68. * Payment Method feature
  69. *
  70. * @var bool
  71. */
  72. protected $_canAuthorize = false;
  73. /**
  74. * Payment Method feature
  75. *
  76. * @var bool
  77. */
  78. protected $_canCapture = false;
  79. /**
  80. * Payment Method feature
  81. *
  82. * @var bool
  83. */
  84. protected $_canCapturePartial = false;
  85. /**
  86. * Payment Method feature
  87. *
  88. * @var bool
  89. */
  90. protected $_canCaptureOnce = false;
  91. /**
  92. * Payment Method feature
  93. *
  94. * @var bool
  95. */
  96. protected $_canRefund = false;
  97. /**
  98. * Payment Method feature
  99. *
  100. * @var bool
  101. */
  102. protected $_canRefundInvoicePartial = false;
  103. /**
  104. * Payment Method feature
  105. *
  106. * @var bool
  107. */
  108. protected $_canVoid = false;
  109. /**
  110. * Payment Method feature
  111. *
  112. * @var bool
  113. */
  114. protected $_canUseInternal = true;
  115. /**
  116. * Payment Method feature
  117. *
  118. * @var bool
  119. */
  120. protected $_canUseCheckout = true;
  121. /**
  122. * Payment Method feature
  123. *
  124. * @var bool
  125. */
  126. protected $_isInitializeNeeded = false;
  127. /**
  128. * Payment Method feature
  129. *
  130. * @var bool
  131. */
  132. protected $_canFetchTransactionInfo = false;
  133. /**
  134. * Payment Method feature
  135. *
  136. * @var bool
  137. */
  138. protected $_canReviewPayment = false;
  139. /**
  140. * TODO: whether a captured transaction may be voided by this gateway
  141. * This may happen when amount is captured, but not settled
  142. * @var bool
  143. */
  144. protected $_canCancelInvoice = false;
  145. /**
  146. * Fields that should be replaced in debug with '***'
  147. *
  148. * @var array
  149. */
  150. protected $_debugReplacePrivateDataKeys = [];
  151. /**
  152. * Payment data
  153. *
  154. * @var \Magento\Payment\Helper\Data
  155. */
  156. protected $_paymentData;
  157. /**
  158. * Core store config
  159. *
  160. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  161. */
  162. protected $_scopeConfig;
  163. /**
  164. * @var Logger
  165. */
  166. protected $logger;
  167. /**
  168. * @var DirectoryHelper
  169. */
  170. private $directory;
  171. /**
  172. * @param \Magento\Framework\Model\Context $context
  173. * @param \Magento\Framework\Registry $registry
  174. * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
  175. * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
  176. * @param \Magento\Payment\Helper\Data $paymentData
  177. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  178. * @param Logger $logger
  179. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  180. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  181. * @param array $data
  182. * @param DirectoryHelper $directory
  183. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  184. */
  185. public function __construct(
  186. \Magento\Framework\Model\Context $context,
  187. \Magento\Framework\Registry $registry,
  188. \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
  189. \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
  190. \Magento\Payment\Helper\Data $paymentData,
  191. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
  192. \Magento\Payment\Model\Method\Logger $logger,
  193. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  194. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  195. array $data = [],
  196. DirectoryHelper $directory = null
  197. ) {
  198. parent::__construct(
  199. $context,
  200. $registry,
  201. $extensionFactory,
  202. $customAttributeFactory,
  203. $resource,
  204. $resourceCollection,
  205. $data
  206. );
  207. $this->_paymentData = $paymentData;
  208. $this->_scopeConfig = $scopeConfig;
  209. $this->logger = $logger;
  210. $this->directory = $directory ?: ObjectManager::getInstance()->get(DirectoryHelper::class);
  211. $this->initializeData($data);
  212. }
  213. /**
  214. * Initializes injected data
  215. *
  216. * @param array $data
  217. * @return void
  218. */
  219. protected function initializeData($data = [])
  220. {
  221. if (!empty($data['formBlockType'])) {
  222. $this->_formBlockType = $data['formBlockType'];
  223. }
  224. }
  225. /**
  226. * @inheritdoc
  227. * @deprecated 100.2.0
  228. */
  229. public function setStore($storeId)
  230. {
  231. $this->setData('store', (int)$storeId);
  232. }
  233. /**
  234. * @inheritdoc
  235. * @deprecated 100.2.0
  236. */
  237. public function getStore()
  238. {
  239. return $this->getData('store');
  240. }
  241. /**
  242. * Check order availability
  243. *
  244. * @return bool
  245. * @api
  246. * @deprecated 100.2.0
  247. */
  248. public function canOrder()
  249. {
  250. return $this->_canOrder;
  251. }
  252. /**
  253. * Check authorize availability
  254. *
  255. * @return bool
  256. * @api
  257. * @deprecated 100.2.0
  258. */
  259. public function canAuthorize()
  260. {
  261. return $this->_canAuthorize;
  262. }
  263. /**
  264. * Check capture availability
  265. *
  266. * @return bool
  267. * @api
  268. * @deprecated 100.2.0
  269. */
  270. public function canCapture()
  271. {
  272. return $this->_canCapture;
  273. }
  274. /**
  275. * Check partial capture availability
  276. *
  277. * @return bool
  278. * @api
  279. * @deprecated 100.2.0
  280. */
  281. public function canCapturePartial()
  282. {
  283. return $this->_canCapturePartial;
  284. }
  285. /**
  286. * Check whether capture can be performed once and no further capture possible
  287. *
  288. * @return bool
  289. * @api
  290. * @deprecated 100.2.0
  291. */
  292. public function canCaptureOnce()
  293. {
  294. return $this->_canCaptureOnce;
  295. }
  296. /**
  297. * Check refund availability
  298. *
  299. * @return bool
  300. * @api
  301. * @deprecated 100.2.0
  302. */
  303. public function canRefund()
  304. {
  305. return $this->_canRefund;
  306. }
  307. /**
  308. * Check partial refund availability for invoice
  309. *
  310. * @return bool
  311. * @api
  312. * @deprecated 100.2.0
  313. */
  314. public function canRefundPartialPerInvoice()
  315. {
  316. return $this->_canRefundInvoicePartial;
  317. }
  318. /**
  319. * Check void availability.
  320. *
  321. * @return bool
  322. * @internal param \Magento\Framework\DataObject $payment
  323. * @api
  324. * @deprecated 100.2.0
  325. */
  326. public function canVoid()
  327. {
  328. return $this->_canVoid;
  329. }
  330. /**
  331. * Using internal pages for input payment data.
  332. *
  333. * Can be used in admin.
  334. *
  335. * @return bool
  336. * @deprecated 100.2.0
  337. */
  338. public function canUseInternal()
  339. {
  340. return $this->_canUseInternal;
  341. }
  342. /**
  343. * Can be used in regular checkout
  344. *
  345. * @return bool
  346. * @deprecated 100.2.0
  347. */
  348. public function canUseCheckout()
  349. {
  350. return $this->_canUseCheckout;
  351. }
  352. /**
  353. * Can be edit order (renew order)
  354. *
  355. * @return bool
  356. * @api
  357. * @deprecated 100.2.0
  358. */
  359. public function canEdit()
  360. {
  361. return true;
  362. }
  363. /**
  364. * Check fetch transaction info availability
  365. *
  366. * @return bool
  367. * @api
  368. * @deprecated 100.2.0
  369. */
  370. public function canFetchTransactionInfo()
  371. {
  372. return $this->_canFetchTransactionInfo;
  373. }
  374. /**
  375. * Fetch transaction info
  376. *
  377. * @param InfoInterface $payment
  378. * @param string $transactionId
  379. * @return array
  380. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  381. * @api
  382. * @deprecated 100.2.0
  383. */
  384. public function fetchTransactionInfo(InfoInterface $payment, $transactionId)
  385. {
  386. return [];
  387. }
  388. /**
  389. * Retrieve payment system relation flag
  390. *
  391. * @return bool
  392. * @api
  393. * @deprecated 100.2.0
  394. */
  395. public function isGateway()
  396. {
  397. return $this->_isGateway;
  398. }
  399. /**
  400. * Retrieve payment method online/offline flag
  401. *
  402. * @return bool
  403. * @api
  404. * @deprecated 100.2.0
  405. */
  406. public function isOffline()
  407. {
  408. return $this->_isOffline;
  409. }
  410. /**
  411. * Flag if we need to run payment initialize while order place
  412. *
  413. * @return bool
  414. * @api
  415. * @deprecated 100.2.0
  416. */
  417. public function isInitializeNeeded()
  418. {
  419. return $this->_isInitializeNeeded;
  420. }
  421. /**
  422. * To check billing country is allowed for the payment method
  423. *
  424. * @param string $country
  425. * @return bool
  426. * @deprecated 100.2.0
  427. */
  428. public function canUseForCountry($country)
  429. {
  430. /*
  431. for specific country, the flag will set up as 1
  432. */
  433. if ($this->getConfigData('allowspecific') == 1) {
  434. $availableCountries = explode(',', $this->getConfigData('specificcountry'));
  435. if (!in_array($country, $availableCountries)) {
  436. return false;
  437. }
  438. }
  439. return true;
  440. }
  441. /**
  442. * Check method for processing with base currency
  443. *
  444. * @param string $currencyCode
  445. * @return bool
  446. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  447. * @deprecated 100.2.0
  448. */
  449. public function canUseForCurrency($currencyCode)
  450. {
  451. return true;
  452. }
  453. /**
  454. * Retrieve payment method code
  455. *
  456. * @return string
  457. * @throws \Magento\Framework\Exception\LocalizedException
  458. * @deprecated 100.2.0
  459. */
  460. public function getCode()
  461. {
  462. if (empty($this->_code)) {
  463. throw new \Magento\Framework\Exception\LocalizedException(
  464. __('We cannot retrieve the payment method code.')
  465. );
  466. }
  467. return $this->_code;
  468. }
  469. /**
  470. * Retrieve block type for method form generation
  471. *
  472. * @return string
  473. * @deprecated 100.2.0
  474. */
  475. public function getFormBlockType()
  476. {
  477. return $this->_formBlockType;
  478. }
  479. /**
  480. * Retrieve block type for display method information
  481. *
  482. * @return string
  483. * @api
  484. * @deprecated 100.2.0
  485. */
  486. public function getInfoBlockType()
  487. {
  488. return $this->_infoBlockType;
  489. }
  490. /**
  491. * Retrieve payment information model object
  492. *
  493. * @return InfoInterface
  494. * @throws \Magento\Framework\Exception\LocalizedException
  495. * @api
  496. * @deprecated 100.2.0
  497. */
  498. public function getInfoInstance()
  499. {
  500. $instance = $this->getData('info_instance');
  501. if (!$instance instanceof InfoInterface) {
  502. throw new \Magento\Framework\Exception\LocalizedException(
  503. __('We cannot retrieve the payment information object instance.')
  504. );
  505. }
  506. return $instance;
  507. }
  508. /**
  509. * Retrieve payment information model object
  510. *
  511. * @param InfoInterface $info
  512. * @return void
  513. * @api
  514. * @deprecated 100.2.0
  515. */
  516. public function setInfoInstance(InfoInterface $info)
  517. {
  518. $this->setData('info_instance', $info);
  519. }
  520. /**
  521. * Validate payment method information object
  522. *
  523. * @return $this
  524. * @throws \Magento\Framework\Exception\LocalizedException
  525. * @api
  526. * @deprecated 100.2.0
  527. */
  528. public function validate()
  529. {
  530. /**
  531. * to validate payment method is allowed for billing country or not
  532. */
  533. $paymentInfo = $this->getInfoInstance();
  534. if ($paymentInfo instanceof Payment) {
  535. $billingCountry = $paymentInfo->getOrder()->getBillingAddress()->getCountryId();
  536. } else {
  537. $billingCountry = $paymentInfo->getQuote()->getBillingAddress()->getCountryId();
  538. }
  539. $billingCountry = $billingCountry ?: $this->directory->getDefaultCountry();
  540. if (!$this->canUseForCountry($billingCountry)) {
  541. throw new \Magento\Framework\Exception\LocalizedException(
  542. __('You can\'t use the payment type you selected to make payments to the billing country.')
  543. );
  544. }
  545. return $this;
  546. }
  547. /**
  548. * Order payment abstract method
  549. *
  550. * @param \Magento\Framework\DataObject|InfoInterface $payment
  551. * @param float $amount
  552. * @return $this
  553. * @throws \Magento\Framework\Exception\LocalizedException
  554. * @api
  555. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  556. * @deprecated 100.2.0
  557. */
  558. public function order(\Magento\Payment\Model\InfoInterface $payment, $amount)
  559. {
  560. if (!$this->canOrder()) {
  561. throw new \Magento\Framework\Exception\LocalizedException(__('The order action is not available.'));
  562. }
  563. return $this;
  564. }
  565. /**
  566. * Authorize payment abstract method
  567. *
  568. * @param \Magento\Framework\DataObject|InfoInterface $payment
  569. * @param float $amount
  570. * @return $this
  571. * @throws \Magento\Framework\Exception\LocalizedException
  572. * @api
  573. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  574. * @deprecated 100.2.0
  575. */
  576. public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)
  577. {
  578. if (!$this->canAuthorize()) {
  579. throw new \Magento\Framework\Exception\LocalizedException(__('The authorize action is not available.'));
  580. }
  581. return $this;
  582. }
  583. /**
  584. * Capture payment abstract method
  585. *
  586. * @param \Magento\Framework\DataObject|InfoInterface $payment
  587. * @param float $amount
  588. * @return $this
  589. * @throws \Magento\Framework\Exception\LocalizedException
  590. * @api
  591. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  592. * @deprecated 100.2.0
  593. */
  594. public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
  595. {
  596. if (!$this->canCapture()) {
  597. throw new \Magento\Framework\Exception\LocalizedException(__('The capture action is not available.'));
  598. }
  599. return $this;
  600. }
  601. /**
  602. * Refund specified amount for payment
  603. *
  604. * @param \Magento\Framework\DataObject|InfoInterface $payment
  605. * @param float $amount
  606. * @return $this
  607. * @throws \Magento\Framework\Exception\LocalizedException
  608. * @api
  609. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  610. * @deprecated 100.2.0
  611. */
  612. public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
  613. {
  614. if (!$this->canRefund()) {
  615. throw new \Magento\Framework\Exception\LocalizedException(__('The refund action is not available.'));
  616. }
  617. return $this;
  618. }
  619. /**
  620. * Cancel payment abstract method
  621. *
  622. * @param \Magento\Framework\DataObject|InfoInterface $payment
  623. * @return $this
  624. * @api
  625. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  626. * @deprecated 100.2.0
  627. */
  628. public function cancel(\Magento\Payment\Model\InfoInterface $payment)
  629. {
  630. return $this;
  631. }
  632. /**
  633. * Void payment abstract method
  634. *
  635. * @param \Magento\Framework\DataObject|InfoInterface $payment
  636. * @return $this
  637. * @throws \Magento\Framework\Exception\LocalizedException
  638. * @api
  639. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  640. * @deprecated 100.2.0
  641. */
  642. public function void(\Magento\Payment\Model\InfoInterface $payment)
  643. {
  644. if (!$this->canVoid()) {
  645. throw new \Magento\Framework\Exception\LocalizedException(__('The void action is not available.'));
  646. }
  647. return $this;
  648. }
  649. /**
  650. * Whether this method can accept or deny payment.
  651. *
  652. * @return bool
  653. * @api
  654. * @deprecated 100.2.0
  655. */
  656. public function canReviewPayment()
  657. {
  658. return $this->_canReviewPayment;
  659. }
  660. /**
  661. * Attempt to accept a payment that us under review
  662. *
  663. * @param InfoInterface $payment
  664. * @return false
  665. * @throws \Magento\Framework\Exception\LocalizedException
  666. * @api
  667. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  668. * @deprecated 100.2.0
  669. */
  670. public function acceptPayment(InfoInterface $payment)
  671. {
  672. if (!$this->canReviewPayment()) {
  673. throw new \Magento\Framework\Exception\LocalizedException(__('The payment review action is unavailable.'));
  674. }
  675. return false;
  676. }
  677. /**
  678. * Attempt to deny a payment that us under review
  679. *
  680. * @param InfoInterface $payment
  681. * @return false
  682. * @throws \Magento\Framework\Exception\LocalizedException
  683. * @api
  684. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  685. * @deprecated 100.2.0
  686. */
  687. public function denyPayment(InfoInterface $payment)
  688. {
  689. if (!$this->canReviewPayment()) {
  690. throw new \Magento\Framework\Exception\LocalizedException(__('The payment review action is unavailable.'));
  691. }
  692. return false;
  693. }
  694. /**
  695. * Retrieve payment method title
  696. *
  697. * @return string
  698. * @deprecated 100.2.0
  699. */
  700. public function getTitle()
  701. {
  702. return $this->getConfigData('title');
  703. }
  704. /**
  705. * Retrieve information from payment configuration
  706. *
  707. * @param string $field
  708. * @param int|string|null|\Magento\Store\Model\Store $storeId
  709. *
  710. * @return mixed
  711. * @deprecated 100.2.0
  712. */
  713. public function getConfigData($field, $storeId = null)
  714. {
  715. if ('order_place_redirect_url' === $field) {
  716. return $this->getOrderPlaceRedirectUrl();
  717. }
  718. if (null === $storeId) {
  719. $storeId = $this->getStore();
  720. }
  721. $path = 'payment/' . $this->getCode() . '/' . $field;
  722. return $this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
  723. }
  724. /**
  725. * Assign data to info model instance
  726. *
  727. * @param array|\Magento\Framework\DataObject $data
  728. * @return $this
  729. * @throws \Magento\Framework\Exception\LocalizedException
  730. * @api
  731. * @deprecated 100.2.0
  732. */
  733. public function assignData(\Magento\Framework\DataObject $data)
  734. {
  735. $this->_eventManager->dispatch(
  736. 'payment_method_assign_data_' . $this->getCode(),
  737. [
  738. AbstractDataAssignObserver::METHOD_CODE => $this,
  739. AbstractDataAssignObserver::MODEL_CODE => $this->getInfoInstance(),
  740. AbstractDataAssignObserver::DATA_CODE => $data
  741. ]
  742. );
  743. $this->_eventManager->dispatch(
  744. 'payment_method_assign_data',
  745. [
  746. AbstractDataAssignObserver::METHOD_CODE => $this,
  747. AbstractDataAssignObserver::MODEL_CODE => $this->getInfoInstance(),
  748. AbstractDataAssignObserver::DATA_CODE => $data
  749. ]
  750. );
  751. return $this;
  752. }
  753. /**
  754. * Check whether payment method can be used
  755. *
  756. * @param \Magento\Quote\Api\Data\CartInterface|null $quote
  757. * @return bool
  758. * @deprecated 100.2.0
  759. */
  760. public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
  761. {
  762. if (!$this->isActive($quote ? $quote->getStoreId() : null)) {
  763. return false;
  764. }
  765. $checkResult = new DataObject();
  766. $checkResult->setData('is_available', true);
  767. // for future use in observers
  768. $this->_eventManager->dispatch(
  769. 'payment_method_is_active',
  770. [
  771. 'result' => $checkResult,
  772. 'method_instance' => $this,
  773. 'quote' => $quote
  774. ]
  775. );
  776. return $checkResult->getData('is_available');
  777. }
  778. /**
  779. * Is active
  780. *
  781. * @param int|null $storeId
  782. * @return bool
  783. * @deprecated 100.2.0
  784. */
  785. public function isActive($storeId = null)
  786. {
  787. return (bool)(int)$this->getConfigData('active', $storeId);
  788. }
  789. /**
  790. * Method that will be executed instead of authorize or capture if flag isInitializeNeeded set to true.
  791. *
  792. * @param string $paymentAction
  793. * @param object $stateObject
  794. *
  795. * @return $this
  796. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  797. * @api
  798. * @deprecated 100.2.0
  799. */
  800. public function initialize($paymentAction, $stateObject)
  801. {
  802. return $this;
  803. }
  804. /**
  805. * Get config payment action url.
  806. *
  807. * Used to universalize payment actions when processing payment place.
  808. *
  809. * @return string
  810. * @api
  811. * @deprecated 100.2.0
  812. */
  813. public function getConfigPaymentAction()
  814. {
  815. return $this->getConfigData('payment_action');
  816. }
  817. /**
  818. * Log debug data to file
  819. *
  820. * @param array $debugData
  821. * @return void
  822. * @deprecated 100.2.0
  823. */
  824. protected function _debug($debugData)
  825. {
  826. $this->logger->debug(
  827. $debugData,
  828. $this->getDebugReplacePrivateDataKeys(),
  829. $this->getDebugFlag()
  830. );
  831. }
  832. /**
  833. * Define if debugging is enabled
  834. *
  835. * @return bool
  836. * @SuppressWarnings(PHPMD.BooleanGetMethodName)
  837. * @api
  838. * @deprecated 100.2.0
  839. */
  840. public function getDebugFlag()
  841. {
  842. return (bool)(int)$this->getConfigData('debug');
  843. }
  844. /**
  845. * Used to call debug method from not Payment Method context
  846. *
  847. * @param mixed $debugData
  848. * @return void
  849. * @api
  850. * @deprecated 100.2.0
  851. */
  852. public function debugData($debugData)
  853. {
  854. $this->_debug($debugData);
  855. }
  856. /**
  857. * Return replace keys for debug data
  858. *
  859. * @return array
  860. * @deprecated 100.2.0
  861. */
  862. public function getDebugReplacePrivateDataKeys()
  863. {
  864. return (array) $this->_debugReplacePrivateDataKeys;
  865. }
  866. }