123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Payment\Model\Method;
- use Magento\Framework\App\ObjectManager;
- use Magento\Framework\DataObject;
- use Magento\Payment\Model\InfoInterface;
- use Magento\Payment\Model\MethodInterface;
- use Magento\Payment\Observer\AbstractDataAssignObserver;
- use Magento\Quote\Api\Data\PaymentMethodInterface;
- use Magento\Sales\Model\Order\Payment;
- use Magento\Directory\Helper\Data as DirectoryHelper;
- /**
- * Payment method abstract model
- *
- * @api
- * @SuppressWarnings(PHPMD.ExcessivePublicCount)
- * @SuppressWarnings(PHPMD.TooManyFields)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @deprecated 100.0.6
- * @see \Magento\Payment\Model\Method\Adapter
- * @see https://devdocs.magento.com/guides/v2.1/payments-integrations/payment-gateway/payment-gateway-intro.html
- * @since 100.0.2
- */
- abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibleModel implements
- MethodInterface,
- PaymentMethodInterface
- {
- const STATUS_UNKNOWN = 'UNKNOWN';
- const STATUS_APPROVED = 'APPROVED';
- const STATUS_ERROR = 'ERROR';
- const STATUS_DECLINED = 'DECLINED';
- const STATUS_VOID = 'VOID';
- const STATUS_SUCCESS = 'SUCCESS';
- /**
- * @var string
- */
- protected $_code;
- /**
- * @var string
- */
- protected $_formBlockType = \Magento\Payment\Block\Form::class;
- /**
- * @var string
- */
- protected $_infoBlockType = \Magento\Payment\Block\Info::class;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_isGateway = false;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_isOffline = false;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_canOrder = false;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_canAuthorize = false;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_canCapture = false;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_canCapturePartial = false;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_canCaptureOnce = false;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_canRefund = false;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_canRefundInvoicePartial = false;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_canVoid = false;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_canUseInternal = true;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_canUseCheckout = true;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_isInitializeNeeded = false;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_canFetchTransactionInfo = false;
- /**
- * Payment Method feature
- *
- * @var bool
- */
- protected $_canReviewPayment = false;
- /**
- * TODO: whether a captured transaction may be voided by this gateway
- * This may happen when amount is captured, but not settled
- * @var bool
- */
- protected $_canCancelInvoice = false;
- /**
- * Fields that should be replaced in debug with '***'
- *
- * @var array
- */
- protected $_debugReplacePrivateDataKeys = [];
- /**
- * Payment data
- *
- * @var \Magento\Payment\Helper\Data
- */
- protected $_paymentData;
- /**
- * Core store config
- *
- * @var \Magento\Framework\App\Config\ScopeConfigInterface
- */
- protected $_scopeConfig;
- /**
- * @var Logger
- */
- protected $logger;
- /**
- * @var DirectoryHelper
- */
- private $directory;
- /**
- * @param \Magento\Framework\Model\Context $context
- * @param \Magento\Framework\Registry $registry
- * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
- * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
- * @param \Magento\Payment\Helper\Data $paymentData
- * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
- * @param Logger $logger
- * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
- * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
- * @param array $data
- * @param DirectoryHelper $directory
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
- */
- public function __construct(
- \Magento\Framework\Model\Context $context,
- \Magento\Framework\Registry $registry,
- \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
- \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
- \Magento\Payment\Helper\Data $paymentData,
- \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
- \Magento\Payment\Model\Method\Logger $logger,
- \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
- \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
- array $data = [],
- DirectoryHelper $directory = null
- ) {
- parent::__construct(
- $context,
- $registry,
- $extensionFactory,
- $customAttributeFactory,
- $resource,
- $resourceCollection,
- $data
- );
- $this->_paymentData = $paymentData;
- $this->_scopeConfig = $scopeConfig;
- $this->logger = $logger;
- $this->directory = $directory ?: ObjectManager::getInstance()->get(DirectoryHelper::class);
- $this->initializeData($data);
- }
- /**
- * Initializes injected data
- *
- * @param array $data
- * @return void
- */
- protected function initializeData($data = [])
- {
- if (!empty($data['formBlockType'])) {
- $this->_formBlockType = $data['formBlockType'];
- }
- }
- /**
- * @inheritdoc
- * @deprecated 100.2.0
- */
- public function setStore($storeId)
- {
- $this->setData('store', (int)$storeId);
- }
- /**
- * @inheritdoc
- * @deprecated 100.2.0
- */
- public function getStore()
- {
- return $this->getData('store');
- }
- /**
- * Check order availability
- *
- * @return bool
- * @api
- * @deprecated 100.2.0
- */
- public function canOrder()
- {
- return $this->_canOrder;
- }
- /**
- * Check authorize availability
- *
- * @return bool
- * @api
- * @deprecated 100.2.0
- */
- public function canAuthorize()
- {
- return $this->_canAuthorize;
- }
- /**
- * Check capture availability
- *
- * @return bool
- * @api
- * @deprecated 100.2.0
- */
- public function canCapture()
- {
- return $this->_canCapture;
- }
- /**
- * Check partial capture availability
- *
- * @return bool
- * @api
- * @deprecated 100.2.0
- */
- public function canCapturePartial()
- {
- return $this->_canCapturePartial;
- }
- /**
- * Check whether capture can be performed once and no further capture possible
- *
- * @return bool
- * @api
- * @deprecated 100.2.0
- */
- public function canCaptureOnce()
- {
- return $this->_canCaptureOnce;
- }
- /**
- * Check refund availability
- *
- * @return bool
- * @api
- * @deprecated 100.2.0
- */
- public function canRefund()
- {
- return $this->_canRefund;
- }
- /**
- * Check partial refund availability for invoice
- *
- * @return bool
- * @api
- * @deprecated 100.2.0
- */
- public function canRefundPartialPerInvoice()
- {
- return $this->_canRefundInvoicePartial;
- }
- /**
- * Check void availability.
- *
- * @return bool
- * @internal param \Magento\Framework\DataObject $payment
- * @api
- * @deprecated 100.2.0
- */
- public function canVoid()
- {
- return $this->_canVoid;
- }
- /**
- * Using internal pages for input payment data.
- *
- * Can be used in admin.
- *
- * @return bool
- * @deprecated 100.2.0
- */
- public function canUseInternal()
- {
- return $this->_canUseInternal;
- }
- /**
- * Can be used in regular checkout
- *
- * @return bool
- * @deprecated 100.2.0
- */
- public function canUseCheckout()
- {
- return $this->_canUseCheckout;
- }
- /**
- * Can be edit order (renew order)
- *
- * @return bool
- * @api
- * @deprecated 100.2.0
- */
- public function canEdit()
- {
- return true;
- }
- /**
- * Check fetch transaction info availability
- *
- * @return bool
- * @api
- * @deprecated 100.2.0
- */
- public function canFetchTransactionInfo()
- {
- return $this->_canFetchTransactionInfo;
- }
- /**
- * Fetch transaction info
- *
- * @param InfoInterface $payment
- * @param string $transactionId
- * @return array
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- * @api
- * @deprecated 100.2.0
- */
- public function fetchTransactionInfo(InfoInterface $payment, $transactionId)
- {
- return [];
- }
- /**
- * Retrieve payment system relation flag
- *
- * @return bool
- * @api
- * @deprecated 100.2.0
- */
- public function isGateway()
- {
- return $this->_isGateway;
- }
- /**
- * Retrieve payment method online/offline flag
- *
- * @return bool
- * @api
- * @deprecated 100.2.0
- */
- public function isOffline()
- {
- return $this->_isOffline;
- }
- /**
- * Flag if we need to run payment initialize while order place
- *
- * @return bool
- * @api
- * @deprecated 100.2.0
- */
- public function isInitializeNeeded()
- {
- return $this->_isInitializeNeeded;
- }
- /**
- * To check billing country is allowed for the payment method
- *
- * @param string $country
- * @return bool
- * @deprecated 100.2.0
- */
- public function canUseForCountry($country)
- {
- /*
- for specific country, the flag will set up as 1
- */
- if ($this->getConfigData('allowspecific') == 1) {
- $availableCountries = explode(',', $this->getConfigData('specificcountry'));
- if (!in_array($country, $availableCountries)) {
- return false;
- }
- }
- return true;
- }
- /**
- * Check method for processing with base currency
- *
- * @param string $currencyCode
- * @return bool
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- * @deprecated 100.2.0
- */
- public function canUseForCurrency($currencyCode)
- {
- return true;
- }
- /**
- * Retrieve payment method code
- *
- * @return string
- * @throws \Magento\Framework\Exception\LocalizedException
- * @deprecated 100.2.0
- */
- public function getCode()
- {
- if (empty($this->_code)) {
- throw new \Magento\Framework\Exception\LocalizedException(
- __('We cannot retrieve the payment method code.')
- );
- }
- return $this->_code;
- }
- /**
- * Retrieve block type for method form generation
- *
- * @return string
- * @deprecated 100.2.0
- */
- public function getFormBlockType()
- {
- return $this->_formBlockType;
- }
- /**
- * Retrieve block type for display method information
- *
- * @return string
- * @api
- * @deprecated 100.2.0
- */
- public function getInfoBlockType()
- {
- return $this->_infoBlockType;
- }
- /**
- * Retrieve payment information model object
- *
- * @return InfoInterface
- * @throws \Magento\Framework\Exception\LocalizedException
- * @api
- * @deprecated 100.2.0
- */
- public function getInfoInstance()
- {
- $instance = $this->getData('info_instance');
- if (!$instance instanceof InfoInterface) {
- throw new \Magento\Framework\Exception\LocalizedException(
- __('We cannot retrieve the payment information object instance.')
- );
- }
- return $instance;
- }
- /**
- * Retrieve payment information model object
- *
- * @param InfoInterface $info
- * @return void
- * @api
- * @deprecated 100.2.0
- */
- public function setInfoInstance(InfoInterface $info)
- {
- $this->setData('info_instance', $info);
- }
- /**
- * Validate payment method information object
- *
- * @return $this
- * @throws \Magento\Framework\Exception\LocalizedException
- * @api
- * @deprecated 100.2.0
- */
- public function validate()
- {
- /**
- * to validate payment method is allowed for billing country or not
- */
- $paymentInfo = $this->getInfoInstance();
- if ($paymentInfo instanceof Payment) {
- $billingCountry = $paymentInfo->getOrder()->getBillingAddress()->getCountryId();
- } else {
- $billingCountry = $paymentInfo->getQuote()->getBillingAddress()->getCountryId();
- }
- $billingCountry = $billingCountry ?: $this->directory->getDefaultCountry();
- if (!$this->canUseForCountry($billingCountry)) {
- throw new \Magento\Framework\Exception\LocalizedException(
- __('You can\'t use the payment type you selected to make payments to the billing country.')
- );
- }
- return $this;
- }
- /**
- * Order payment abstract method
- *
- * @param \Magento\Framework\DataObject|InfoInterface $payment
- * @param float $amount
- * @return $this
- * @throws \Magento\Framework\Exception\LocalizedException
- * @api
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- * @deprecated 100.2.0
- */
- public function order(\Magento\Payment\Model\InfoInterface $payment, $amount)
- {
- if (!$this->canOrder()) {
- throw new \Magento\Framework\Exception\LocalizedException(__('The order action is not available.'));
- }
- return $this;
- }
- /**
- * Authorize payment abstract method
- *
- * @param \Magento\Framework\DataObject|InfoInterface $payment
- * @param float $amount
- * @return $this
- * @throws \Magento\Framework\Exception\LocalizedException
- * @api
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- * @deprecated 100.2.0
- */
- public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)
- {
- if (!$this->canAuthorize()) {
- throw new \Magento\Framework\Exception\LocalizedException(__('The authorize action is not available.'));
- }
- return $this;
- }
- /**
- * Capture payment abstract method
- *
- * @param \Magento\Framework\DataObject|InfoInterface $payment
- * @param float $amount
- * @return $this
- * @throws \Magento\Framework\Exception\LocalizedException
- * @api
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- * @deprecated 100.2.0
- */
- public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
- {
- if (!$this->canCapture()) {
- throw new \Magento\Framework\Exception\LocalizedException(__('The capture action is not available.'));
- }
- return $this;
- }
- /**
- * Refund specified amount for payment
- *
- * @param \Magento\Framework\DataObject|InfoInterface $payment
- * @param float $amount
- * @return $this
- * @throws \Magento\Framework\Exception\LocalizedException
- * @api
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- * @deprecated 100.2.0
- */
- public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
- {
- if (!$this->canRefund()) {
- throw new \Magento\Framework\Exception\LocalizedException(__('The refund action is not available.'));
- }
- return $this;
- }
- /**
- * Cancel payment abstract method
- *
- * @param \Magento\Framework\DataObject|InfoInterface $payment
- * @return $this
- * @api
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- * @deprecated 100.2.0
- */
- public function cancel(\Magento\Payment\Model\InfoInterface $payment)
- {
- return $this;
- }
- /**
- * Void payment abstract method
- *
- * @param \Magento\Framework\DataObject|InfoInterface $payment
- * @return $this
- * @throws \Magento\Framework\Exception\LocalizedException
- * @api
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- * @deprecated 100.2.0
- */
- public function void(\Magento\Payment\Model\InfoInterface $payment)
- {
- if (!$this->canVoid()) {
- throw new \Magento\Framework\Exception\LocalizedException(__('The void action is not available.'));
- }
- return $this;
- }
- /**
- * Whether this method can accept or deny payment.
- *
- * @return bool
- * @api
- * @deprecated 100.2.0
- */
- public function canReviewPayment()
- {
- return $this->_canReviewPayment;
- }
- /**
- * Attempt to accept a payment that us under review
- *
- * @param InfoInterface $payment
- * @return false
- * @throws \Magento\Framework\Exception\LocalizedException
- * @api
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- * @deprecated 100.2.0
- */
- public function acceptPayment(InfoInterface $payment)
- {
- if (!$this->canReviewPayment()) {
- throw new \Magento\Framework\Exception\LocalizedException(__('The payment review action is unavailable.'));
- }
- return false;
- }
- /**
- * Attempt to deny a payment that us under review
- *
- * @param InfoInterface $payment
- * @return false
- * @throws \Magento\Framework\Exception\LocalizedException
- * @api
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- * @deprecated 100.2.0
- */
- public function denyPayment(InfoInterface $payment)
- {
- if (!$this->canReviewPayment()) {
- throw new \Magento\Framework\Exception\LocalizedException(__('The payment review action is unavailable.'));
- }
- return false;
- }
- /**
- * Retrieve payment method title
- *
- * @return string
- * @deprecated 100.2.0
- */
- public function getTitle()
- {
- return $this->getConfigData('title');
- }
- /**
- * Retrieve information from payment configuration
- *
- * @param string $field
- * @param int|string|null|\Magento\Store\Model\Store $storeId
- *
- * @return mixed
- * @deprecated 100.2.0
- */
- public function getConfigData($field, $storeId = null)
- {
- if ('order_place_redirect_url' === $field) {
- return $this->getOrderPlaceRedirectUrl();
- }
- if (null === $storeId) {
- $storeId = $this->getStore();
- }
- $path = 'payment/' . $this->getCode() . '/' . $field;
- return $this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
- }
- /**
- * Assign data to info model instance
- *
- * @param array|\Magento\Framework\DataObject $data
- * @return $this
- * @throws \Magento\Framework\Exception\LocalizedException
- * @api
- * @deprecated 100.2.0
- */
- public function assignData(\Magento\Framework\DataObject $data)
- {
- $this->_eventManager->dispatch(
- 'payment_method_assign_data_' . $this->getCode(),
- [
- AbstractDataAssignObserver::METHOD_CODE => $this,
- AbstractDataAssignObserver::MODEL_CODE => $this->getInfoInstance(),
- AbstractDataAssignObserver::DATA_CODE => $data
- ]
- );
- $this->_eventManager->dispatch(
- 'payment_method_assign_data',
- [
- AbstractDataAssignObserver::METHOD_CODE => $this,
- AbstractDataAssignObserver::MODEL_CODE => $this->getInfoInstance(),
- AbstractDataAssignObserver::DATA_CODE => $data
- ]
- );
- return $this;
- }
- /**
- * Check whether payment method can be used
- *
- * @param \Magento\Quote\Api\Data\CartInterface|null $quote
- * @return bool
- * @deprecated 100.2.0
- */
- public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
- {
- if (!$this->isActive($quote ? $quote->getStoreId() : null)) {
- return false;
- }
- $checkResult = new DataObject();
- $checkResult->setData('is_available', true);
- // for future use in observers
- $this->_eventManager->dispatch(
- 'payment_method_is_active',
- [
- 'result' => $checkResult,
- 'method_instance' => $this,
- 'quote' => $quote
- ]
- );
- return $checkResult->getData('is_available');
- }
- /**
- * Is active
- *
- * @param int|null $storeId
- * @return bool
- * @deprecated 100.2.0
- */
- public function isActive($storeId = null)
- {
- return (bool)(int)$this->getConfigData('active', $storeId);
- }
- /**
- * Method that will be executed instead of authorize or capture if flag isInitializeNeeded set to true.
- *
- * @param string $paymentAction
- * @param object $stateObject
- *
- * @return $this
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- * @api
- * @deprecated 100.2.0
- */
- public function initialize($paymentAction, $stateObject)
- {
- return $this;
- }
- /**
- * Get config payment action url.
- *
- * Used to universalize payment actions when processing payment place.
- *
- * @return string
- * @api
- * @deprecated 100.2.0
- */
- public function getConfigPaymentAction()
- {
- return $this->getConfigData('payment_action');
- }
- /**
- * Log debug data to file
- *
- * @param array $debugData
- * @return void
- * @deprecated 100.2.0
- */
- protected function _debug($debugData)
- {
- $this->logger->debug(
- $debugData,
- $this->getDebugReplacePrivateDataKeys(),
- $this->getDebugFlag()
- );
- }
- /**
- * Define if debugging is enabled
- *
- * @return bool
- * @SuppressWarnings(PHPMD.BooleanGetMethodName)
- * @api
- * @deprecated 100.2.0
- */
- public function getDebugFlag()
- {
- return (bool)(int)$this->getConfigData('debug');
- }
- /**
- * Used to call debug method from not Payment Method context
- *
- * @param mixed $debugData
- * @return void
- * @api
- * @deprecated 100.2.0
- */
- public function debugData($debugData)
- {
- $this->_debug($debugData);
- }
- /**
- * Return replace keys for debug data
- *
- * @return array
- * @deprecated 100.2.0
- */
- public function getDebugReplacePrivateDataKeys()
- {
- return (array) $this->_debugReplacePrivateDataKeys;
- }
- }
|