Esempio n. 1
0
 /**
  * @param string $methodCode
  * @param string $htmlTransactionId
  * @dataProvider testGetHtmlTransactionIdProvider
  */
 public function testGetHtmlTransactionId($methodCode, $htmlTransactionId)
 {
     $txnId = 'XXX123123XXX';
     $htmlTransactionId = sprintf($htmlTransactionId, 'sandbox', $txnId);
     $this->configMock->expects($this->any())->method('getValue')->with($this->stringContains('sandboxFlag'))->willReturn(true);
     $this->assertEquals($htmlTransactionId, $this->_helper->getHtmlTransactionId($methodCode, $txnId));
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function getSectionData()
 {
     $customerId = $this->currentCustomer->getCustomerId();
     if ($this->paypalData->shouldAskToCreateBillingAgreement($this->config, $customerId)) {
         return ['askToCreate' => true, 'confirmUrl' => $this->escaper->escapeUrl($this->urlBuilder->getUrl($this->startAction, [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1])), 'confirmMessage' => $this->escaper->escapeJsQuote(__('Would you like to sign a billing agreement to streamline further purchases with PayPal?'))];
     }
     return [];
 }
 /**
  * Update transaction with HTML representation of txn_id
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     /** @var \Magento\Sales\Model\Order\Payment\Transaction $transaction */
     $transaction = $observer->getDataObject();
     $order = $transaction->getOrder();
     $payment = $order->getPayment();
     $methodInstance = $payment->getMethodInstance();
     $paymentCode = $methodInstance->getCode();
     $transactionLink = $this->paypalData->getHtmlTransactionId($paymentCode, $transaction->getTxnId());
     $transaction->setData('html_txn_id', $transactionLink);
 }
Esempio n. 4
0
 /**
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 protected function _beforeToHtml()
 {
     $result = parent::_beforeToHtml();
     /** @var \Magento\Paypal\Model\Config $config */
     $config = $this->_paypalConfigFactory->create();
     $config->setMethod($this->_paymentMethodCode);
     $isInCatalog = $this->getIsInCatalogProduct();
     if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) {
         $this->_shouldRender = false;
         return $result;
     }
     $quote = $isInCatalog || !$this->_checkoutSession ? null : $this->_checkoutSession->getQuote();
     // set misc data
     $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_'))->setCheckoutUrl($this->getUrl($this->_startAction));
     // use static image if in catalog
     if ($isInCatalog || null === $quote) {
         $this->setImageUrl($config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale()));
     } else {
         /**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */
         $parameters = ['params' => ['quote' => $quote, 'config' => $config]];
         $checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters);
         $this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl());
     }
     // ask whether to create a billing agreement
     $customerId = $this->currentCustomer->getCustomerId();
     // potential issue for caching
     if ($this->_paypalData->shouldAskToCreateBillingAgreement($config, $customerId)) {
         $this->setConfirmationUrl($this->getUrl($this->_startAction, [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1]));
         $this->setConfirmationMessage(__('Would you like to sign a billing agreement to streamline further purchases with PayPal?'));
     }
     return $result;
 }
 public function testObserveHtmlTransactionId()
 {
     $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->setMethods(['getDataObject'])->disableOriginalConstructor()->getMock();
     $transactionMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Payment\\Transaction')->setMethods(['getOrder', 'getTxnId', 'setData'])->disableOriginalConstructor()->getMock();
     $orderMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order')->setMethods(['getPayment'])->disableOriginalConstructor()->getMock();
     $paymentMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Payment')->setMethods(['getMethodInstance'])->disableOriginalConstructor()->getMock();
     $methodInstanceMock = $this->getMockBuilder('\\Magento\\Payment\\Model\\MethodInterface')->setMethods(['getCode'])->getMockForAbstractClass();
     $observerMock->expects($this->once())->method('getDataObject')->willReturn($transactionMock);
     $transactionMock->expects($this->once())->method('getOrder')->willReturn($orderMock);
     $orderMock->expects($this->once())->method('getPayment')->willReturn($paymentMock);
     $paymentMock->expects($this->once())->method('getMethodInstance')->willReturn($methodInstanceMock);
     $methodInstanceMock->expects($this->once())->method('getCode')->willReturn("'test'");
     $transactionMock->expects($this->once())->method('getTxnId')->willReturn("'test'");
     $this->paypalDataMock->expects($this->once())->method('getHtmlTransactionId')->willReturn('test');
     $transactionMock->expects($this->once())->method('setData')->with('html_txn_id', 'test');
     $this->_model->execute($observerMock);
 }
Esempio n. 6
0
 /**
  * Load available billing agreement methods
  *
  * @return array
  */
 protected function _loadPaymentMethods()
 {
     if (!$this->_paymentMethods) {
         foreach ($this->_helper->getBillingAgreementMethods() as $paymentMethod) {
             $this->_paymentMethods[$paymentMethod->getCode()] = $paymentMethod->getTitle();
         }
     }
     return $this->_paymentMethods;
 }
Esempio n. 7
0
 /**
  * Retrieve wizard payment options array
  *
  * @return array
  */
 public function getWizardPaymentMethodOptions()
 {
     $paymentMethodOptions = [];
     foreach ($this->_helper->getBillingAgreementMethods() as $paymentMethod) {
         if ($paymentMethod->getConfigData('allow_billing_agreement_wizard') == 1) {
             $paymentMethodOptions[$paymentMethod->getCode()] = $paymentMethod->getTitle();
         }
     }
     return $paymentMethodOptions;
 }
 public function testGetWizardPaymentMethodOptions()
 {
     $method1 = $this->getMock('Magento\\Paypal\\Model\\Method\\Agreement', ['getConfigData', 'getCode', 'getTitle'], [], '', false);
     $method2 = $this->getMock('Magento\\Paypal\\Model\\Method\\Agreement', ['getConfigData', 'getCode', 'getTitle'], [], '', false);
     $method3 = $this->getMock('Magento\\Paypal\\Model\\Method\\Agreement', ['getConfigData', 'getCode', 'getTitle'], [], '', false);
     $method1->expects($this->once())->method('getCode')->willReturn('code1');
     $method2->expects($this->never())->method('getCode');
     $method3->expects($this->once())->method('getCode')->willReturn('code3');
     $method1->expects($this->once())->method('getTitle')->willReturn('title1');
     $method2->expects($this->never())->method('getTitle');
     $method3->expects($this->once())->method('getTitle')->willReturn('title3');
     $method1->expects($this->any())->method('getConfigData')->willReturn(1);
     $method2->expects($this->any())->method('getConfigData')->willReturn(0);
     $method3->expects($this->any())->method('getConfigData')->willReturn(1);
     $paymentMethods = [$method1, $method2, $method3];
     $this->helper->expects($this->once())->method('getBillingAgreementMethods')->willReturn($paymentMethods);
     $this->assertEquals(['code1' => 'title1', 'code3' => 'title3'], $this->block->getWizardPaymentMethodOptions());
 }
Esempio n. 9
0
 /**
  * Get billing agreement code
  *
  * @return string|null
  */
 public function getBillingAgreementCode()
 {
     $customerId = $this->currentCustomer->getCustomerId();
     return $this->_paypalData->shouldAskToCreateBillingAgreement($this->_config, $customerId) ? \Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT : null;
 }
 /**
  * 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;
 }
Esempio n. 11
0
 /**
  * @param bool $ask
  * @param string|null $expected
  * @dataProvider getBillingAgreementCodeDataProvider
  */
 public function testGetBillingAgreementCode($ask, $expected)
 {
     $this->currentCustomer->expects($this->once())->method('getCustomerId')->will($this->returnValue('customer id'));
     $this->_paypalData->expects($this->once())->method('shouldAskToCreateBillingAgreement')->with($this->identicalTo($this->_paypalConfig), 'customer id')->will($this->returnValue($ask));
     $this->assertEquals($expected, $this->_model->getBillingAgreementCode());
 }
Esempio n. 12
0
 /**
  * @dataProvider canManageBillingAgreementsDataProvider
  * @param $expectedResult
  * @param $methodInstance
  */
 public function testCanManageBillingAgreements($expectedResult, $methodInstance)
 {
     $this->assertEquals($expectedResult, $this->_helper->canManageBillingAgreements($methodInstance));
 }