public function testPrepareLayoutInfoEmpty() { $this->_payment->expects($this->once())->method('getInfoValue')->will($this->returnValue('1')); $this->_block->setAddressType('shipping'); $parentBlock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\Template')->disableOriginalConstructor()->setMethods(array('unsetChild'))->getMock(); $parentBlock->expects($this->once())->method('unsetChild'); $layout = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods(array('getParentName', 'getBlock'))->getMock(); $layout->expects($this->once())->method('getParentName')->will($this->returnValue('name')); $layout->expects($this->once())->method('getBlock')->will($this->returnValue($parentBlock)); $this->_block->setLayout($layout); $this->assertEmpty($this->_block->getRenderedInfo()); }
public function testPrepareLayout() { $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->_payment = $this->getMockBuilder('Magento\\RecurringPayment\\Model\\Payment')->disableOriginalConstructor()->setMethods(array('setStore', 'getFieldLabel', '__wakeup'))->getMock(); $this->_payment->expects($this->once())->method('setStore')->will($this->returnValue($this->_payment)); $registry = $this->getMockBuilder('Magento\\Framework\\Registry')->disableOriginalConstructor()->setMethods(array('registry'))->getMock(); $registry->expects($this->once())->method('registry')->with('current_recurring_payment')->will($this->returnValue($this->_payment)); $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $storeManager = $this->getMockBuilder('Magento\\Store\\Model\\StoreManager')->disableOriginalConstructor()->setMethods(array('getStore'))->getMock(); $storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store)); $this->_block = $objectManager->getObject('Magento\\RecurringPayment\\Block\\Payment\\View\\Item', array('registry' => $registry, 'storeManager' => $storeManager)); $layout = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods(array('helper'))->getMock(); $this->_block->setLayout($layout); }
public function testAddRecurringPaymentIdsToSession() { $this->_prepareRecurringPayments(); $this->_quote->expects($this->once())->method('import')->will($this->returnValue(array($this->_payment))); $this->_payment->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->_payment->expects($this->once())->method('submit'); $this->_testModel->submitRecurringPayments($this->_observer); $this->_testModel->addRecurringPaymentIdsToSession(); }
/** * Render self only if needed, also render info tabs group if needed * * @return string */ protected function _toHtml() { if (!$this->_recurringPayment || $this->_shouldRenderInfo && !$this->_info) { return ''; } if ($this->hasShouldPrepareInfoTabs()) { $layout = $this->getLayout(); foreach ($this->getGroupChildNames('info_tabs') as $name) { $block = $layout->getBlock($name); if (!$block) { continue; } $block->setViewUrl($this->getUrl("*/*/{$block->getViewAction()}", array('payment' => $this->_recurringPayment->getId()))); } } return parent::_toHtml(); }
/** * Process notification from recurring payments * * @return void * @throws \Magento\Framework\Model\Exception * @throws Exception */ protected function _processRecurringPayment() { $this->_getConfig(); try { // handle payment_status $paymentStatus = $this->_filterPaymentStatus($this->getRequestData('payment_status')); if ($paymentStatus != \Magento\Paypal\Model\Info::PAYMENTSTATUS_COMPLETED) { throw new Exception("Cannot handle payment status '{$paymentStatus}'."); } // Register recurring payment notification, create and process order $price = $this->getRequestData('mc_gross') - $this->getRequestData('tax') - $this->getRequestData('shipping'); $productItemInfo = new \Magento\Framework\Object(); $type = trim($this->getRequestData('period_type')); if ($type == 'Trial') { $productItemInfo->setPaymentType(\Magento\RecurringPayment\Model\PaymentTypeInterface::TRIAL); } elseif ($type == 'Regular') { $productItemInfo->setPaymentType(\Magento\RecurringPayment\Model\PaymentTypeInterface::REGULAR); } $productItemInfo->setTaxAmount($this->getRequestData('tax')); $productItemInfo->setShippingAmount($this->getRequestData('shipping')); $productItemInfo->setPrice($price); $order = $this->_recurringPayment->createOrder($productItemInfo); $payment = $order->getPayment()->setTransactionId($this->getRequestData('txn_id'))->setCurrencyCode($this->getRequestData('mc_currency'))->setPreparedMessage($this->_createIpnComment(''))->setIsTransactionClosed(0); $order->save(); $this->_recurringPayment->addOrderRelation($order->getId()); $payment->registerCaptureNotification($this->getRequestData('mc_gross')); $order->save(); // notify customer $invoice = $payment->getCreatedInvoice(); if ($invoice) { $message = __('You notified customer about invoice #%1.', $invoice->getIncrementId()); $this->orderSender->send($order); $order->addStatusHistoryComment($message)->setIsCustomerNotified(true)->save(); } } catch (\Magento\Framework\Model\Exception $e) { $comment = $this->_createIpnComment(__('Note: %1', $e->getMessage()), true); //TODO: add to payment comments //$comment->save(); throw $e; } }
/** * Instantiate payments collection * * @param array|int|string $fields * @return void */ protected function _preparePayments($fields = '*') { $this->_payments = $this->_recurringPayment->getCollection()->addFieldToFilter('customer_id', $this->_registry->registry(RegistryConstants::CURRENT_CUSTOMER_ID))->addFieldToSelect($fields)->setOrder('payment_id', 'desc'); }