Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetPaymentNonceCommand.php
Go to the documentation of this file.
1 <?php
8 
12 use Magento\Payment\Gateway\Command\Result\ArrayResultFactory;
15 
20 {
21 
25  private $tokenManagement;
26 
30  private $adapterFactory;
31 
35  private $resultFactory;
36 
40  private $subjectReader;
41 
45  private $responseValidator;
46 
54  public function __construct(
55  PaymentTokenManagementInterface $tokenManagement,
56  BraintreeAdapterFactory $adapterFactory,
57  ArrayResultFactory $resultFactory,
58  SubjectReader $subjectReader,
59  PaymentNonceResponseValidator $responseValidator
60  ) {
61  $this->tokenManagement = $tokenManagement;
62  $this->adapterFactory = $adapterFactory;
63  $this->resultFactory = $resultFactory;
64  $this->subjectReader = $subjectReader;
65  $this->responseValidator = $responseValidator;
66  }
67 
72  public function execute(array $commandSubject)
73  {
74  $publicHash = $this->subjectReader->readPublicHash($commandSubject);
75  $customerId = $this->subjectReader->readCustomerId($commandSubject);
76  $paymentToken = $this->tokenManagement->getByPublicHash($publicHash, $customerId);
77  if (!$paymentToken) {
78  throw new \Exception('No available payment tokens');
79  }
80 
81  $storeId = $this->subjectReader->readStoreId($commandSubject);
82  $data = $this->adapterFactory->create($storeId)
83  ->createNonce($paymentToken->getGatewayToken());
84  $result = $this->responseValidator->validate(['response' => ['object' => $data]]);
85 
86  if (!$result->isValid()) {
87  throw new \Exception(__(implode("\n", $result->getFailsDescription())));
88  }
89 
90  return $this->resultFactory->create(['array' => ['paymentMethodNonce' => $data->paymentMethodNonce->nonce]]);
91  }
92 }
__construct(PaymentTokenManagementInterface $tokenManagement, BraintreeAdapterFactory $adapterFactory, ArrayResultFactory $resultFactory, SubjectReader $subjectReader, PaymentNonceResponseValidator $responseValidator)
__()
Definition: __.php:13