Esempio n. 1
0
 public function testIsBillingAddressEnabled()
 {
     $isEnabled = 1;
     $prefix = 'payment/braintree_paypal/';
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with($prefix . PayPal::KEY_REQUIRE_BILLING_ADDRESS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null)->willReturn($isEnabled);
     $this->assertEquals(true, $this->model->isBillingAddressEnabled());
 }
Esempio n. 2
0
 /**
  * @dataProvider getConfigDataProvider
  */
 public function testGetConfig($configData, $locale, $expectedResult)
 {
     foreach ($configData as $key => $value) {
         $this->configMock->expects($this->any())->method($key)->willReturn($value);
     }
     $this->localResolverMock->expects($this->any())->method('getLocale')->willReturn($locale);
     $this->assertEquals($expectedResult, $this->model->getConfig());
 }
Esempio n. 3
0
 /**
  * @return array|void
  */
 public function getConfig()
 {
     if (!$this->config->isActive()) {
         return [];
     }
     $clientToken = $this->config->getClientToken();
     $config = ['payment' => ['braintree_paypal' => ['clientToken' => $clientToken, 'locale' => $this->localeResolver->getLocale(), 'merchantDisplayName' => $this->config->getMerchantNameOverride()]]];
     return $config;
 }
Esempio n. 4
0
 public function testDispatchButtonNotEnabled()
 {
     $resultRedirect = new \Magento\Framework\DataObject();
     $this->braintreePayPalConfigMock->expects($this->once())->method('isActive')->willReturn(true);
     $this->braintreePayPalConfigMock->expects($this->once())->method('isShortcutCheckoutEnabled')->willReturn(false);
     $this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\ActionInterface::FLAG_NO_DISPATCH);
     $this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($resultRedirect);
     $this->assertEquals($resultRedirect, $this->controller->execute($this->requestMock));
     $this->assertEquals('noRoute', $resultRedirect->getPath());
 }
Esempio n. 5
0
 /**
  * Check whether payment method is enabled
  *
  * @param RequestInterface $request
  * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\App\ResponseInterface
  */
 public function dispatch(RequestInterface $request)
 {
     if (!$this->braintreePayPalConfig->isActive() || !$this->braintreePayPalConfig->isShortcutCheckoutEnabled()) {
         $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath('noRoute');
         return $resultRedirect;
     }
     return parent::dispatch($request);
 }
 public function testAddPaypalShortcutsNotEnabled()
 {
     $orPosition = 'before';
     $containerMock = $this->getMockBuilder('\\Magento\\Catalog\\Block\\ShortcutButtons')->disableOriginalConstructor()->getMock();
     $event = new \Magento\Framework\DataObject(['is_catalog_product' => false, 'container' => $containerMock, 'or_position' => $orPosition]);
     $observer = new \Magento\Framework\Event\Observer(['event' => $event]);
     $this->paypalMethodMock->expects($this->once())->method('isActive')->willReturn(true);
     $this->paypalConfigMock->expects($this->once())->method('isShortcutCheckoutEnabled')->willReturn(false);
     $containerMock->expects($this->never())->method('getLayout');
     $this->addPaypalShortcutsObserver->execute($observer);
 }
 /**
  * Add Braintree PayPal shortcut buttons
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     //Don't display shortcut on product view page
     if (!$this->methodPayPal->isActive() || !$this->paypalConfig->isShortcutCheckoutEnabled()) {
         return;
     }
     /** @var \Magento\Catalog\Block\ShortcutButtons $shortcutButtons */
     $shortcutButtons = $observer->getEvent()->getContainer();
     /** @var Shortcut $shortcut */
     $shortcut = $shortcutButtons->getLayout()->createBlock(self::PAYPAL_SHORTCUT_BLOCK, '', ['data' => [Shortcut::MINI_CART_FLAG_KEY => !$observer->getEvent()->getIsCatalogProduct()]]);
     if ($shortcut->skipShortcutForGuest()) {
         return;
     }
     $shortcut->setShowOrPosition($observer->getEvent()->getOrPosition());
     $shortcutButtons->addShortcut($shortcut);
 }
Esempio n. 8
0
 /**
  * Validate data
  *
  * @return $this
  * @throws LocalizedException
  */
 public function validate()
 {
     $info = $this->getInfoInstance();
     if ($info instanceof \Magento\Sales\Model\Order\Payment) {
         $billingCountry = $info->getOrder()->getBillingAddress()->getCountryId();
     } else {
         $billingCountry = $info->getQuote()->getBillingAddress()->getCountryId();
     }
     if (!$this->payPalConfig->canUseForCountry($billingCountry)) {
         throw new LocalizedException(__('Selected payment type is not allowed for billing country.'));
     }
     return $this;
 }
Esempio n. 9
0
 public function testExecuteValidationFailure()
 {
     $paymentMethodNonce = 'nonce';
     $email = '*****@*****.**';
     $billingAddress = ['someAddress'];
     $details = ['email' => $email, 'billingAddress' => $billingAddress];
     $detailsEncoded = json_encode($details);
     $this->braintreePayPalConfigMock->expects($this->once())->method('isBillingAddressEnabled')->willReturn(true);
     $this->requestMock->expects($this->at(0))->method('getParam')->with('payment_method_nonce')->willReturn($paymentMethodNonce);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('details')->willReturn($detailsEncoded);
     $this->setupCart();
     $errorMessage = new \Magento\Framework\Phrase('Selected payment type is not allowed for billing country.');
     $this->paymentMethodInstanceMock->expects($this->once())->method('validate')->willThrowException(new \Magento\Framework\Exception\LocalizedException($errorMessage));
     $this->messageManagerMock->expects($this->once())->method('addError')->with(new \Magento\Framework\Phrase('Selected payment type is not allowed for billing country.'));
     $resultRedirect = $this->getMockBuilder('\\Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $resultRedirect->expects($this->once())->method('setPath')->with('checkout/cart')->willReturnSelf();
     $this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)->willReturn($resultRedirect);
     $this->assertEquals($resultRedirect, $this->controller->execute());
 }
Esempio n. 10
0
 public function testGetConfigData()
 {
     $field = 'configFieldName';
     $storeId = '2';
     $configValue = 'configValue';
     $this->payPalConfigMock->expects($this->once())->method('getConfigData')->with($field, $storeId)->willReturn($configValue);
     $this->assertEquals($configValue, $this->model->getConfigData($field, $storeId));
 }
Esempio n. 11
0
 public function testEnableBillingAddress()
 {
     $flag = true;
     $this->paypalConfigMock->expects($this->once())->method('isBillingAddressEnabled')->willReturn($flag);
     $this->assertEquals($flag, $this->block->enableBillingAddress());
 }
Esempio n. 12
0
 /**
  * @return bool
  */
 public function enableBillingAddress()
 {
     return $this->paypalConfig->isBillingAddressEnabled();
 }