loadLanguage('', JPATH_ADMINISTRATOR);
* Prepares variables for the payment form.
* Displayed when customer selects the method in Shipping and Payment step of Checkout
function _renderForm($data)
$user = JFactory::getUser();
$vars->onselection_text = 'You have selected this method. You will be redirected.';
//if this is a direct integration, the form layout should have the credit card form fields.
$html = $this->_getLayout('form', $vars);
* Method to display a Place order button either to redirect the customer or process the credit card information.
* @param $data array form post data
* @return string HTML to display
function _prePayment($data)
$params = J2Store::config();
$currency = J2Store::currency();
// prepare the payment form
$vars->order_id = $data['order_id'];
$vars->orderpayment_id = $data['orderpayment_id'];
F0FTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/tables');
$order = F0FTable::getInstance('Order', 'J2StoreTable')->getClone();
$order->load(array('order_id' => $data['order_id']));
$currency_values = $this->getCurrency($order);
$vars->currency_code = $currency_values['currency_code'];
$vars->orderpayment_amount = $currency->format($order->order_total, $currency_values['currency_code'], $currency_values['currency_value'], false);
$return_url = $rootURL . JRoute::_("index.php?option=com_j2store&view=checkout&task=confirmPayment&orderpayment_type=" . $this->_element . "&paction=display");
$cancel_url = $rootURL . JRoute::_("index.php?option=com_j2store&view=checkout&task=confirmPayment&orderpayment_type=" . $this->_element . "&paction=cancel");
$callback_url = JURI::root() . "index.php?option=com_j2store&view=checkout&task=confirmPayment&orderpayment_type=" . $this->_element . "&paction=callback&tmpl=component";
$orderinfo = $order->getOrderInformation();
$vars->invoice = $order->getInvoiceNumber();
$html = $this->_getLayout('prepayment', $vars);
* 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)
$app = JFactory::getApplication();
$paction = $app->input->getString('paction');
$vars->message = 'Thank you for the order.';
$html = $this->_getLayout('message', $vars);
//get the thank you message from the article (ID) provided in the plugin params
$html .= $this->_displayArticle();
//Its a call back. You can update the order based on the response from the payment gateway
$vars->message = 'Some message to the gateway'
//process the response from the gateway
$html = $this->_getLayout('message', $vars);
$vars->message = 'Sorry, you have cancelled the order'
$html = $this->_getLayout('message', $vars);
$vars->message = 'Seems an unknow request.'
$html = $this->_getLayout('message', $vars);
* Processes the sale payment
private function _processSale()
$app = JFactory::getApplication();
$data = $app->input->getArray($_POST);
//get the order id sent by the gateway. This may differ based on the API of your payment gateway
$order_id = $data['YOUR_PAYMENT_GATEWAY_FIELD_HOLDING_ORDER_ID'];
// load the orderpayment record and set some values
$order = F0FTable::getInstance('Order', 'J2StoreTable')->getClone();
if ($order->load(array('order_id' => $order_id))) {
$order->add_history(JText::_('J2STORE_CALLBACK_RESPONSE_RECEIVED'));
//run any checks you want here.
//if payment successful, call : $order->payment_complete ();
$errors[] = $order->getError();
return count($errors) ? implode("\n", $errors) : '';