/**
  * @param array $paymentMethodsAvailability
  * @param array $blocks
  * @dataProvider addAvailabilityOfMethodsDataProvider
  */
 public function testAddPaypalShortcuts($paymentMethodsAvailability, $blocks)
 {
     $this->paypalConfigMock->expects($this->any())->method('isMethodAvailable')->will($this->returnValueMap($paymentMethodsAvailability));
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->setMethods(['createBlock'])->disableOriginalConstructor()->getMock();
     $shortcutButtonsMock = $this->getMockBuilder('Magento\\Catalog\\Block\\ShortcutButtons')->setMethods(['getLayout', 'addShortcut'])->disableOriginalConstructor()->getMock();
     $blockInstances = [];
     $atPosition = 0;
     foreach ($blocks as $blockName => $blockInstance) {
         if ($this->paypalConfigMock->isMethodAvailable($blockInstance[1])) {
             $block = $this->getMockBuilder($blockInstance[0])->setMethods(null)->disableOriginalConstructor()->getMock();
             $blockInstances[$blockName] = $block;
             $layoutMock->expects(new MethodInvokedAtIndex($atPosition))->method('createBlock')->with($blockName)->will($this->returnValue($block));
             $atPosition++;
         }
     }
     $shortcutButtonsMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock));
     $atPosition = 0;
     foreach ($blocks as $blockName => $blockInstance) {
         if ($this->paypalConfigMock->isMethodAvailable($blockInstance[1])) {
             $shortcutButtonsMock->expects(new MethodInvokedAtIndex($atPosition))->method('addShortcut')->with($this->identicalTo($blockInstances[$blockName]));
             $atPosition++;
         }
     }
     $this->_event->setContainer($shortcutButtonsMock);
     $this->_model->execute($this->_observer);
 }
 /**
  * @expectedException \Magento\Framework\Model\Exception
  */
 public function testInitialize()
 {
     $order = $this->getMock('Magento\\Sales\\Model\\Order', [], [], '', false);
     $this->infoInstance->expects($this->any())->method('getOrder')->will($this->returnValue($order));
     $this->paypalConfig->expects($this->once())->method('getBuildNotationCode')->will($this->returnValue('build notation code'));
     $this->payflowRequest->expects($this->once())->method('setData')->with('BNCODE', 'build notation code')->will($this->returnSelf());
     $this->model->initialize(\Magento\Paypal\Model\Config::PAYMENT_ACTION_AUTH, new \Magento\Framework\Object());
 }
 /**
  * @param CurrentCustomer $currentCustomer
  * @param Data $paypalData
  * @param ConfigFactory $paypalConfigFactory
  * @param UrlInterface $urlBuilder
  * @param Escaper $escaper
  */
 public function __construct(CurrentCustomer $currentCustomer, Data $paypalData, ConfigFactory $paypalConfigFactory, UrlInterface $urlBuilder, Escaper $escaper)
 {
     $this->currentCustomer = $currentCustomer;
     $this->paypalData = $paypalData;
     $this->urlBuilder = $urlBuilder;
     $this->escaper = $escaper;
     $this->config = $paypalConfigFactory->create();
     $this->config->setMethod(Config::METHOD_EXPRESS);
 }
Exemple #4
0
 /**
  * Disable block output if banner turned off or PublisherId is miss
  *
  * @return string
  */
 protected function _toHtml()
 {
     $publisherId = $this->_paypalConfig->getBmlPublisherId();
     $display = $this->_paypalConfig->getBmlDisplay($this->_section);
     $position = $this->_paypalConfig->getBmlPosition($this->_section);
     if (!$publisherId || $display == 0 || $this->_position != $position) {
         return '';
     }
     $this->setData('publisher_id', $publisherId);
     $this->setData('size', $this->_paypalConfig->getBmlSize($this->_section));
     return parent::_toHtml();
 }
Exemple #5
0
 /**
  * Check whether customer should be asked confirmation whether to sign a billing agreement
  *
  * @param \Magento\Paypal\Model\Config $config
  * @param int $customerId
  * @return bool
  */
 public function shouldAskToCreateBillingAgreement(\Magento\Paypal\Model\Config $config, $customerId)
 {
     if (null === self::$_shouldAskToCreateBillingAgreement) {
         self::$_shouldAskToCreateBillingAgreement = false;
         if ($customerId && $config->shouldAskToCreateBillingAgreement()) {
             if ($this->_agreementFactory->create()->needToCreateForCustomer($customerId)) {
                 self::$_shouldAskToCreateBillingAgreement = true;
             }
         }
     }
     return self::$_shouldAskToCreateBillingAgreement;
 }
 public function testInitialize()
 {
     $order = $this->getMock('Magento\\Sales\\Model\\Order', [], [], '', false);
     $this->infoInstance->expects($this->any())->method('getOrder')->will($this->returnValue($order));
     $this->infoInstance->expects($this->any())->method('setAdditionalInformation')->will($this->returnSelf());
     $this->paypalConfig->expects($this->once())->method('getBuildNotationCode')->will($this->returnValue('build notation code'));
     $response = new \Magento\Framework\DataObject(['result' => '0', 'pnref' => 'V19A3D27B61E', 'respmsg' => 'Approved', 'authcode' => '510PNI', 'hostcode' => 'A', 'request_id' => 'f930d3dc6824c1f7230c5529dc37ae5e', 'result_code' => '0']);
     $this->gatewayMock->expects($this->once())->method('postRequest')->willReturn($response);
     $this->payflowRequest->expects($this->exactly(3))->method('setData')->willReturnMap([['user' => null, 'vendor' => null, 'partner' => null, 'pwd' => null, 'verbosity' => null, 'BNCODE' => 'build notation code', 'tender' => 'C'], $this->returnSelf()], ['USER1', 1, $this->returnSelf()], ['USER2', 'a20d3dc6824c1f7780c5529dc37ae5e', $this->returnSelf()]);
     $stateObject = new \Magento\Framework\DataObject();
     $this->model->initialize(\Magento\Paypal\Model\Config::PAYMENT_ACTION_AUTH, $stateObject);
 }
 protected function setUp()
 {
     $this->paypalConfig = $this->getMock(Config::class, [], [], '', false);
     $this->paypalConfig->expects($this->once())->method('setMethod')->will($this->returnSelf());
     $this->paypalConfig->expects($this->once())->method('setMethod')->with(Config::METHOD_EXPRESS);
     $paypalConfigFactory = $this->getMock(ConfigFactory::class, ['create'], [], '', false);
     $paypalConfigFactory->expects($this->once())->method('create')->will($this->returnValue($this->paypalConfig));
     $customerId = 20;
     $this->currentCustomer = $this->getMock(CurrentCustomer::class, [], [], '', false);
     $this->currentCustomer->expects($this->any())->method('getCustomerId')->willReturn($customerId);
     $this->paypalData = $this->getMock(Data::class, [], [], '', false);
     $helper = new ObjectManager($this);
     $this->billingAgreement = $helper->getObject(BillingAgreement::class, ['paypalConfigFactory' => $paypalConfigFactory, 'paypalData' => $this->paypalData, 'currentCustomer' => $this->currentCustomer]);
 }
 protected function setUp()
 {
     $this->_paypalConfig = $this->getMock('Magento\\Paypal\\Model\\Config', [], [], '', false);
     $this->_paypalConfig->expects($this->once())->method('setMethod')->will($this->returnSelf());
     $paypalConfigFactory = $this->getMock('Magento\\Paypal\\Model\\ConfigFactory', ['create'], [], '', false);
     $paypalConfigFactory->expects($this->once())->method('create')->will($this->returnValue($this->_paypalConfig));
     $mark = $this->getMock('Magento\\Framework\\View\\Element\\Template', [], [], '', false);
     $mark->expects($this->once())->method('setTemplate')->will($this->returnSelf());
     $mark->expects($this->any())->method('__call')->will($this->returnSelf());
     $layout = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface');
     $layout->expects($this->once())->method('createBlock')->with('Magento\\Framework\\View\\Element\\Template')->will($this->returnValue($mark));
     $localeResolver = $this->getMock('Magento\\Framework\\Locale\\ResolverInterface', [], [], '', false, false);
     $helper = new ObjectManager($this);
     $this->_model = $helper->getObject('Magento\\Paypal\\Block\\PayflowExpress\\Form', ['paypalConfigFactory' => $paypalConfigFactory, 'layout' => $layout, 'localeResolver' => $localeResolver]);
 }
Exemple #9
0
 /**
  * Log debug data to file
  *
  * @return void
  */
 protected function _debug()
 {
     if ($this->_config && $this->_config->getConfigValue('debug')) {
         $file = $this->_config->getMethodCode() ? "payment_{$this->_config->getMethodCode()}.log" : self::DEFAULT_LOG_FILE;
         $this->_logAdapterFactory->create(array('fileName' => $file))->log($this->_debugData);
     }
 }
Exemple #10
0
 /**
  * @param string $localeCode
  * @param float|null $orderTotal
  * @param string|null $pal
  * @param string|null $staticSize
  * @param string $areButtonDynamic
  * @param bool $sandboxFlag
  * @param string $result
  * @dataProvider dataProviderGetPaymentMarkImageUrl
  */
 public function testGetPaymentMarkImageUrl($localeCode, $orderTotal, $pal, $staticSize, $areButtonDynamic, $sandboxFlag, $result)
 {
     $this->_model->setMethod(Config::METHOD_WPP_EXPRESS);
     $this->_model->setStoreId(123);
     $this->_scopeConfig->expects($this->any())->method('getValue')->willReturnMap([['paypal/wpp/button_flavor', ScopeInterface::SCOPE_STORE, 123, $areButtonDynamic], ['paypal/wpp/sandbox_flag', ScopeInterface::SCOPE_STORE, 123, $sandboxFlag]]);
     $this->assertEquals($result, $this->_model->getPaymentMarkImageUrl($localeCode, $orderTotal, $pal, $staticSize));
 }
Exemple #11
0
 /**
  * Aggregated cart summary label getter
  *
  * @return string
  */
 private function _getAggregatedCartSummary()
 {
     if ($this->_config->getConfigValue('lineItemsSummary')) {
         return $this->_config->getConfigValue('lineItemsSummary');
     }
     return $this->_storeManager->getStore($this->getStore())->getFrontendName();
 }
Exemple #12
0
 /**
  * @dataProvider dataProviderGetBmlDisplay
  */
 public function testGetBmlDisplay($section, $expectedValue, $expectedFlag, $expected)
 {
     $this->_model->setStoreId(1);
     $this->_coreData->expects($this->any())->method('getDefaultCountry')->with(1)->will($this->returnValue('US'));
     $this->_scopeConfig->expects($this->any())->method('isSetFlag')->will($this->returnValue($expectedFlag));
     $this->_scopeConfig->expects($this->any())->method('getValue')->will($this->returnValueMap([['payment/' . Config::METHOD_WPP_BML . '/' . $section . '_display', 'store', 1, $expectedValue], ['payment/' . Config::METHOD_WPP_BML . '/active', 'store', 1, $expectedValue], ['payment/' . Config::METHOD_WPP_PE_BML . '/active', 'store', 1, $expectedValue]]));
     $this->assertEquals($expected, $this->_model->getBmlDisplay($section));
 }
Exemple #13
0
 /**
  * Config instance setter
  *
  * @param \Magento\Paypal\Model\Config $instace
  * @param int|null $storeId
  * @return $this
  */
 public function setConfig(\Magento\Paypal\Model\Config $instance, $storeId = null)
 {
     $this->_config = $instance;
     if (null !== $storeId) {
         $this->_config->setStoreId($storeId);
     }
     return $this;
 }
Exemple #14
0
 protected function setUp()
 {
     $this->_paypalData = $this->getMock('Magento\\Paypal\\Helper\\Data', [], [], '', false);
     $this->_paypalConfig = $this->getMock('Magento\\Paypal\\Model\\Config', [], [], '', false);
     $this->_paypalConfig->expects($this->once())->method('setMethod')->will($this->returnSelf());
     $paypalConfigFactory = $this->getMock('Magento\\Paypal\\Model\\ConfigFactory', ['create'], [], '', false);
     $paypalConfigFactory->expects($this->once())->method('create')->will($this->returnValue($this->_paypalConfig));
     $mark = $this->getMock('Magento\\Framework\\View\\Element\\Template', array(), array(), '', false);
     $mark->expects($this->once())->method('setTemplate')->will($this->returnSelf());
     $mark->expects($this->any())->method('__call')->will($this->returnSelf());
     $layout = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface');
     $layout->expects($this->once())->method('createBlock')->with('Magento\\Framework\\View\\Element\\Template')->will($this->returnValue($mark));
     $this->currentCustomer = $this->getMockBuilder('\\Magento\\Customer\\Helper\\Session\\CurrentCustomer')->disableOriginalConstructor()->getMock();
     $localeResolver = $this->getMock('Magento\\Framework\\Locale\\ResolverInterface', array(), array(), '', false, false);
     $helper = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->_model = $helper->getObject('Magento\\Paypal\\Block\\Express\\Form', array('paypalData' => $this->_paypalData, 'paypalConfigFactory' => $paypalConfigFactory, 'currentCustomer' => $this->currentCustomer, 'layout' => $layout, 'localeResolver' => $localeResolver));
 }
Exemple #15
0
 /**
  * @return bool
  */
 protected function shouldRender()
 {
     $this->config->setMethod(Config::METHOD_EXPRESS);
     $isInCatalog = $this->getIsInCatalogProduct();
     $isInContext = (bool) (int) $this->config->getValue('in_context');
     $isEnabled = $isInContext && $isInCatalog || !$isInContext;
     $this->config->setMethod($this->_paymentMethodCode);
     return $isEnabled && $this->_shouldRender;
 }
 /**
  * Add PayPal shortcut buttons
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     /** @var \Magento\Catalog\Block\ShortcutButtons $shortcutButtons */
     $shortcutButtons = $observer->getEvent()->getContainer();
     $blocks = ['Magento\\Paypal\\Block\\Express\\Shortcut' => PaypalConfig::METHOD_WPP_EXPRESS, 'Magento\\Paypal\\Block\\WpsExpress\\Shortcut' => PaypalConfig::METHOD_WPS_EXPRESS, 'Magento\\Paypal\\Block\\PayflowExpress\\Shortcut' => PaypalConfig::METHOD_WPP_PE_EXPRESS, 'Magento\\Paypal\\Block\\Bml\\Shortcut' => PaypalConfig::METHOD_WPP_EXPRESS, 'Magento\\Paypal\\Block\\WpsBml\\Shortcut' => PaypalConfig::METHOD_WPS_EXPRESS, 'Magento\\Paypal\\Block\\Payflow\\Bml\\Shortcut' => PaypalConfig::METHOD_WPP_PE_EXPRESS];
     foreach ($blocks as $blockInstanceName => $paymentMethodCode) {
         if (!$this->paypalConfig->isMethodAvailable($paymentMethodCode)) {
             continue;
         }
         $params = ['shortcutValidator' => $this->shortcutFactory->create($observer->getEvent()->getCheckoutSession())];
         if (!in_array('Bml', explode('\\', $blockInstanceName))) {
             $params['checkoutSession'] = $observer->getEvent()->getCheckoutSession();
         }
         // we believe it's \Magento\Framework\View\Element\Template
         $shortcut = $shortcutButtons->getLayout()->createBlock($blockInstanceName, '', $params);
         $shortcut->setIsInCatalogProduct($observer->getEvent()->getIsCatalogProduct())->setShowOrPosition($observer->getEvent()->getOrPosition());
         $shortcutButtons->addShortcut($shortcut);
     }
 }
Exemple #17
0
 /**
  * Set shipping options to api
  * @param \Magento\Paypal\Model\Cart $cart
  * @param \Magento\Quote\Model\Quote\Address|null $address
  * @return void
  */
 private function setShippingOptions(PaypalCart $cart, Address $address = null)
 {
     // for included tax always disable line items (related to paypal amount rounding problem)
     $this->_api->setIsLineItemsEnabled($this->_config->getValue(PaypalConfig::TRANSFER_CART_LINE_ITEMS));
     // add shipping options if needed and line items are available
     $cartItems = $cart->getAllItems();
     if ($this->_config->getValue(PaypalConfig::TRANSFER_CART_LINE_ITEMS) && $this->_config->getValue(PaypalConfig::TRANSFER_SHIPPING_OPTIONS) && !empty($cartItems)) {
         if (!$this->_quote->getIsVirtual()) {
             $options = $this->_prepareShippingOptions($address, true);
             if ($options) {
                 $this->_api->setShippingOptionsCallbackUrl($this->_coreUrl->getUrl('*/*/shippingOptionsCallback', ['quote_id' => $this->_quote->getId()]))->setShippingOptions($options);
             }
         }
     }
 }
Exemple #18
0
 /**
  * Set create billing agreement flag to api call
  *
  * @return $this
  */
 protected function _setBillingAgreementRequest()
 {
     if (!$this->_customerId || $this->_quote->hasNominalItems()) {
         return $this;
     }
     $isRequested = $this->_isBARequested || $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT);
     if (!($this->_config->getConfigValue('allow_ba_signup') == PaypalConfig::EC_BA_SIGNUP_AUTO || $isRequested && $this->_config->shouldAskToCreateBillingAgreement())) {
         return $this;
     }
     if (!$this->_agreementFactory->create()->needToCreateForCustomer($this->_customerId)) {
         return $this;
     }
     $this->_api->setBillingType($this->_api->getBillingAgreementType());
     return $this;
 }
Exemple #19
0
 /**
  * Disable block output if banner turned off or PublisherId is miss
  *
  * @return string
  */
 protected function _toHtml()
 {
     if (!$this->_paypalConfig->isMethodAvailable(Config::METHOD_WPP_BML) && !$this->_paypalConfig->isMethodAvailable(Config::METHOD_WPP_PE_BML)) {
         return '';
     }
     $publisherId = $this->_paypalConfig->getBmlPublisherId();
     $display = $this->_paypalConfig->getBmlDisplay($this->_section);
     $position = $this->_paypalConfig->getBmlPosition($this->_section);
     if (!$publisherId || $display == 0 || $this->_position != $position) {
         return '';
     }
     $this->setData('publisher_id', $publisherId);
     $this->setData('size', $this->_paypalConfig->getBmlSize($this->_section));
     return parent::_toHtml();
 }
 /**
  * @return string
  */
 public function getMerchantId()
 {
     return $this->config->getValue('merchant_id');
 }
 /**
  * Check whether method active in configuration and supported for merchant country or not
  *
  * @param string $method Method code
  * @return bool
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function isMethodActive($method)
 {
     return parent::isMethodActive(Config::METHOD_PAYMENT_PRO) || parent::isMethodActive(Config::METHOD_PAYFLOWPRO);
 }
Exemple #22
0
 /**
  * Check whether API certificate authentication should be used
  *
  * @return bool
  * @SuppressWarnings(PHPMD.BooleanGetMethodName)
  */
 public function getUseCertAuthentication()
 {
     return (bool) $this->_config->getValue('apiAuthentication');
 }
 /**
  * @return string
  */
 public function getImageUrl()
 {
     return $this->config->getExpressCheckoutInContextImageUrl($this->localeResolver->getLocale());
 }
Exemple #24
0
 /**
  * 2015-07-15
  * Цель перекрытия —
  * добавление России в список «Merchant Country»:
  * https://github.com/magento/magento2/issues/1489
  * «PayPal currency list need to be updated»:
  * https://github.com/magento/magento2/issues/2157
  * @override
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Directory\Helper\Data $directoryHelper
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Payment\Model\Source\CctypeFactory $cctypeFactory
  * @param \Magento\Paypal\Model\CertFactory $certFactory
  * @param array $params
  */
 public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Directory\Helper\Data $directoryHelper, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Payment\Model\Source\CctypeFactory $cctypeFactory, \Magento\Paypal\Model\CertFactory $certFactory, $params = [])
 {
     $this->_supportedCurrencyCodes[] = 'RUB';
     $this->_supportedCountryCodes[] = 'RU';
     parent::__construct($scopeConfig, $directoryHelper, $storeManager, $cctypeFactory, $certFactory, $params);
 }
 /**
  * Log debug data to file
  *
  * @return void
  */
 protected function _debug()
 {
     if ($this->_config && $this->_config->getValue('debug')) {
         $this->logger->debug(var_export($this->_debugData, true));
     }
 }
Exemple #26
0
 /**
  * Don't show CC type for non-CC methods
  *
  * @return string|null
  */
 public function getCcTypeName()
 {
     if (\Magento\Paypal\Model\Config::getIsCreditCardMethod($this->getInfo()->getMethod())) {
         return parent::getCcTypeName();
     }
 }
 /**
  * Return billing agreement code for method
  *
  * @param string $code
  * @return null|string
  */
 protected function getBillingAgreementCode($code)
 {
     $customerId = $this->currentCustomer->getCustomerId();
     $this->config->setMethod($code);
     return $this->paypalHelper->shouldAskToCreateBillingAgreement($this->config, $customerId) ? Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT : null;
 }