/** * 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 $app = JFactory::getApplication(); $vars = new JObject(); $html = ''; $orderpayment_id = $app->input->getInt('orderpayment_id'); // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2store/tables'); $orderpayment = JTable::getInstance('Orders', 'Table'); $orderpayment->load($orderpayment_id); if ($orderpayment->id == $orderpayment_id) { $payment_status = $this->getPaymentStatus($this->params->get('payment_status', 4)); $orderpayment->transaction_status = $payment_status; $orderpayment->order_state = $payment_status; $orderpayment->order_state_id = $this->params->get('payment_status', 4); // DEFAULT: PENDING // save the orderpayment if ($orderpayment->save()) { JLoader::register('K2StoreHelperCart', JPATH_SITE . '/components/com_k2store/helpers/cart.php'); // remove items from cart K2StoreHelperCart::removeOrderItems($orderpayment->id); } else { $errors[] = $orderpayment->getError(); } // let us inform the user that the order is successful require_once JPATH_SITE . '/components/com_k2store/helpers/orders.php'; K2StoreOrdersHelper::sendUserEmail($orderpayment->user_id, $orderpayment->order_id, $orderpayment->transaction_status, $orderpayment->order_state, $orderpayment->order_state_id); $vars->onafterpayment_text = $this->params->get('onafterpayment', ''); // display the layout $html = $this->_getLayout('postpayment', $vars); // append the article with cash payment information $html .= $this->_displayArticle(); } return $html; }
/** * This method occurs after payment is attempted, * and fires the onPostPayment plugin event * * @return unknown_type */ function confirmPayment() { $app = JFactory::getApplication(); $orderpayment_type = $app->input->getString('orderpayment_type'); // Get post values $values = $app->input->getArray($_POST); //backward compatibility for payment plugins foreach ($values as $name => $value) { $app->input->set($name, $value); } //set the guest mail to null if it is present //check if it was a guest checkout $account = $this->session->get('account', 'register', 'k2store'); // get the order_id from the session set by the prePayment $orderpayment_id = (int) $app->getUserState('k2store.orderpayment_id'); if ($account != 'guest') { $order_link = 'index.php?option=com_k2store&view=orders&task=view&id=' . $orderpayment_id; } else { $guest_token = $app->getUserState('k2store.order_token'); $order_link = 'index.php?option=com_k2store&view=orders&task=view'; //assign to another session variable, for security reasons if ($this->session->has('guest', 'k2store')) { $guest = $this->session->get('guest', array(), 'k2store'); $this->session->set('guest_order_email', $guest['billing']['email']); $this->session->set('guest_order_token', $guest_token); } } $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('k2store'); $html = ""; $order = $this->_order; $order->load(array('id' => $orderpayment_id)); // free product? set the state to confirmed and save the order. if (!empty($orderpayment_id) && (double) $order->order_total == (double) '0.00') { $order->order_state = trim(JText::_('CONFIRMED')); $order->order_state_id = '1'; // PAYMENT RECEIVED. if ($order->save()) { // remove items from cart K2StoreHelperCart::removeOrderItems($order->id); } //send email require_once JPATH_SITE . '/components/com_k2store/helpers/orders.php'; K2StoreOrdersHelper::sendUserEmail($order->user_id, $order->order_id, $order->transaction_status, $order->order_state, $order->order_state_id); } else { // get the payment results from the payment plugin $results = $dispatcher->trigger("onK2StorePostPayment", array($orderpayment_type, $values)); // Display whatever comes back from Payment Plugin for the onPrePayment for ($i = 0; $i < count($results); $i++) { $html .= $results[$i]; } // re-load the order in case the payment plugin updated it $order->load(array('id' => $orderpayment_id)); } // $order_id would be empty on posts back from Paypal, for example if (isset($orderpayment_id)) { //unset a few things from the session. $this->session->clear('shipping_method', 'k2store'); $this->session->clear('shipping_methods', 'k2store'); $this->session->clear('shipping_values', 'k2store'); $this->session->clear('payment_method', 'k2store'); $this->session->clear('payment_methods', 'k2store'); $this->session->clear('payment_values', 'k2store'); $this->session->clear('guest', 'k2store'); $this->session->clear('customer_note', 'k2store'); //save the coupon to the order_coupons table for tracking and unset session. if ($this->session->has('coupon', 'k2store')) { $coupon_info = K2StoreHelperCart::getCoupon($this->session->get('coupon', '', 'k2store')); if ($coupon_info) { $order_coupons = JTable::getInstance('OrderCoupons', 'Table'); $order_coupons->set('coupon_id', $coupon_info->coupon_id); $order_coupons->set('orderpayment_id', $orderpayment_id); $order_coupons->set('customer_id', JFactory::getUser()->id); $order_coupons->set('amount', $order->order_discount); $order_coupons->set('created_date', JFactory::getDate()->toSql()); $order_coupons->store(); } } //clear the session $this->session->clear('coupon', 'k2store'); //trigger onAfterOrder plugin event $results = $dispatcher->trigger("onK2StoreAfterPayment", array($order)); foreach ($results as $result) { $html .= $result; } // Set display $view = $this->getView('checkout', 'html'); $view->setLayout('postpayment'); $view->set('_doTask', true); $params = $params = JComponentHelper::getParams('com_k2store'); if ($params->get('show_postpayment_orderlink', 1)) { $view->assign('order_link', JRoute::_($order_link)); } $view->assign('plugin_html', $html); // Get and Set Model $model = $this->getModel('checkout'); $view->setModel($model, true); $view->display(); } return; }
function _process() { /* * perform initial checks */ if (!JRequest::checkToken()) { return $this->_renderHtml(JText::_('Invalid Token')); } $app = JFactory::getApplication(); $data = $app->input->getArray($_POST); $json = array(); $errors = array(); // get order information JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2store/tables'); $order = JTable::getInstance('Orders', 'Table'); $order->load($data['orderpayment_id']); if (empty($order->order_id)) { $json['error'] = JText::_('K2STORE_CHECKOUTAPIPAYMENT_INVALID_ORDER'); } if (empty($this->secret_key) || empty($this->publishable_key)) { $json['error'] = JText::_('K2STORE_CHECKOUTAPIPAYMENT_MESSAGE_MISSING_CONFIG'); } if (!$json) { require_once JPATH_SITE . '/components/com_k2store/helpers/utilities.php'; //get the order info from order info table $orderinfo = JTable::getInstance('Orderinfo', 'Table'); $orderinfo->load(array('order_id' => $order->order_id)); $currency_values = $this->getCurrency($order); $amount = $this->getAmount($order->orderpayment_amount, $currency_values['currency_code'], $currency_values['currency_value'], $currency_values['convert']); $amountCents = $amount * 100; $config = array(); $config['authorization'] = $this->secret_key; $config['mode'] = $this->endpoint; $config['postedParam'] = array('email' => $orderinfo->user_email, 'value' => $amountCents, 'currency' => $order->currency_code, 'shippingDetails' => array('addressLine1' => $orderinfo->shipping_address_1, 'addressLine2' => $orderinfo->shipping_address_2, 'Postcode' => $orderinfo->shipping_zip, 'Country' => $orderinfo->shipping_country_name, 'City' => $orderinfo->shipping_city, 'State' => $orderinfo->shipping_zone_name, 'Phone' => !empty($orderinfo->shipping_phone_1) ? $orderinfo->shipping_phone_1 : $orderinfo->shipping_phone_2, 'recipientname' => $orderinfo->shipping_first_name . ' ' . $orderinfo->shipping_first_name)); if ($this->trans_type == 'Authorize_Capture') { $config = array_merge($this->captureConfig(), $config); } else { $config = array_merge($this->authorizeConfig(), $config); } if ($this->ispci == "Yes") { $config['postedParam']['card']['name'] = $data['cardname']; $config['postedParam']['card']['number'] = $data['cardnum']; $config['postedParam']['card']['expiryMonth'] = $data['cardmonth']; $config['postedParam']['card']['expiryYear'] = $data['cardyear']; $config['postedParam']['card']['cvv'] = $data['cardcvv']; $config['postedParam']['card']['billingDetails']['addressLine1'] = $orderinfo->billing_address_1; $config['postedParam']['card']['billingDetails']['addressLine2'] = $orderinfo->billing_address_2; $config['postedParam']['card']['billingDetails']['postcode'] = $orderinfo->billing_zip; $config['postedParam']['card']['billingDetails']['country'] = $orderinfo->billing_country_name; $config['postedParam']['card']['billingDetails']['city'] = $orderinfo->billing_city; $config['postedParam']['card']['billingDetails']['city'] = $orderinfo->billing_zone_name; $config['postedParam']['card']['billingDetails']['phone'] = !empty($orderinfo->billing_phone_1) ? $orderinfo->billing_phone_1 : $orderinfo->billing_phone_2; } else { $config['postedParam']['email'] = $data['cko_cc_email']; $config['postedParam']['cardToken'] = $data['cko_cc_token']; } $respondCharge = $this->placeOrder($config); if ($respondCharge->isValid()) { if (preg_match('/^1[0-9]+$/', $respondCharge->getResponseCode())) { $order->order_state_id = 1; $order->order_state = JText::_('K2STORE_CONFIRMED'); } else { $errMsg = JText::_('K2STORE_CHECKOUTAPI_MESSAGE_TRANSACTION_UNSUCCESSFUL') . $respondCharge->getResponseMessage(); $order->order_state_id = 3; $order->order_state = JText::_('K2STORE_DECLINED'); $errors[] = $errMsg; $this->_log($errMsg, 'Error Message'); } } else { $errMsg = JText::_('K2STORE_CHECKOUTAPI_MESSAGE_TRANSACTION_UNSUCCESSFUL') . $respondCharge->getExceptionState()->getErrorMessage(); $order->order_state_id = 3; $order->order_state = JText::_('K2STORE_FAILED'); $errors[] = $errMsg; $this->_log($errMsg, 'Error Message'); } if (!$order->save()) { $errors[] = $order->getError(); } if (empty($errors)) { $json['success'] = JText::_($this->params->get('onafterpayment', '')); $json['redirect'] = JRoute::_('index.php?option=com_k2store&view=checkout&task=confirmPayment&orderpayment_type=' . $this->_element . '&paction=display'); K2StoreHelperCart::removeOrderItems($order->id); } if (count($errors)) { $json['error'] = implode("\n", $errors); } } return $json; }
/** * 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 $app = JFactory::getApplication(); $vars = new JObject(); $html = ''; $orderpayment_id = $app->input->getInt('orderpayment_id'); // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2store/tables'); $orderpayment = JTable::getInstance('Orders', 'Table'); $orderpayment->load($orderpayment_id); if ($orderpayment->id == $orderpayment_id) { $bank_information = $this->params->get('bank_information', ''); //we have to save the bank information in the customer note because that is the only field availale to display now //TODO: Trigger a plugin event so that you can show custom info depending on the payment plugin. //get the customer note. We dont want to overwrite it. if (JString::strlen($bank_information) > 5) { $customer_note = $orderpayment->customer_note; $html = '<br />'; $html .= '<strong>' . JText::_('K2STORE_BANK_TRANSFER_INSTRUCTIONS') . '</strong>'; $html .= '<br />'; $html .= $bank_information; $orderpayment->customer_note = $customer_note . $html; } $payment_status = $this->getPaymentStatus($this->params->get('payment_status', 4)); $orderpayment->transaction_status = $payment_status; $orderpayment->order_state = $payment_status; $orderpayment->order_state_id = $this->params->get('payment_status', 4); // DEFAULT: PENDING // save the orderpayment if ($orderpayment->save()) { JLoader::register('K2StoreHelperCart', JPATH_SITE . '/components/com_k2store/helpers/cart.php'); // remove items from cart K2StoreHelperCart::removeOrderItems($orderpayment->id); } else { $errors[] = $orderpayment->getError(); } // let us inform the user that the order is successful require_once JPATH_SITE . '/components/com_k2store/helpers/orders.php'; K2StoreOrdersHelper::sendUserEmail($orderpayment->user_id, $orderpayment->order_id, $orderpayment->transaction_status, $orderpayment->order_state, $orderpayment->order_state_id); $vars->onafterpayment_text = $this->params->get('onafterpayment', ''); // display the layout $html = $this->_getLayout('postpayment', $vars); // append the article with banktransfer payment information $html .= $this->_displayArticle(); } return $html; }
/** * 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 = JRequest::getVar('orderpayment_id'); $offline_payment_method = JRequest::getVar('offline_payment_method'); $formatted = array('offline_payment_method' => $offline_payment_method); // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2store' . DS . 'tables'); $orderpayment = JTable::getInstance('Orders', 'Table'); //remove this after live. //$orderpayment_id = substr($orderpayment_id, 2, 3); $orderpayment->load($orderpayment_id); $orderpayment->transaction_details = implode("\n", $formatted); //$orderpayment->transaction_status = JText::_('Pending_Payment'); //$orderpayment->order_state = JText::_('Pending'); $payment_status = $this->getPaymentStatus($this->params->get('payment_status', 4)); $orderpayment->transaction_status = $payment_status; $orderpayment->order_state = $payment_status; $orderpayment->order_state_id = $this->params->get('payment_status', 4); // PENDING // save the orderpayment if ($orderpayment->save()) { JLoader::register('K2StoreHelperCart', JPATH_SITE . '/components/com_k2store/helpers/cart.php'); // remove items from cart K2StoreHelperCart::removeOrderItems($orderpayment->id); } else { $errors[] = $orderpayment->getError(); } // let us inform the user that the order is successful require_once JPATH_SITE . '/components/com_k2store/helpers/orders.php'; K2StoreOrdersHelper::sendUserEmail($orderpayment->user_id, $orderpayment->order_id, $orderpayment->transaction_status, $orderpayment->order_state, $orderpayment->order_state_id); $vars->onafterpayment_text = $this->params->get('onafterpayment', ''); // display the layout $html = $this->_getLayout('postpayment', $vars); // append the article with offline payment information $html .= $this->_displayArticle(); return $html; }