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();
     }
 }