/** * Processes the sale payment * * @param array $data IPN data * @return boolean Did the IPN Validate? * @access protected */ function _processSale($data, $ipnValidationFailed = '') { $send_email = false; /* * 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'); } // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($data['custom']); $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 Tienda::load('TiendaHelperBase', 'helpers._base'); $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => '')); $respond_amount = TiendaHelperBase::number($data['mc_gross'], array('thousands' => '')); if ($stored_amount != $respond_amount) { $errors[] = JText::_('PAGSEGURO MESSAGE PAYMENT 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 JLoader::import('com_tienda.helpers.order', JPATH_ADMINISTRATOR . '/components'); JLoader::import('com_tienda.helpers.carts', JPATH_ADMINISTRATOR . '/components'); $order = JTable::getInstance('Orders', 'TiendaTable'); $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 = Tienda::getInstance('pending_order_state', '1'); // PENDING // Update quantities for echeck payments TiendaHelperOrder::updateProductQuantities($orderpayment->order_id, '-'); // remove items from cart TiendaHelperCarts::removeOrderItems($orderpayment->order_id); } 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 Tienda::load("TiendaHelperBase", 'helpers._base'); $helper = TiendaHelperBase::getInstance('Email'); $model = Tienda::getClass("TiendaModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } return count($errors) ? implode("\n", $errors) : ''; }
/** * Processes the payment form * and returns HTML to be displayed to the user * generally with a success/failed message * * @param $data array form post data * @return string HTML to display */ function _postPayment($data) { // Process the payment $vars = new JObject(); $orderpayment_id = !empty($data['orderpayment_id']) ? $data['orderpayment_id'] : JRequest::getVar('orderpayment_id'); $cardtype = !empty($data['cardtype']) ? $data['cardtype'] : JRequest::getVar('cardtype'); $cardnum = !empty($data['cardnum']) ? $data['cardnum'] : JRequest::getVar('cardnum'); $cardexp = !empty($data['cardexp']) ? $data['cardexp'] : JRequest::getVar('cardexp'); $cardcvv = !empty($data['cardcvv']) ? $data['cardcvv'] : JRequest::getVar('cardcvv'); $formatted = array('cardtype' => $cardtype, 'cardnum' => $cardnum, 'cardexp' => $cardexp, 'cardcvv' => $cardcvv); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($orderpayment_id); $orderpayment->transaction_details = implode("\n", $formatted); if ($orderpayment->save()) { // Don't remove order quantities until payment is actually received? if ($this->params->get('remove_quantities')) { Tienda::load('TiendaHelperOrder', 'helpers.order'); TiendaHelperOrder::updateProductQuantities($orderpayment->order_id, '-'); } // remove items from cart Tienda::load('TiendaHelperCarts', 'helpers.carts'); TiendaHelperCarts::removeOrderItems($orderpayment->order_id); // send notice of new order Tienda::load("TiendaHelperBase", 'helpers._base'); $helper = TiendaHelperBase::getInstance('Email'); $model = Tienda::getClass("TiendaModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } // display the layout $html = $this->_getLayout('postpayment', $vars); // append the article with offline payment information $html .= $this->_displayArticle(); return $html; }
/** * this is updating the transaction id with the Google Order id * */ function _saveTransaction($data, $error = '') { $errors = array(); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $oredrPaymentId = $data['shopping-cart']['merchant-private-data']['orderPaymentId']['VALUE']; $orderpayment->load($oredrPaymentId); if (empty($orderpayment->orderpayment_id)) { $errors[] = JText::_('COM_TIENDA_GOOGLECHECKOUT_CHECKOUT_INVALID_ORDERPAYMENTID'); return count($errors) ? implode("\n", $errors) : ''; } $orderpayment->transaction_id = $data['google-order-number']['VALUE']; // update the orderpayment if (!$orderpayment->save()) { $errors[] = $orderpayment->getError(); } // set the order's new status and update quantities if necessary Tienda::load('TiendaHelperOrder', 'helpers.order'); Tienda::load('TiendaHelperCarts', 'helpers.carts'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($orderpayment->order_id); // if the transaction has the "pending" status, $order->order_state_id = Tienda::getInstance('pending_order_state', '1'); // PENDING // Update quantities for echeck payments TiendaHelperOrder::updateProductQuantities($orderpayment->order_id, '-'); // remove items from cart TiendaHelperCarts::removeOrderItems($orderpayment->order_id); // send email $send_email = true; if ($send_email) { // send notice of new order Tienda::load("TiendaHelperBase", 'helpers._base'); $helper = TiendaHelperBase::getInstance('Email'); $model = Tienda::getClass("TiendaModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } return count($errors) ? implode("\n", $errors) : ''; }
/** * 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_tienda/tables'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($order_id); if (empty($order->order_id)) { // TODO we must make sure this class is always instantiated $this->setError(JText::_('COM_TIENDA_INVALID_ORDER_ID')); return false; } // Fire an doCompletedOrderTasks event $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('doCompletedOrderTasks', array($order_id)); // 0. Enable One-Time Purchase Subscriptions TiendaHelperOrder::enableNonRecurringSubscriptions($order_id); // 1. Update quantities TiendaHelperOrder::updateProductQuantities($order_id, '-'); // 2. remove items from cart Tienda::load('TiendaHelperCarts', 'helpers.carts'); TiendaHelperCarts::removeOrderItems($order_id); // 3. add productfiles to product downloads TiendaHelperOrder::enableProductDownloads($order_id); // 4. do SQL queries $helper = TiendaHelperBase::getInstance('Sql'); $helper->processOrder($order_id); // register commission if amigos is installed $helper = TiendaHelperBase::getInstance('Amigos'); $helper->createCommission($order_id); // change ticket limits if billets is installed $helper = TiendaHelperBase::getInstance('Billets'); $helper->processOrder($order_id); // add to JUGA Groups if JUGA installed $helper = TiendaHelperBase::getInstance('Juga'); $helper->processOrder($order_id); // change core ACL if set $helper = TiendaHelperBase::getInstance('User'); $helper->processOrder($order_id); // do Ambra Subscriptions Integration processes $helper = TiendaHelperBase::getInstance('Ambrasubs'); $helper->processOrder($order_id); // increase the hit counts for coupons in the order $helper = TiendaHelperBase::getInstance('Coupon'); $helper->processOrder($order_id); if ($error) { $this->setError(implode('<br/>', $errors)); return false; } else { $order->completed_tasks = '1'; $order->store(); return true; } }
/** * 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) { Tienda::load('TiendaHelperCarts', 'helpers.carts'); TiendaHelperCarts::removeOrderItems($order_id); }
function _process($data) { $errors = array(); // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($data['reference']); $orderpayment->transaction_details = $data['key']; $orderpayment->transaction_id = $data['txn_id']; // set the order's new status and update quantities if necessary Tienda::load('TiendaHelperOrder', 'helpers.order'); Tienda::load('TiendaHelperCarts', 'helpers.carts'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($orderpayment->order_id); if ($data['txn_status'] == '2') { $order->order_state_id = $this->params->get('payment_received_order_state', '17'); // PAYMENT RECEIVED // do post payment actions $setOrderPaymentReceived = true; } else { $orderpayment->transaction_status = 'Failed'; $order->order_state_id = $this->params->get('failed_order_state', '10'); // FAILED } // 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); } $html = ""; if ($data['txn_status'] == '2') { // clear the shopping cart Tienda::load('TiendaHelperCarts', 'helpers.carts'); TiendaHelperCarts::removeOrderItems($orderpayment->order_id); $html = "<dl id='system-message'><dt class='message'>message</dt><dd class='message fade'><ul><li>Your order has been completed successfully. Your transaction no. is <strong>" . $data['txn_id'] . "</strong> and your receipt no. is <strong>" . $data['receipt_no'] . "</strong> <br />( <a href='index.php?option=com_tienda&view=orders&task=view&id=" . $orderpayment->order_id . "'>view invoice</a> )</li></ul></dd></dl>"; } else { $html = "<div style='padding-top: 10px;' id='validationmessage'><dl id='system-message'><dt class='notice'>notice</dt><dd class='notice message fade'><ul><li>Unable to complete order because : <i>" . $data['response_text'] . "</i></li></ul></dd></dl></div><style type='text/css'>.postpayment_article{display:none!important;visibility:hidden!important;}</style>"; } return $html; }