Ejemplo n.º 1
0
 /**
  * Run test getConfig method
  *
  * @param array $config
  * @param array $expected
  * @dataProvider getConfigDataProvider
  */
 public function testGetConfig($config, $expected)
 {
     $this->braintreeAdapter->expects(static::once())->method('generate')->willReturn(self::CLIENT_TOKEN);
     foreach ($config as $method => $value) {
         $this->config->expects(static::once())->method($method)->willReturn($value);
     }
     static::assertEquals($expected, $this->configProvider->getConfig());
 }
Ejemplo n.º 2
0
 /**
  * @covers \Magento\BraintreeTwo\Block\Form::getCcAvailableTypes
  * @param string $countryId
  * @param array $availableTypes
  * @param array $expected
  * @dataProvider countryCardTypesDataProvider
  */
 public function testGetCcAvailableTypes($countryId, array $availableTypes, array $expected)
 {
     $this->sessionQuote->expects(static::once())->method('getCountryId')->willReturn($countryId);
     $this->gatewayConfig->expects(static::once())->method('getAvailableCardTypes')->willReturn(self::$configCardTypes);
     $this->gatewayConfig->expects(static::once())->method('getCountryAvailableCardTypes')->with($countryId)->willReturn($availableTypes);
     $result = $this->block->getCcAvailableTypes();
     static::assertEquals($expected, array_values($result));
 }
Ejemplo n.º 3
0
 /**
  * Filter card types for specific country
  * @param array $configCardTypes
  * @param string $countryId
  * @return array
  */
 private function filterCardTypesForCountry(array $configCardTypes, $countryId)
 {
     $filtered = $configCardTypes;
     $countryCardTypes = $this->gatewayConfig->getCountryAvailableCardTypes($countryId);
     // filter card types only if specific card types are set for country
     if (!empty($countryCardTypes)) {
         $availableTypes = array_fill_keys($countryCardTypes, '');
         $filtered = array_intersect_key($filtered, $availableTypes);
     }
     return $filtered;
 }
Ejemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function build(array $buildSubject)
 {
     $paymentDO = $this->subjectReader->readPayment($buildSubject);
     $payment = $paymentDO->getPayment();
     $result = [self::AMOUNT => $this->formatPrice($this->subjectReader->readAmount($buildSubject)), self::PAYMENT_METHOD_NONCE => $payment->getAdditionalInformation(DataAssignObserver::PAYMENT_METHOD_NONCE)];
     $merchantAccountId = $this->config->getValue(Config::KEY_MERCHANT_ACCOUNT_ID);
     if (!empty($merchantAccountId)) {
         $result[self::MERCHANT_ACCOUNT_ID] = $merchantAccountId;
     }
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * Initializes credentials.
  *
  * @return void
  */
 protected function initCredentials()
 {
     if ($this->config->getValue(Config::KEY_ENVIRONMENT) == Environment::ENVIRONMENT_PRODUCTION) {
         $this->environment(Environment::ENVIRONMENT_PRODUCTION);
     } else {
         $this->environment(Environment::ENVIRONMENT_SANDBOX);
     }
     $this->merchantId($this->config->getValue(Config::KEY_MERCHANT_ID));
     $this->publicKey($this->config->getValue(Config::KEY_PUBLIC_KEY));
     $this->privateKey($this->config->getValue(Config::KEY_PRIVATE_KEY));
 }
 public function testBuild()
 {
     $additionalData = [DataAssignObserver::DEVICE_DATA => self::DEVICE_DATA];
     $expectedResult = [KountPaymentDataBuilder::DEVICE_DATA => self::DEVICE_DATA];
     $buildSubject = ['payment' => $this->paymentDO];
     $this->paymentMock->expects(static::exactly(count($additionalData)))->method('getAdditionalInformation')->willReturn($additionalData);
     $this->configMock->expects(static::once())->method('hasFraudProtection')->willReturn(true);
     $this->paymentDO->expects(static::once())->method('getPayment')->willReturn($this->paymentMock);
     $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDO);
     static::assertEquals($expectedResult, $this->builder->build($buildSubject));
 }
 /**
  * @param bool $verify
  * @param float $thresholdAmount
  * @param string $countryId
  * @param array $countries
  * @param array $expected
  * @covers \Magento\BraintreeTwo\Gateway\Request\ThreeDSecureDataBuilder::build
  * @dataProvider buildDataProvider
  */
 public function testBuild($verify, $thresholdAmount, $countryId, array $countries, array $expected)
 {
     $buildSubject = ['payment' => $this->paymentDO, 'amount' => 25];
     $this->configMock->expects(static::once())->method('isVerify3DSecure')->willReturn($verify);
     $this->configMock->expects(static::any())->method('getThresholdAmount')->willReturn($thresholdAmount);
     $this->configMock->expects(static::any())->method('get3DSecureSpecificCountries')->willReturn($countries);
     $this->billingAddress->expects(static::any())->method('getCountryId')->willReturn($countryId);
     $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDO);
     $this->subjectReaderMock->expects(self::once())->method('readAmount')->with($buildSubject)->willReturn(25);
     $result = $this->builder->build($buildSubject);
     static::assertEquals($expected, $result);
 }
 /**
  * Check if 3d secure is enabled
  * @param OrderAdapterInterface $order
  * @param float $amount
  * @return bool
  */
 private function is3DSecureEnabled(OrderAdapterInterface $order, $amount)
 {
     if (!$this->config->isVerify3DSecure() || $amount < $this->config->getThresholdAmount()) {
         return false;
     }
     $billingAddress = $order->getBillingAddress();
     $specificCounties = $this->config->get3DSecureSpecificCountries();
     if (!empty($specificCounties) && !in_array($billingAddress->getCountryId(), $specificCounties)) {
         return false;
     }
     return true;
 }
Ejemplo n.º 9
0
 public function testBuild()
 {
     $additionalData = [[DataAssignObserver::PAYMENT_METHOD_NONCE, self::PAYMENT_METHOD_NONCE]];
     $expectedResult = [PaymentDataBuilder::AMOUNT => 10.0, PaymentDataBuilder::PAYMENT_METHOD_NONCE => self::PAYMENT_METHOD_NONCE, PaymentDataBuilder::MERCHANT_ACCOUNT_ID => self::MERCHANT_ACCOUNT_ID];
     $buildSubject = ['payment' => $this->paymentDO, 'amount' => 10.0];
     $this->paymentMock->expects(static::exactly(count($additionalData)))->method('getAdditionalInformation')->willReturnMap($additionalData);
     $this->configMock->expects(static::once())->method('getValue')->with(Config::KEY_MERCHANT_ACCOUNT_ID)->willReturn(self::MERCHANT_ACCOUNT_ID);
     $this->paymentDO->expects(static::once())->method('getPayment')->willReturn($this->paymentMock);
     $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDO);
     $this->subjectReaderMock->expects(self::once())->method('readAmount')->with($buildSubject)->willReturn(10.0);
     static::assertEquals($expectedResult, $this->builder->build($buildSubject));
 }
 /**
  * Run test getConfig method
  *
  * @param array $config
  * @param array $expected
  * @dataProvider getConfigDataProvider
  */
 public function testGetConfig($config, $expected)
 {
     $this->braintreeAdapter->expects(static::once())->method('generate')->willReturn(self::CLIENT_TOKEN);
     foreach ($config as $method => $value) {
         $this->config->expects(static::once())->method($method)->willReturn($value);
     }
     $this->payPalConfig->expects(static::once())->method('isActive')->willReturn(true);
     $this->payPalConfig->expects(static::once())->method('isAllowToEditShippingAddress')->willReturn(true);
     $this->payPalConfig->expects(static::once())->method('getMerchantName')->willReturn('Test');
     $this->payPalConfig->expects(static::once())->method('getTitle')->willReturn('Payment Title');
     $this->localeResolver->expects(static::once())->method('getLocale')->willReturn('en_US');
     static::assertEquals($expected, $this->configProvider->getConfig());
 }
Ejemplo n.º 11
0
 /**
  * @inheritdoc
  */
 public function build(array $buildSubject)
 {
     $result = [];
     if (!$this->config->hasFraudProtection()) {
         return $result;
     }
     $paymentDO = $this->subjectReader->readPayment($buildSubject);
     $payment = $paymentDO->getPayment();
     $data = $payment->getAdditionalInformation();
     if (isset($data[DataAssignObserver::DEVICE_DATA])) {
         $result[self::DEVICE_DATA] = $data[DataAssignObserver::DEVICE_DATA];
     }
     return $result;
 }
 protected function setUp()
 {
     $this->paymentToken = $this->getMock(PaymentTokenInterface::class);
     $this->paymentTokenFactory = $this->getMockBuilder(PaymentTokenInterfaceFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->paymentTokenFactory->expects(self::once())->method('create')->willReturn($this->paymentToken);
     $this->paymentExtension = $this->getMockBuilder(OrderPaymentExtensionInterface::class)->setMethods(['setVaultPaymentToken', 'getVaultPaymentToken'])->disableOriginalConstructor()->getMock();
     $this->paymentExtensionFactory = $this->getMockBuilder(OrderPaymentExtensionInterfaceFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->paymentExtensionFactory->expects(self::once())->method('create')->willReturn($this->paymentExtension);
     $this->payment = $this->getMockBuilder(Payment::class)->disableOriginalConstructor()->setMethods(['__wakeup'])->getMock();
     $this->subjectReader = $this->getMockBuilder(SubjectReader::class)->disableOriginalConstructor()->getMock();
     $mapperArray = ["american-express" => "AE", "discover" => "DI", "jcb" => "JCB", "mastercard" => "MC", "master-card" => "MC", "visa" => "VI", "maestro" => "MI", "diners-club" => "DN", "unionpay" => "CUP"];
     $this->config = $this->getMockBuilder(Config::class)->setMethods(['getCctypesMapper'])->disableOriginalConstructor()->getMock();
     $this->config->expects(self::once())->method('getCctypesMapper')->willReturn($mapperArray);
     $this->paymentHandler = new VaultDetailsHandler($this->paymentTokenFactory, $this->paymentExtensionFactory, $this->config, $this->subjectReader);
 }
Ejemplo n.º 13
0
 /**
  * @param int $value
  * @param array $expected
  * @covers \Magento\BraintreeTwo\Gateway\Config\Config::get3DSecureSpecificCountries
  * @dataProvider threeDSecureSpecificCountriesDataProvider
  */
 public function testGet3DSecureSpecificCountries($value, array $expected)
 {
     $this->scopeConfigMock->expects(static::at(0))->method('getValue')->with($this->getPath(Config::KEY_VERIFY_ALLOW_SPECIFIC), ScopeInterface::SCOPE_STORE, null)->willReturn($value);
     if ($value !== Config::VALUE_3DSECURE_ALL) {
         $this->scopeConfigMock->expects(static::at(1))->method('getValue')->with($this->getPath(Config::KEY_VERIFY_SPECIFIC), ScopeInterface::SCOPE_STORE, null)->willReturn('GB,US');
     }
     static::assertEquals($expected, $this->model->get3DSecureSpecificCountries());
 }
 /**
  * Retrieve assoc array of checkout configuration
  *
  * @return array
  */
 public function getConfig()
 {
     $isPayPalActive = $this->payPalConfig->isActive();
     return ['payment' => [self::CODE => ['isActive' => $this->config->isActive(), 'isSingleUse' => !$isPayPalActive, 'clientToken' => $this->getClientToken(), 'ccTypesMapper' => $this->config->getCctypesMapper(), 'sdkUrl' => $this->config->getSdkUrl(), 'countrySpecificCardTypes' => $this->config->getCountrySpecificCardTypeConfig(), 'availableCardTypes' => $this->config->getAvailableCardTypes(), 'useCvv' => $this->config->isCvvEnabled(), 'environment' => $this->config->getEnvironment(), 'kountMerchantId' => $this->config->getKountMerchantId(), 'hasFraudProtection' => $this->config->hasFraudProtection(), 'merchantId' => $this->config->getMerchantId()], Config::CODE_3DSECURE => ['enabled' => $this->config->isVerify3DSecure(), 'thresholdAmount' => $this->config->getThresholdAmount(), 'specificCountries' => $this->config->get3DSecureSpecificCountries()], self::PAYPAL_CODE => ['isActive' => $isPayPalActive, 'title' => $this->payPalConfig->getTitle(), 'isAllowShippingAddressOverride' => $this->payPalConfig->isAllowToEditShippingAddress(), 'merchantName' => $this->payPalConfig->getMerchantName(), 'locale' => strtolower($this->localeResolver->getLocale()), 'paymentAcceptanceMarkSrc' => 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-medium.png']]];
 }
Ejemplo n.º 15
0
 /**
  * Get type of credit card mapped from Braintree
  *
  * @param string $type
  * @return array
  */
 private function getCreditCardType($type)
 {
     $replaced = str_replace(' ', '-', strtolower($type));
     $mapper = $this->config->getCctypesMapper();
     return $mapper[$replaced];
 }
Ejemplo n.º 16
0
 /**
  * Create mock for gateway config
  */
 private function initConfigMock()
 {
     $this->config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->setMethods(['getCctypesMapper'])->getMock();
     $this->config->expects(static::once())->method('getCctypesMapper')->willReturn(['american-express' => 'AE', 'discover' => 'DI', 'jcb' => 'JCB', 'mastercard' => 'MC', 'master-card' => 'MC', 'visa' => 'VI']);
 }
 /**
  * Retrieve assoc array of checkout configuration
  *
  * @return array
  */
 public function getConfig()
 {
     return ['payment' => [self::CODE => ['clientToken' => $this->getClientToken(), 'ccTypesMapper' => $this->config->getCctypesMapper(), 'sdkUrl' => $this->config->getSdkUrl(), 'countrySpecificCardTypes' => $this->config->getCountrySpecificCardTypeConfig(), 'availableCardTypes' => $this->config->getAvailableCardTypes(), 'useCvv' => $this->config->isCvvEnabled(), 'environment' => $this->config->getEnvironment(), 'kountMerchantId' => $this->config->getKountMerchantId(), 'hasFraudProtection' => $this->config->hasFraudProtection(), 'merchantId' => $this->config->getMerchantId()], Config::CODE_3DSECURE => ['enabled' => $this->config->isVerify3DSecure(), 'thresholdAmount' => $this->config->getThresholdAmount(), 'specificCountries' => $this->config->get3DSecureSpecificCountries()]]];
 }