Exemplo n.º 1
0
 /**
  * Register recurring payment notification, create and process order
  */
 protected function _registerRecurringProfilePaymentCapture()
 {
     $price = $this->getRequestData('mc_gross') - $this->getRequestData('tax') - $this->getRequestData('shipping');
     $productItemInfo = new Varien_Object();
     $type = trim($this->getRequestData('period_type'));
     if ($type == 'Trial') {
         $productItemInfo->setPaymentType(Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL);
     } elseif ($type == 'Regular') {
         $productItemInfo->setPaymentType(Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_REGULAR);
     }
     $productItemInfo->setTaxAmount($this->getRequestData('tax'));
     $productItemInfo->setShippingAmount($this->getRequestData('shipping'));
     $productItemInfo->setPrice($price);
     /** @var $order Mage_Sales_Model_Order */
     $order = $this->_recurringProfile->createOrder($productItemInfo);
     $payment = $order->getPayment();
     $payment->setTransactionId($this->getRequestData('txn_id'))->setCurrencyCode($this->getRequestData('mc_currency'))->setPreparedMessage($this->_createIpnComment(''))->setIsTransactionClosed(0);
     $order->save();
     $this->_recurringProfile->addOrderRelation($order->getId());
     $payment->registerCaptureNotification($this->getRequestData('mc_gross'));
     $order->save();
     $invoice = $payment->getCreatedInvoice();
     if ($invoice) {
         // notify customer
         $message = Mage::helper('paypal')->__('Notified customer about invoice #%s.', $invoice->getIncrementId());
         $order->queueNewOrderEmail()->addStatusHistoryComment($message)->setIsCustomerNotified(true)->save();
     }
 }
Exemplo n.º 2
0
 /**
  * Register recurring payment notification, create and process order
  */
 protected function _registerRecurringProfilePaymentCapture()
 {
     $price = $this->_price;
     $tax = $this->_taxAmount;
     $shipping = $this->_shippingAmount;
     $grandTotal = $this->_amount;
     $periodType = $this->_periodType;
     $transactionId = $this->_txdId;
     $ewayMessage = '';
     $productItemInfo = new Varien_Object();
     /** @todo: response doesn't contain period type / payment type */
     $productItemInfo->setPaymentType($periodType);
     $productItemInfo->setTaxAmount($tax);
     $productItemInfo->setShippingAmount($shipping);
     $productItemInfo->setPrice($price);
     /** @var Mage_Sales_Model_Recurring_Profile $recurringProfile */
     $recurringProfile = $this->_recurringProfile;
     $order = $recurringProfile->createOrder($productItemInfo);
     $payment = $order->getPayment();
     $payment->setTransactionId($transactionId)->setPreparedMessage($ewayMessage)->setIsTransactionClosed(0);
     $order->save();
     $this->_recurringProfile->addOrderRelation($order->getId());
     $payment->registerCaptureNotification($grandTotal);
     $order->save();
     // notify customer
     if ($invoice = $payment->getCreatedInvoice()) {
         $message = Mage::helper('paypal')->__('Notified customer about invoice #%s.', $invoice->getIncrementId());
         $comment = $order->sendNewOrderEmail()->addStatusHistoryComment($message)->setIsCustomerNotified(true)->save();
     }
     if (!$recurringProfile->getIsCronJob()) {
         $session = Mage::getSingleton('checkout/type_onepage')->getCheckout();
         $session->setLastOrderId($order->getId());
     }
 }