public function testValidateSuccess()
 {
     $obj = new \stdClass();
     $obj->success = true;
     $obj->paymentMethodNonce = new \stdClass();
     $obj->paymentMethodNonce->nonce = 'fj2hd9239kd1kq9';
     $subject = ['response' => ['object' => $obj]];
     $this->subjectReader->expects(static::once())->method('readResponseObject')->willReturn($obj);
     $result = $this->getMock(ResultInterface::class);
     $this->resultInterfaceFactory->expects(self::once())->method('create')->with(['isValid' => true, 'failsDescription' => []])->willReturn($result);
     $actual = $this->validator->validate($subject);
     static::assertEquals($result, $actual);
 }
 /**
  * @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]]);
 }