public function testHandleWithoutStoreId() { $field = 'field'; $expected = 'some value'; $this->configMock->expects($this->once())->method('getValue')->with($field, null)->willReturn($expected); $this->assertEquals($expected, $this->model->handle(['field' => $field])); }
/** * @dataProvider validateAllowspecificFalseDataProvider */ public function testValidateAllowspecificFalse($storeId, $allowspecific, $isValid) { $validationSubject = ['storeId' => $storeId]; $this->configMock->expects($this->at(0))->method('getValue')->with('allowspecific', $storeId)->willReturn($allowspecific); $this->resultFactoryMock->expects($this->once())->method('create')->with(['isValid' => $isValid])->willReturn($this->resultMock); $this->assertSame($this->resultMock, $this->model->validate($validationSubject)); }
/** * @return PaymentTokenRepositoryInterface */ private function getInstance() { if (!$this->vaultPayment->isActive()) { return $this->nullRepository; } $methodCode = $this->config->getValue(VaultProvidersMap::VALUE_CODE); return isset($this->repositories[$methodCode]) ? $this->objectManager->get($this->repositories[$methodCode]) : $this->nullRepository; }
/** * Builds ENV request * * @param array $buildSubject * @return array */ public function build(array $buildSubject) { if (!isset($buildSubject['payment']) || !$buildSubject['payment'] instanceof PaymentDataObjectInterface) { throw new \InvalidArgumentException('Payment data object should be provided'); } /** @var PaymentDataObjectInterface $payment */ $payment = $buildSubject['payment']; $order = $payment->getOrder(); $address = $order->getShippingAddress(); return ['TXN_TYPE' => 'A', 'INVOICE' => $order->getOrderIncrementId(), 'AMOUNT' => $order->getGrandTotalAmount(), 'CURRENCY' => $order->getCurrencyCode(), 'EMAIL' => $address->getEmail(), 'MERCHANT_KEY' => $this->config->getValue('merchant_gateway_key', $order->getStoreId())]; }
/** * @param array $validationSubject * @return bool * @throws NotFoundException * @throws \Exception */ public function validate(array $validationSubject) { $isValid = true; $storeId = $validationSubject['storeId']; if ((int) $this->config->getValue('allowspecific', $storeId) === 1) { $availableCountries = explode(',', $this->config->getValue('specificcountry', $storeId)); if (!in_array($validationSubject['country'], $availableCountries)) { $isValid = false; } } return $this->resultFactory->create(['isValid' => $isValid]); }
/** * Builds ENV request * * @param array $buildSubject * @return array */ public function build(array $buildSubject) { if (!isset($buildSubject['payment']) || !$buildSubject['payment'] instanceof PaymentDataObjectInterface) { throw new \InvalidArgumentException('Payment data object should be provided'); } /** @var PaymentDataObjectInterface $paymentDO */ $paymentDO = $buildSubject['payment']; $order = $paymentDO->getOrder(); $payment = $paymentDO->getPayment(); if (!$payment instanceof OrderPaymentInterface) { throw new \LogicException('Order payment should be provided.'); } return ['TXN_TYPE' => 'S', 'TXN_ID' => $payment->getLastTransId(), 'MERCHANT_KEY' => $this->config->getValue('merchant_gateway_key', $order->getStoreId())]; }
/** * Prepare PayPal-specific payment information * * @param \Magento\Framework\DataObject|array|null $transport * @return \Magento\Framework\DataObject */ protected function _prepareSpecificInformation($transport = null) { $transport = parent::_prepareSpecificInformation($transport); $payment = $this->getInfo(); $fieldsToStore = explode(',', (string) $this->config->getValue('paymentInfoKeys')); if ($this->getIsSecureMode()) { $fieldsToStore = array_diff($fieldsToStore, explode(',', (string) $this->config->getValue('privateInfoKeys'))); } foreach ($fieldsToStore as $field) { if ($payment->getAdditionalInformation($field) !== null) { $this->setDataToTransfer($transport, $field, $payment->getAdditionalInformation($field)); } } return $transport; }
/** * Run test for proxy methods */ public function testProxyCall() { /** @var SearchCriteria|\PHPUnit_Framework_MockObject_MockObject $searchCriteriaMock */ $searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class)->getMockForAbstractClass(); /** @var PaymentTokenSearchResultsInterface|\PHPUnit_Framework_MockObject_MockObject $searchResultMock */ $searchResultMock = $this->getMockBuilder(PaymentTokenSearchResultsInterface::class)->getMockForAbstractClass(); /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $tokenMock */ $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class)->getMockForAbstractClass(); /** @var PaymentTokenRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject $proxyCallsMock */ $proxyCallsMock = $this->getMockBuilder(PaymentTokenRepositoryInterface::class)->getMockForAbstractClass(); $this->configMock->expects(self::once())->method('getValue')->with(VaultProvidersMap::VALUE_CODE)->willReturn('code'); $this->objectManagerMock->expects(self::once())->method('get')->with(get_class($proxyCallsMock))->willReturn($proxyCallsMock); $proxy = new PaymentTokenRepositoryProxy($this->defaultRepository, $this->configMock, $this->objectManagerMock, ['code' => get_class($proxyCallsMock)]); $proxyCallsMock->expects(self::once())->method('delete')->with($tokenMock)->willReturn(self::DELETE_RESULT); $proxyCallsMock->expects(self::once())->method('getById')->with(1)->willReturn($tokenMock); $proxyCallsMock->expects(self::once())->method('getList')->with($searchCriteriaMock)->willReturn($searchResultMock); $proxyCallsMock->expects(self::once())->method('save')->with($tokenMock)->willReturn(self::SAVE_RESULT); self::assertEquals(self::DELETE_RESULT, $proxy->delete($tokenMock)); self::assertEquals($tokenMock, $proxy->getById(1)); self::assertEquals($searchResultMock, $proxy->getList($searchCriteriaMock)); self::assertEquals(self::SAVE_RESULT, $proxy->save($tokenMock)); }
/** * @return PaymentTokenRepositoryInterface */ private function getInstance() { $methodCode = $this->config->getValue(VaultProvidersMap::VALUE_CODE); return isset($this->repositories[$methodCode]) ? $this->objectManager->get($this->repositories[$methodCode]) : $this->defaultRepository; }
/** * @inheritdoc */ public function handle(array $subject, $storeId = null) { $vaultPaymentCode = $this->config->getValue(VaultProvidersMap::VALUE_CODE, $storeId); return (int) ((int) $this->config->getValue('active', $storeId) === 1 && $vaultPaymentCode && $vaultPaymentCode !== VaultProvidersMap::EMPTY_VALUE); }
/** * Retrieve method configured value * * @param array $subject * @param int|null $storeId * * @return mixed */ public function handle(array $subject, $storeId = null) { return $this->configInterface->getValue(SubjectReader::readField($subject), $storeId); }
/** * Run test for handle method */ public function testHandleVaultPaymentNotSet() { $this->configMock->expects(self::at(0))->method('getValue')->with(VaultProvidersMap::VALUE_CODE)->willReturn(VaultProvidersMap::EMPTY_VALUE); $this->configMock->expects(self::at(1))->method('getValue')->with('active')->willReturn(1); self::assertEquals(0, $this->activeHandler->handle([], 1)); }
/** * Retrieve method configured value * * @param string $field * @param int|null $storeId * * @return mixed */ public function handle($field, $storeId = null) { return $this->configInterface->getValue($field, $storeId); }
/** * @param null $storeId * @return string|null */ public function getProviderCode($storeId = null) { return $this->config->getValue(VaultProvidersMap::VALUE_CODE, $this->getStore() ?: $storeId); }
/** * Whether debug is enabled in configuration * * @return bool */ private function isDebugOn() { return $this->config and (bool) $this->config->getValue('debug'); }
/** * @inheritdoc */ public function isActive($storeId = null) { return $this->getVaultProvider()->isActive($storeId) && $this->config->getValue(self::$activeKey, $this->getStore() ?: $storeId); }