Exemplo n.º 1
0
 /**
  * Prepare recurring payments
  *
  * @param \Magento\Sales\Model\Quote $quote
  * @throws \Exception
  * @return array
  */
 public function import(\Magento\Sales\Model\Quote $quote)
 {
     if (!$quote->getTotalsCollectedFlag()) {
         throw new \Exception('Quote totals must be collected before this operation.');
     }
     $result = array();
     foreach ($quote->getAllVisibleItems() as $item) {
         $product = $item->getProduct();
         if (is_object($product) && $product->getIsRecurring() && ($payment = $this->_paymentFactory->create()->importProduct($product))) {
             $payment->importQuote($quote);
             $payment->importQuoteItem($item);
             $result[] = $payment;
         }
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Load recurring payment
  *
  * @return \Magento\RecurringPayment\Model\Payment
  * @throws Exception
  */
 protected function _getRecurringPayment()
 {
     $referenceId = $this->getRequestData('rp_invoice_id');
     $this->_recurringPayment = $this->_recurringPaymentFactory->create()->loadByInternalReferenceId($referenceId);
     if (!$this->_recurringPayment->getId()) {
         throw new Exception(sprintf('Wrong recurring payment INTERNAL_REFERENCE_ID: "%s".', $referenceId));
     }
     return $this->_recurringPayment;
 }