22 use Psr\Log\LoggerInterface;
38 private $valueHandlerPool;
43 private $validatorPool;
58 private $formBlockType;
63 private $infoBlockType;
68 private $infoInstance;
78 private $eventManager;
83 private $paymentDataObjectFactory;
88 private $commandExecutor;
120 LoggerInterface $logger =
null 122 $this->valueHandlerPool = $valueHandlerPool;
123 $this->validatorPool = $validatorPool;
124 $this->commandPool = $commandPool;
126 $this->infoBlockType = $infoBlockType;
127 $this->formBlockType = $formBlockType;
128 $this->eventManager = $eventManager;
129 $this->paymentDataObjectFactory = $paymentDataObjectFactory;
130 $this->commandExecutor = $commandExecutor;
142 if ($this->validatorPool ===
null) {
143 throw new \DomainException(
'Validator pool is not configured for use.');
145 return $this->validatorPool;
153 return $this->canPerformCommand(
'order');
161 return $this->canPerformCommand(
'authorize');
169 return $this->canPerformCommand(
'capture');
177 return $this->canPerformCommand(
'capture_partial');
185 return $this->canPerformCommand(
'capture_once');
193 return $this->canPerformCommand(
'refund');
201 return $this->canPerformCommand(
'refund_partial_per_invoice');
209 return $this->canPerformCommand(
'void');
217 return (
bool)$this->getConfiguredValue(
'can_use_internal');
225 return (
bool)$this->getConfiguredValue(
'can_use_checkout');
233 return (
bool)$this->getConfiguredValue(
'can_edit');
241 return $this->canPerformCommand(
'fetch_transaction_info');
249 return $this->canPerformCommand(
'review_payment');
257 return (
bool)$this->getConfiguredValue(
'is_gateway');
265 return (
bool)$this->getConfiguredValue(
'is_offline');
273 return (
bool)(int)$this->getConfiguredValue(
'can_initialize');
286 $checkResult->setData(
'is_available',
true);
289 if ($infoInstance !==
null) {
291 $result = $validator->validate(
293 'payment' => $this->paymentDataObjectFactory->create($infoInstance)
297 $checkResult->setData(
'is_available',
$result->isValid());
299 }
catch (\Exception $e) {
304 $this->eventManager->dispatch(
305 'payment_method_is_active',
307 'result' => $checkResult,
308 'method_instance' => $this,
313 return $checkResult->getData(
'is_available');
321 return (
bool)$this->getConfiguredValue(
'active', $storeId);
331 }
catch (\Exception $e) {
335 $result = $validator->validate([
'country' => $country,
'storeId' => $this->
getStore()]);
346 }
catch (\Exception $e) {
350 $result = $validator->validate([
'currency' => $currencyCode,
'storeId' => $this->
getStore()]);
360 private function canPerformCommand($commandCode)
362 return (
bool)$this->getConfiguredValue(
'can_' . $commandCode);
372 private function getConfiguredValue($field, $storeId =
null)
374 $handler = $this->valueHandlerPool->get($field);
380 $subject[
'payment'] = $this->paymentDataObjectFactory->create($this->
getInfoInstance());
391 return $this->getConfiguredValue($field, $storeId);
401 }
catch (\Exception $e) {
405 $result = $validator->validate(
411 __(implode(
"\n",
$result->getFailsDescription()))
423 return $this->executeCommand(
424 'fetch_transaction_information',
425 [
'payment' =>
$payment,
'transactionId' => $transactionId]
434 $this->executeCommand(
447 $this->executeCommand(
460 $this->executeCommand(
473 $this->executeCommand(
486 $this->executeCommand(
'cancel', [
'payment' =>
$payment]);
496 $this->executeCommand(
'void', [
'payment' =>
$payment]);
506 $this->executeCommand(
'accept_payment', [
'payment' =>
$payment]);
516 $this->executeCommand(
'deny_payment', [
'payment' =>
$payment]);
524 private function executeCommand($commandCode, array
$arguments = [])
526 if (!$this->canPerformCommand($commandCode)) {
537 if ($this->commandExecutor !==
null) {
541 if ($this->commandPool ===
null) {
542 throw new \DomainException(
"The command pool isn't configured for use.");
545 $command = $this->commandPool->get($commandCode);
563 return $this->getConfiguredValue(
'title');
571 $this->storeId = (int)$storeId;
579 return $this->storeId;
587 return $this->formBlockType;
595 return $this->infoBlockType;
603 return $this->infoInstance;
611 $this->infoInstance =
$info;
621 $this->eventManager->dispatch(
622 'payment_method_assign_data_' . $this->
getCode(),
630 $this->eventManager->dispatch(
631 'payment_method_assign_data',
648 $this->executeCommand(
652 'paymentAction' => $paymentAction,
653 'stateObject' => $stateObject
664 return $this->getConfiguredValue(
'payment_action');
acceptPayment(InfoInterface $payment)
getConfigData($field, $storeId=null)
capture(InfoInterface $payment, $amount)
void(InfoInterface $payment)
cancel(InfoInterface $payment)
isAvailable(CartInterface $quote=null)
canFetchTransactionInfo()
setInfoInstance(InfoInterface $info)
canUseForCountry($country)
initialize($paymentAction, $stateObject)
denyPayment(InfoInterface $payment)
__construct(ManagerInterface $eventManager, ValueHandlerPoolInterface $valueHandlerPool, PaymentDataObjectFactory $paymentDataObjectFactory, $code, $formBlockType, $infoBlockType, CommandPoolInterface $commandPool=null, ValidatorPoolInterface $validatorPool=null, CommandManagerInterface $commandExecutor=null, LoggerInterface $logger=null)
fetchTransactionInfo(InfoInterface $payment, $transactionId)
canUseForCurrency($currencyCode)
foreach( $_productCollection as $_product)() ?>" class $info
order(InfoInterface $payment, $amount)
canRefundPartialPerInvoice()
authorize(InfoInterface $payment, $amount)
refund(InfoInterface $payment, $amount)
catch(\Exception $e) $handler
assignData(\Magento\Framework\DataObject $data)