/** * @inheritdoc * @throws \Exception */ public function execute(array $commandSubject) { $publicHash = $this->subjectReader->readPublicHash($commandSubject); $customerId = $this->subjectReader->readCustomerId($commandSubject); $paymentToken = $this->tokenManagement->getByPublicHash($publicHash, $customerId); if (!$paymentToken) { throw new Exception('No available payment tokens'); } $data = $this->adapter->createNonce($paymentToken->getGatewayToken()); $result = $this->responseValidator->validate(['response' => ['object' => $data]]); if (!$result->isValid()) { throw new Exception(__(implode("\n", $result->getFailsDescription()))); } return $this->resultFactory->create(['array' => ['paymentMethodNonce' => $data->paymentMethodNonce->nonce]]); }
/** * @covers \Magento\Braintree\Gateway\Helper\SubjectReader::readCustomerId */ public function testReadCustomerId() { $customerId = 1; static::assertEquals($customerId, $this->subjectReader->readCustomerId(['customer_id' => $customerId])); }