Пример #1
0
 /**
  * Generate a new client token if necessary
  * @return string
  */
 public function getClientToken()
 {
     if (empty($this->clientToken)) {
         $this->clientToken = $this->adapter->generate();
     }
     return $this->clientToken;
 }
Пример #2
0
 /**
  * Run test placeRequest method
  *
  * @return void
  */
 public function testPlaceRequestSuccess()
 {
     $response = $this->getResponseObject();
     $this->adapter->expects($this->once())->method('sale')->with($this->getTransferData())->willReturn($response);
     $this->loggerMock->expects($this->once())->method('debug')->with(['request' => $this->getTransferData(), 'client' => TransactionSale::class, 'response' => ['success' => 1]]);
     $actualResult = $this->model->placeRequest($this->getTransferObjectMock());
     $this->assertTrue(is_object($actualResult['object']));
     $this->assertEquals(['object' => $response], $actualResult);
 }
 /**
  * @covers \Magento\Braintree\Gateway\Http\Client\TransactionSubmitForSettlement::process
  */
 public function testPlaceRequest()
 {
     $data = new Successful(['success'], [true]);
     $this->adapter->expects(static::once())->method('submitForSettlement')->willReturn($data);
     /** @var TransferInterface|\PHPUnit_Framework_MockObject_MockObject $transferObjectMock */
     $transferObjectMock = $this->getTransferObjectMock();
     $response = $this->client->placeRequest($transferObjectMock);
     static::assertTrue(is_object($response['object']));
     static::assertEquals(['object' => $data], $response);
 }
 /**
  * @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\Command\GetPaymentNonceCommand::execute
  */
 public function testExecute()
 {
     $publicHash = '3wv2m24d2er3';
     $customerId = 1;
     $token = 'jd2vnq';
     $nonce = 's1dj23';
     $this->subjectReader->expects(static::once())->method('readPublicHash')->willReturn($publicHash);
     $this->subjectReader->expects(static::once())->method('readCustomerId')->willReturn($customerId);
     $this->tokenManagement->expects(static::once())->method('getByPublicHash')->with($publicHash, $customerId)->willReturn($this->paymentToken);
     $this->paymentToken->expects(static::once())->method('getGatewayToken')->willReturn($token);
     $obj = new \stdClass();
     $obj->success = true;
     $obj->paymentMethodNonce = new \stdClass();
     $obj->paymentMethodNonce->nonce = $nonce;
     $this->adapter->expects(static::once())->method('createNonce')->with($token)->willReturn($obj);
     $this->responseValidator->expects(static::once())->method('validate')->with(['response' => ['object' => $obj]])->willReturn($this->validationResult);
     $this->validationResult->expects(static::once())->method('isValid')->willReturn(true);
     $this->validationResult->expects(static::never())->method('getFailsDescription');
     $expected = $this->getMockBuilder(ArrayResult::class)->disableOriginalConstructor()->setMethods(['get'])->getMock();
     $expected->expects(static::once())->method('get')->willReturn(['paymentMethodNonce' => $nonce]);
     $this->resultFactory->expects(static::once())->method('create')->willReturn($expected);
     $actual = $this->command->execute(['publicHash' => $publicHash, 'customerId' => $customerId]);
     static::assertEquals($expected, $actual);
     static::assertEquals($nonce, $actual->get()['paymentMethodNonce']);
 }
 /**
  * Fetch collection from Braintree
  * @return \Braintree\ResourceCollection|null
  */
 protected function fetchIdsCollection()
 {
     if (empty($this->filtersList)) {
         return null;
     }
     // Fetch all transaction IDs in order to filter
     if (empty($this->collection)) {
         $filters = $this->getFilters();
         $this->collection = $this->braintreeAdapter->search($filters);
     }
     return $this->collection;
 }
 /**
  * Get items with limit
  */
 public function testGetItemsWithNullLimit()
 {
     $transations = range(1, TransactionsCollection::TRANSACTION_MAXIMUM_COUNT + 10);
     $this->filterMapperMock->expects($this->once())->method('getFilter')->willReturn(new BraintreeSearchNodeStub());
     $this->braintreeAdapterMock->expects($this->once())->method('search')->willReturn($transations);
     $this->entityFactoryMock->expects($this->exactly(TransactionsCollection::TRANSACTION_MAXIMUM_COUNT))->method('create')->willReturn($this->transactionMapMock);
     $collection = new TransactionsCollection($this->entityFactoryMock, $this->braintreeAdapterMock, $this->filterMapperMock);
     $collection->setPageSize(null);
     $collection->addFieldToFilter('orderId', ['like' => '0']);
     $items = $collection->getItems();
     $this->assertEquals(TransactionsCollection::TRANSACTION_MAXIMUM_COUNT, count($items));
     $this->assertInstanceOf(DocumentInterface::class, $items[1]);
 }
 /**
  * @param string $lastTransactionId
  * @return \Braintree\ResourceCollection|\PHPUnit_Framework_MockObject_MockObject
  */
 private function getNotExpiredExpectedCollection($lastTransactionId)
 {
     $isExpectations = ['id' => ['is' => $lastTransactionId], 'status' => [\Braintree\Transaction::AUTHORIZATION_EXPIRED]];
     $collection = $this->getMockBuilder(\Braintree\ResourceCollection::class)->disableOriginalConstructor()->getMock();
     $this->braintreeAdapter->expects(static::once())->method('search')->with(static::callback(function (array $filters) use($isExpectations) {
         foreach ($filters as $filter) {
             /** @var IsNode $filter */
             if (!isset($isExpectations[$filter->name])) {
                 return false;
             }
             if ($isExpectations[$filter->name] !== $filter->toParam()) {
                 return false;
             }
         }
         return true;
     }))->willReturn($collection);
     return $collection;
 }
 /**
  * @param OrderPaymentInterface $payment
  * @return boolean
  */
 private function isExpiredAuthorization(OrderPaymentInterface $payment)
 {
     $collection = $this->braintreeAdapter->search([$this->braintreeSearchAdapter->id()->is($payment->getLastTransId()), $this->braintreeSearchAdapter->status()->is(Transaction::AUTHORIZATION_EXPIRED)]);
     return $collection->maximumCount() > 0;
 }
Пример #10
0
 /**
  * @covers \Magento\Braintree\Model\Ui\ConfigProvider::getClientToken
  */
 public function testGetClientToken()
 {
     $this->braintreeAdapter->expects(static::once())->method('generate')->willReturn(self::CLIENT_TOKEN);
     static::assertEquals(self::CLIENT_TOKEN, $this->configProvider->getClientToken());
 }