Exemple #1
0
 /**
  * This method for after an orderpayment has been received when the admin click on the
  * that performs acts such as:
  * enabling file downloads
  *
  * @param $order_id
  * @return unknown_type
  */
 public static function doCompletedOrderTasks($order_id)
 {
     $errors = array();
     $error = false;
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     $order = JTable::getInstance('Orders', 'CitruscartTable');
     $order->load($order_id);
     if (empty($order->order_id)) {
         // TODO we must make sure this class is always instantiated
         $this->setError(JText::_('COM_CITRUSCART_INVALID_ORDER_ID'));
         return false;
     }
     // Fire an doCompletedOrderTasks event
     JFactory::getApplication()->triggerEvent('doCompletedOrderTasks', array($order_id));
     // 0. Enable One-Time Purchase Subscriptions
     CitruscartHelperOrder::enableNonRecurringSubscriptions($order_id);
     // 1. Update quantities
     CitruscartHelperOrder::updateProductQuantities($order_id, '-');
     // 2. remove items from cart
     Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
     CitruscartHelperCarts::removeOrderItems($order_id);
     // 3. add productfiles to product downloads
     CitruscartHelperOrder::enableProductDownloads($order_id);
     // 4. do SQL queries
     $helper = CitruscartHelperBase::getInstance('Sql');
     $helper->processOrder($order_id);
     // register commission if amigos is installed
     $helper = CitruscartHelperBase::getInstance('Amigos');
     $helper->createCommission($order_id);
     // change ticket limits if billets is installed
     $helper = CitruscartHelperBase::getInstance('Billets');
     $helper->processOrder($order_id);
     // add to JUGA Groups if JUGA installed
     $helper = CitruscartHelperBase::getInstance('Juga');
     $helper->processOrder($order_id);
     // change core ACL if set
     $helper = CitruscartHelperBase::getInstance('User');
     $helper->processOrder($order_id);
     // do Ambra Subscriptions Integration processes
     $helper = CitruscartHelperBase::getInstance('Ambrasubs');
     $helper->processOrder($order_id);
     // increase the hit counts for coupons in the order
     $helper = CitruscartHelperBase::getInstance('Coupon');
     $helper->processOrder($order_id);
     if ($error) {
         $this->setError(implode('<br/>', $errors));
         return false;
     } else {
         $order->completed_tasks = '1';
         $order->store();
         return true;
     }
 }
 /**
  * Processes the sale payment
  *
  * @param  array   $data IPN data
  * @return boolean Did the IPN Validate?
  * @access protected
  */
 public function _processSale($data, $ipnValidationFailed = '')
 {
     /*
      * validate the payment data
      */
     $errors = array();
     if (!empty($ipnValidationFailed)) {
         $errors[] = $ipnValidationFailed;
     }
     // is the recipient correct?
     if (empty($data['receiver_email']) || $data['receiver_email'] != $this->_getParam('merchant_email')) {
         $errors[] = JText::_('PAYPAL MESSAGE RECEIVER INVALID');
     }
     if (empty($data['custom'])) {
         $errors[] = JText::_('PAYPAL MESSAGE INVALID ORDERPAYMENTID');
         return count($errors) ? implode("\n", $errors) : '';
     }
     // load the orderpayment record and set some values
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     $orderpayment = JTable::getInstance('OrderPayments', 'CitruscartTable');
     $orderpayment->load($data['custom']);
     if (empty($data['custom']) || empty($orderpayment->orderpayment_id)) {
         $errors[] = JText::_('PAYPAL MESSAGE INVALID ORDERPAYMENTID');
         return count($errors) ? implode("\n", $errors) : '';
     }
     $orderpayment->transaction_details = $data['transaction_details'];
     $orderpayment->transaction_id = $data['txn_id'];
     $orderpayment->transaction_status = $data['payment_status'];
     // check the stored amount against the payment amount
     Citruscart::load('CitruscartHelperBase', 'helpers._base');
     $stored_amount = CitruscartHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => ''));
     $respond_amount = CitruscartHelperBase::number($data['mc_gross'], array('thousands' => ''));
     if ($stored_amount != $respond_amount) {
         $errors[] = JText::_('PAYPAL MESSAGE AMOUNT INVALID');
         $errors[] = $stored_amount . " != " . $respond_amount;
     }
     // check the payment status
     if (empty($data['payment_status']) || $data['payment_status'] != 'Completed' && $data['payment_status'] != 'Pending') {
         $errors[] = JText::sprintf('PAYPAL MESSAGE STATUS INVALID', $data['payment_status']);
     }
     // set the order's new status and update quantities if necessary
     Citruscart::load('CitruscartHelperOrder', 'helpers.order');
     Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
     $order = JTable::getInstance('Orders', 'CitruscartTable');
     $order->load($orderpayment->order_id);
     if (count($errors)) {
         // if an error occurred
         $order->order_state_id = $this->params->get('failed_order_state', '10');
         // FAILED
     } elseif ($data['payment_status'] == 'Pending') {
         // if the transaction has the "pending" status,
         $order->order_state_id = Citruscart::getInstance('pending_order_state', '1');
         // PENDING
         // Update quantities for echeck payments
         CitruscartHelperOrder::updateProductQuantities($orderpayment->order_id, '-');
         // remove items from cart
         CitruscartHelperCarts::removeOrderItems($orderpayment->order_id);
         // send email
         $send_email = true;
     } else {
         $order->order_state_id = $this->params->get('payment_received_order_state', '17');
         // PAYMENT RECEIVED
         // do post payment actions
         $setOrderPaymentReceived = true;
         // send email
         $send_email = true;
     }
     // save the order
     if (!$order->save()) {
         $errors[] = $order->getError();
     }
     // save the orderpayment
     if (!$orderpayment->save()) {
         $errors[] = $orderpayment->getError();
     }
     if (!empty($setOrderPaymentReceived)) {
         $this->setOrderPaymentReceived($orderpayment->order_id);
     }
     if ($send_email) {
         // send notice of new order
         Citruscart::load("CitruscartHelperBase", 'helpers._base');
         $helper = CitruscartHelperBase::getInstance('Email');
         $model = Citruscart::getClass("CitruscartModelOrders", "models.orders");
         $model->setId($orderpayment->order_id);
         $order = $model->getItem();
         $helper->sendEmailNotices($order, 'new_order');
     }
     return count($errors) ? implode("\n", $errors) : '';
 }
Exemple #3
0
 /**
  * Given an order_id, will remove the order's items from the user's cart
  *
  * @param unknown_type $order_id
  * @return unknown_type
  */
 function removeOrderItemsFromCart($order_id)
 {
     Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
     CitruscartHelperCarts::removeOrderItems($order_id);
 }