/** * 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)); }
/** * @inheritdoc */ public function build(array $buildSubject) { $paymentDO = $this->subjectReader->readPayment($buildSubject); $payment = $paymentDO->getPayment(); $order = $paymentDO->getOrder(); $result = [self::AMOUNT => $this->formatPrice($this->subjectReader->readAmount($buildSubject)), self::PAYMENT_METHOD_NONCE => $payment->getAdditionalInformation(DataAssignObserver::PAYMENT_METHOD_NONCE), self::ORDER_ID => $order->getOrderIncrementId()]; $merchantAccountId = $this->config->getValue(Config::KEY_MERCHANT_ACCOUNT_ID); if (!empty($merchantAccountId)) { $result[self::MERCHANT_ACCOUNT_ID] = $merchantAccountId; } return $result; }
/** * @param bool $verify * @param float $thresholdAmount * @param string $countryId * @param array $countries * @param array $expected * @covers \Magento\Braintree\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; }
/** * 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()); }
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::ORDER_ID => '000000101', 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->paymentDO->expects(static::once())->method('getOrder')->willReturn($this->orderMock); $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDO); $this->subjectReaderMock->expects(self::once())->method('readAmount')->with($buildSubject)->willReturn(10.0); $this->orderMock->expects(static::once())->method('getOrderIncrementId')->willReturn('000000101'); static::assertEquals($expectedResult, $this->builder->build($buildSubject)); }
/** * @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); }
/** * @param int $value * @param array $expected * @covers \Magento\Braintree\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']]]; }
/** * 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']); }
/** * 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]; }