Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Adapter Class Reference
Inheritance diagram for Adapter:
MethodInterface

Public Member Functions

 __construct (ManagerInterface $eventManager, ValueHandlerPoolInterface $valueHandlerPool, PaymentDataObjectFactory $paymentDataObjectFactory, $code, $formBlockType, $infoBlockType, CommandPoolInterface $commandPool=null, ValidatorPoolInterface $validatorPool=null, CommandManagerInterface $commandExecutor=null, LoggerInterface $logger=null)
 
 getValidatorPool ()
 
 canOrder ()
 
 canAuthorize ()
 
 canCapture ()
 
 canCapturePartial ()
 
 canCaptureOnce ()
 
 canRefund ()
 
 canRefundPartialPerInvoice ()
 
 canVoid ()
 
 canUseInternal ()
 
 canUseCheckout ()
 
 canEdit ()
 
 canFetchTransactionInfo ()
 
 canReviewPayment ()
 
 isGateway ()
 
 isOffline ()
 
 isInitializeNeeded ()
 
 isAvailable (CartInterface $quote=null)
 
 isActive ($storeId=null)
 
 canUseForCountry ($country)
 
 canUseForCurrency ($currencyCode)
 
 getConfigData ($field, $storeId=null)
 
 validate ()
 
 fetchTransactionInfo (InfoInterface $payment, $transactionId)
 
 order (InfoInterface $payment, $amount)
 
 authorize (InfoInterface $payment, $amount)
 
 capture (InfoInterface $payment, $amount)
 
 refund (InfoInterface $payment, $amount)
 
 cancel (InfoInterface $payment)
 
 void (InfoInterface $payment)
 
 acceptPayment (InfoInterface $payment)
 
 denyPayment (InfoInterface $payment)
 
 getCode ()
 
 getTitle ()
 
 setStore ($storeId)
 
 getStore ()
 
 getFormBlockType ()
 
 getInfoBlockType ()
 
 getInfoInstance ()
 
 setInfoInstance (InfoInterface $info)
 
 assignData (\Magento\Framework\DataObject $data)
 
 initialize ($paymentAction, $stateObject)
 
 getConfigPaymentAction ()
 
- Public Member Functions inherited from MethodInterface
 order (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 authorize (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 capture (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 refund (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 cancel (\Magento\Payment\Model\InfoInterface $payment)
 
 void (\Magento\Payment\Model\InfoInterface $payment)
 
 assignData (DataObject $data)
 

Additional Inherited Members

- Data Fields inherited from MethodInterface
const ACTION_ORDER = 'order'
 
const ACTION_AUTHORIZE = 'authorize'
 
const ACTION_AUTHORIZE_CAPTURE = 'authorize_capture'
 
const CHECK_USE_FOR_COUNTRY = 'country'
 
const CHECK_USE_FOR_CURRENCY = 'currency'
 
const CHECK_USE_CHECKOUT = 'checkout'
 
const CHECK_USE_INTERNAL = 'internal'
 
const CHECK_ORDER_TOTAL_MIN_MAX = 'total'
 
const CHECK_ZERO_TOTAL = 'zero_total'
 
const GROUP_OFFLINE = 'offline'
 

Detailed Description

Payment method facade. Abstract method adapter

@SuppressWarnings(PHPMD.ExcessivePublicCount) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

@api Use this class as a base for virtual types declaration

Since
100.0.2

Definition at line 33 of file Adapter.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ManagerInterface  $eventManager,
ValueHandlerPoolInterface  $valueHandlerPool,
PaymentDataObjectFactory  $paymentDataObjectFactory,
  $code,
  $formBlockType,
  $infoBlockType,
CommandPoolInterface  $commandPool = null,
ValidatorPoolInterface  $validatorPool = null,
CommandManagerInterface  $commandExecutor = null,
LoggerInterface  $logger = null 
)
Parameters
ManagerInterface$eventManager
ValueHandlerPoolInterface$valueHandlerPool
PaymentDataObjectFactory$paymentDataObjectFactory
string$code
string$formBlockType
string$infoBlockType
CommandPoolInterface | null$commandPool
ValidatorPoolInterface | null$validatorPool
CommandManagerInterface | null$commandExecutor
LoggerInterface | null$logger@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 110 of file Adapter.php.

121  {
122  $this->valueHandlerPool = $valueHandlerPool;
123  $this->validatorPool = $validatorPool;
124  $this->commandPool = $commandPool;
125  $this->code = $code;
126  $this->infoBlockType = $infoBlockType;
127  $this->formBlockType = $formBlockType;
128  $this->eventManager = $eventManager;
129  $this->paymentDataObjectFactory = $paymentDataObjectFactory;
130  $this->commandExecutor = $commandExecutor;
131  $this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
132  }
$logger
$code
Definition: info.phtml:12

Member Function Documentation

◆ acceptPayment()

acceptPayment ( InfoInterface  $payment)

Attempt to accept a payment that us under review

Parameters
InfoInterface$payment
Returns
false
Exceptions

Implements MethodInterface.

Definition at line 504 of file Adapter.php.

505  {
506  $this->executeCommand('accept_payment', ['payment' => $payment]);
507 
508  return $this;
509  }
$payment
Definition: order.php:17

◆ assignData()

assignData ( \Magento\Framework\DataObject  $data)
Parameters
DataObject$data
Returns
$this

Definition at line 619 of file Adapter.php.

620  {
621  $this->eventManager->dispatch(
622  'payment_method_assign_data_' . $this->getCode(),
623  [
627  ]
628  );
629 
630  $this->eventManager->dispatch(
631  'payment_method_assign_data',
632  [
636  ]
637  );
638 
639  return $this;
640  }

◆ authorize()

authorize ( InfoInterface  $payment,
  $amount 
)

Definition at line 445 of file Adapter.php.

446  {
447  $this->executeCommand(
448  'authorize',
449  ['payment' => $payment, 'amount' => $amount]
450  );
451 
452  return $this;
453  }
$amount
Definition: order.php:14
$payment
Definition: order.php:17

◆ canAuthorize()

canAuthorize ( )

Check authorize availability

Returns
bool

Implements MethodInterface.

Definition at line 159 of file Adapter.php.

160  {
161  return $this->canPerformCommand('authorize');
162  }

◆ canCapture()

canCapture ( )

Check capture availability

Returns
bool

Implements MethodInterface.

Definition at line 167 of file Adapter.php.

168  {
169  return $this->canPerformCommand('capture');
170  }

◆ canCaptureOnce()

canCaptureOnce ( )

Check whether capture can be performed once and no further capture possible

Returns
bool

Implements MethodInterface.

Definition at line 183 of file Adapter.php.

184  {
185  return $this->canPerformCommand('capture_once');
186  }

◆ canCapturePartial()

canCapturePartial ( )

Check partial capture availability

Returns
bool

Implements MethodInterface.

Definition at line 175 of file Adapter.php.

176  {
177  return $this->canPerformCommand('capture_partial');
178  }

◆ cancel()

cancel ( InfoInterface  $payment)

Definition at line 484 of file Adapter.php.

485  {
486  $this->executeCommand('cancel', ['payment' => $payment]);
487 
488  return $this;
489  }
$payment
Definition: order.php:17

◆ canEdit()

canEdit ( )

Can be edit order (renew order)

Returns
bool

Implements MethodInterface.

Definition at line 231 of file Adapter.php.

232  {
233  return (bool)$this->getConfiguredValue('can_edit');
234  }

◆ canFetchTransactionInfo()

canFetchTransactionInfo ( )

Check fetch transaction info availability

Returns
bool

Implements MethodInterface.

Definition at line 239 of file Adapter.php.

240  {
241  return $this->canPerformCommand('fetch_transaction_info');
242  }

◆ canOrder()

canOrder ( )

Check order availability

Returns
bool

Implements MethodInterface.

Definition at line 151 of file Adapter.php.

152  {
153  return $this->canPerformCommand('order');
154  }

◆ canRefund()

canRefund ( )

Check refund availability

Returns
bool

Implements MethodInterface.

Definition at line 191 of file Adapter.php.

192  {
193  return $this->canPerformCommand('refund');
194  }

◆ canRefundPartialPerInvoice()

canRefundPartialPerInvoice ( )

Check partial refund availability for invoice

Returns
bool

Implements MethodInterface.

Definition at line 199 of file Adapter.php.

200  {
201  return $this->canPerformCommand('refund_partial_per_invoice');
202  }

◆ canReviewPayment()

canReviewPayment ( )

Whether this method can accept or deny payment

Returns
bool

Implements MethodInterface.

Definition at line 247 of file Adapter.php.

248  {
249  return $this->canPerformCommand('review_payment');
250  }

◆ canUseCheckout()

canUseCheckout ( )

Can be used in regular checkout

Returns
bool

Implements MethodInterface.

Definition at line 223 of file Adapter.php.

224  {
225  return (bool)$this->getConfiguredValue('can_use_checkout');
226  }

◆ canUseForCountry()

canUseForCountry (   $country)

To check billing country is allowed for the payment method

Parameters
string$country
Returns
bool

Implements MethodInterface.

Definition at line 327 of file Adapter.php.

328  {
329  try {
330  $validator = $this->getValidatorPool()->get('country');
331  } catch (\Exception $e) {
332  return true;
333  }
334 
335  $result = $validator->validate(['country' => $country, 'storeId' => $this->getStore()]);
336  return $result->isValid();
337  }

◆ canUseForCurrency()

canUseForCurrency (   $currencyCode)

Check method for processing with base currency

Parameters
string$currencyCode
Returns
bool @SuppressWarnings(PHPMD.UnusedFormalParameter)

Implements MethodInterface.

Definition at line 342 of file Adapter.php.

343  {
344  try {
345  $validator = $this->getValidatorPool()->get('currency');
346  } catch (\Exception $e) {
347  return true;
348  }
349 
350  $result = $validator->validate(['currency' => $currencyCode, 'storeId' => $this->getStore()]);
351  return $result->isValid();
352  }

◆ canUseInternal()

canUseInternal ( )

Using internal pages for input payment data Can be used in admin

Returns
bool

Implements MethodInterface.

Definition at line 215 of file Adapter.php.

216  {
217  return (bool)$this->getConfiguredValue('can_use_internal');
218  }

◆ canVoid()

canVoid ( )

Check void availability

Returns
bool

Implements MethodInterface.

Definition at line 207 of file Adapter.php.

208  {
209  return $this->canPerformCommand('void');
210  }

◆ capture()

capture ( InfoInterface  $payment,
  $amount 
)

Definition at line 458 of file Adapter.php.

459  {
460  $this->executeCommand(
461  'capture',
462  ['payment' => $payment, 'amount' => $amount]
463  );
464 
465  return $this;
466  }
$amount
Definition: order.php:14
$payment
Definition: order.php:17

◆ denyPayment()

denyPayment ( InfoInterface  $payment)

Attempt to deny a payment that us under review

Parameters
InfoInterface$payment
Returns
false
Exceptions

Implements MethodInterface.

Definition at line 514 of file Adapter.php.

515  {
516  $this->executeCommand('deny_payment', ['payment' => $payment]);
517 
518  return $this;
519  }
$payment
Definition: order.php:17

◆ fetchTransactionInfo()

fetchTransactionInfo ( InfoInterface  $payment,
  $transactionId 
)

Fetch transaction info

Parameters
InfoInterface$payment
string$transactionId
Returns
array @SuppressWarnings(PHPMD.UnusedFormalParameter)

Implements MethodInterface.

Definition at line 421 of file Adapter.php.

422  {
423  return $this->executeCommand(
424  'fetch_transaction_information',
425  ['payment' => $payment, 'transactionId' => $transactionId]
426  );
427  }
$payment
Definition: order.php:17

◆ getCode()

getCode ( )

Retrieve payment method code

Returns
string

Implements MethodInterface.

Definition at line 553 of file Adapter.php.

554  {
555  return $this->code;
556  }
$code
Definition: info.phtml:12

◆ getConfigData()

getConfigData (   $field,
  $storeId = null 
)

Retrieve information from payment configuration

Parameters
string$field
int | string | null | \Magento\Store\Model\Store$storeId
Returns
mixed

Implements MethodInterface.

Definition at line 389 of file Adapter.php.

390  {
391  return $this->getConfiguredValue($field, $storeId);
392  }

◆ getConfigPaymentAction()

getConfigPaymentAction ( )

Get config payment action url Used to universalize payment actions when processing payment place

Returns
string

Implements MethodInterface.

Definition at line 662 of file Adapter.php.

663  {
664  return $this->getConfiguredValue('payment_action');
665  }

◆ getFormBlockType()

getFormBlockType ( )

Retrieve block type for method form generation

Returns
string
Deprecated:
100.0.2

Implements MethodInterface.

Definition at line 585 of file Adapter.php.

586  {
587  return $this->formBlockType;
588  }

◆ getInfoBlockType()

getInfoBlockType ( )

Retrieve block type for display method information

Returns
string
Deprecated:
100.0.2

Implements MethodInterface.

Definition at line 593 of file Adapter.php.

594  {
595  return $this->infoBlockType;
596  }

◆ getInfoInstance()

getInfoInstance ( )

Retrieve payment information model object

Returns
InfoInterface
Exceptions

Implements MethodInterface.

Definition at line 601 of file Adapter.php.

602  {
603  return $this->infoInstance;
604  }

◆ getStore()

getStore ( )

Store id getter

Returns
int

Implements MethodInterface.

Definition at line 577 of file Adapter.php.

578  {
579  return $this->storeId;
580  }

◆ getTitle()

getTitle ( )

Retrieve payment method title

Returns
string

Implements MethodInterface.

Definition at line 561 of file Adapter.php.

562  {
563  return $this->getConfiguredValue('title');
564  }

◆ getValidatorPool()

getValidatorPool ( )

Returns Validator pool

Returns
ValidatorPoolInterface
Exceptions

Definition at line 140 of file Adapter.php.

141  {
142  if ($this->validatorPool === null) {
143  throw new \DomainException('Validator pool is not configured for use.');
144  }
145  return $this->validatorPool;
146  }

◆ initialize()

initialize (   $paymentAction,
  $stateObject 
)

Method that will be executed instead of authorize or capture if flag isInitializeNeeded set to true

Parameters
string$paymentAction
object$stateObject
Returns
$this @SuppressWarnings(PHPMD.UnusedFormalParameter)
@SuppressWarnings(PHPMD.UnusedFormalParameter)

Implements MethodInterface.

Definition at line 646 of file Adapter.php.

647  {
648  $this->executeCommand(
649  'initialize',
650  [
651  'payment' => $this->getInfoInstance(),
652  'paymentAction' => $paymentAction,
653  'stateObject' => $stateObject
654  ]
655  );
656  return $this;
657  }

◆ isActive()

isActive (   $storeId = null)

Is active

Parameters
int | null$storeId
Returns
bool

Implements MethodInterface.

Definition at line 319 of file Adapter.php.

320  {
321  return (bool)$this->getConfiguredValue('active', $storeId);
322  }

◆ isAvailable()

isAvailable ( CartInterface  $quote = null)

Check whether payment method can be used

Parameters
CartInterface | null$quote
Returns
bool

Implements MethodInterface.

Definition at line 279 of file Adapter.php.

280  {
281  if (!$this->isActive($quote ? $quote->getStoreId() : null)) {
282  return false;
283  }
284 
285  $checkResult = new DataObject();
286  $checkResult->setData('is_available', true);
287  try {
288  $infoInstance = $this->getInfoInstance();
289  if ($infoInstance !== null) {
290  $validator = $this->getValidatorPool()->get('availability');
291  $result = $validator->validate(
292  [
293  'payment' => $this->paymentDataObjectFactory->create($infoInstance)
294  ]
295  );
296 
297  $checkResult->setData('is_available', $result->isValid());
298  }
299  } catch (\Exception $e) {
300  // pass
301  }
302 
303  // for future use in observers
304  $this->eventManager->dispatch(
305  'payment_method_is_active',
306  [
307  'result' => $checkResult,
308  'method_instance' => $this,
309  'quote' => $quote
310  ]
311  );
312 
313  return $checkResult->getData('is_available');
314  }
$quote

◆ isGateway()

isGateway ( )

Retrieve payment system relation flag

Returns
bool

Implements MethodInterface.

Definition at line 255 of file Adapter.php.

256  {
257  return (bool)$this->getConfiguredValue('is_gateway');
258  }

◆ isInitializeNeeded()

isInitializeNeeded ( )

Flag if we need to run payment initialize while order place

Returns
bool

Implements MethodInterface.

Definition at line 271 of file Adapter.php.

272  {
273  return (bool)(int)$this->getConfiguredValue('can_initialize');
274  }

◆ isOffline()

isOffline ( )

Retrieve payment method online/offline flag

Returns
bool

Implements MethodInterface.

Definition at line 263 of file Adapter.php.

264  {
265  return (bool)$this->getConfiguredValue('is_offline');
266  }

◆ order()

order ( InfoInterface  $payment,
  $amount 
)

Definition at line 432 of file Adapter.php.

433  {
434  $this->executeCommand(
435  'order',
436  ['payment' => $payment, 'amount' => $amount]
437  );
438 
439  return $this;
440  }
$amount
Definition: order.php:14
$payment
Definition: order.php:17

◆ refund()

refund ( InfoInterface  $payment,
  $amount 
)

Definition at line 471 of file Adapter.php.

472  {
473  $this->executeCommand(
474  'refund',
475  ['payment' => $payment, 'amount' => $amount]
476  );
477 
478  return $this;
479  }
$amount
Definition: order.php:14
$payment
Definition: order.php:17

◆ setInfoInstance()

setInfoInstance ( InfoInterface  $info)

Retrieve payment information model object

Parameters
InfoInterface$info
Returns
void
Deprecated:
100.0.2

Implements MethodInterface.

Definition at line 609 of file Adapter.php.

610  {
611  $this->infoInstance = $info;
612  }
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ setStore()

setStore (   $storeId)

Store id setter

Parameters
int$storeId
Returns
void

Implements MethodInterface.

Definition at line 569 of file Adapter.php.

570  {
571  $this->storeId = (int)$storeId;
572  }

◆ validate()

validate ( )

Validate payment method information object

Returns
$this
Exceptions

Implements MethodInterface.

Definition at line 397 of file Adapter.php.

398  {
399  try {
400  $validator = $this->getValidatorPool()->get('global');
401  } catch (\Exception $e) {
402  return $this;
403  }
404 
405  $result = $validator->validate(
406  ['payment' => $this->getInfoInstance(), 'storeId' => $this->getStore()]
407  );
408 
409  if (!$result->isValid()) {
410  throw new LocalizedException(
411  __(implode("\n", $result->getFailsDescription()))
412  );
413  }
414 
415  return $this;
416  }
__()
Definition: __.php:13

◆ void()

void ( InfoInterface  $payment)

Definition at line 494 of file Adapter.php.

495  {
496  $this->executeCommand('void', ['payment' => $payment]);
497 
498  return $this;
499  }
$payment
Definition: order.php:17

The documentation for this class was generated from the following file: