array('NOTIFY_URL_DEFINE','html',''), //The URL where the payment plateform the user about the payment (fail or success) 'returnurl' => array('Example return URL. Copy and paste the notification URL above here', 'input'), 'product_id' => array('product id given to you by Example', 'input'), 'pay_item_id' => array('pay item id given to you by Example', 'input'), 'Unique_Key' => array('Unique Key given to you by Example', 'input'), 'site_name' => array('site name eg www.yoursite.com', 'input'), 'url' => array('Example Payment URL given to you','input'), // Example platform payment's url 'currencyCodeNaira' => array('currencyCodeNaira - type 566 here', 'input'), 'prefix_for_ReferenceT' => array('prefix for transaction reference - optional', 'input'), 'notification' => array('ALLOW_NOTIFICATIONS_FROM_X', 'boolean','0'), //To allow (or not) notifications from the payment platform. The plugin can only work if notifications are allowed 'debug' => array('DEBUG', 'boolean','0'), //Write some things on the debug file 'invalid_status' => array('INVALID_STATUS', 'orderstatus'), //Invalid status for order in case of problem during the payment process 'verified_status' => array('VERIFIED_STATUS', 'orderstatus') //Valid status for order if the payment has been done well ); // The constructor is optional if you don't need to initialize some parameters of some fields of the configuration and not that it can also be done in the getPaymentDefaultValues function as you will see later on function __construct(&$subject, $config) { $this->pluginConfig['notification'][0] = JText::sprintf('ALLOW_NOTIFICATIONS_FROM_X','Example'); // This is the cancel URL of HikaShop that should be given to the payment gateway so that it can redirect to it when the user cancel the payment on the payment gateway page. That URL will automatically cancel the order of the user and redirect him to the checkout so that he can choose another payment method $this->pluginConfig['cancel_url'][2] = HIKASHOP_LIVE."index.php?option=com_hikashop&ctrl=order&task=cancel_order"; // This is the "thank you" or "return" URL of HikaShop that should be given to the payment gateway so that it can redirect to it when the payment of the user is valid. That URL will reinit some variables in the session like the cart and will then automatically redirect to the "return_url" parameter $this->pluginConfig['return_url'][2] = HIKASHOP_LIVE."index.php?option=com_hikashop&ctrl=checkout&task=after_end"; // This is the "notification" URL of HikaShop that should be given to the payment gateway so that it can send a request to that URL in order to tell HikaShop that the payment has been done (sometimes the payment gateway doesn't do that and passes the information to the return URL, in which case you need to use that notification URL as return URL and redirect the user to the HikaShop return URL at the end of the onPaymentNotification function) $this->pluginConfig['notify_url'][2] = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify&notif_payment='.$this->name.'&tmpl=component'; return parent::__construct($subject, $config); } //This function is called at the end of the checkout. That's the function which should display your payment gateway redirection form with the data from HikaShop function onAfterOrderConfirm(&$order,&$methods,$method_id) { parent::onAfterOrderConfirm($order,$methods,$method_id); // This is a mandatory line in order to initialize the attributes of the payment method //Here we can do some checks on the options of the payment method and make sure that every required parameter is set and otherwise display an error message to the user if (empty($this->payment_params->returnurl)) //The plugin can only work if those parameters are configured on the website's backend { $this->app->enqueueMessage('You have to configure the return url for the Example payment plugin first : check your plugin\'s parameters, on your website backend','error'); //Enqueued messages will appear to the user, as Joomla's error messages return false; } elseif (empty($this->payment_params->product_id)) { $this->app->enqueueMessage('You have to configure a product id for the Example payment plugin first : check your plugin\'s parameters, on your website backend','error'); return false; } elseif (empty($this->payment_params->pay_item_id)) { $this->app->enqueueMessage('You have to configure a pay item id for the Example payment plugin first : check your plugin\'s parameters, on your website backend','error'); return false; } elseif (empty($this->payment_params->Unique_Key)) { $this->app->enqueueMessage('You have to configure a Mac Key for the Example payment plugin first : check your plugin\'s parameters, on your website backend','error'); return false; } elseif (empty($this->payment_params->site_name)) { $this->app->enqueueMessage('You have to configure a site name for the Example payment plugin first : check your plugin\'s parameters, on your website backend','error'); return false; } elseif (empty($this->payment_params->url)) { $this->app->enqueueMessage('You have to configure a payment URL for the Example payment plugin first : check your plugin\'s parameters, on your website backend','error'); return false; } elseif (empty($this->payment_params->currencyCodeNaira)) { $this->app->enqueueMessage('You have to configure the Naira currency Code (566) for the Example payment plugin first : check your plugin\'s parameters, on your website backend','error'); return false; } else { //Here, all the required parameters are valid, so we can proceed to the payment platform //First we need to create the transaction reference which is unique to each order as required by Example $ReferenceT = $order->order_id; $ReferenceT .= '_'; $ReferenceT .= $this->payment_params->prefix_for_ReferenceT; $ReferenceT .= uniqid(); //Now we put together all the data, in addition to the transaction reference, to be hashed as required by Example $product_id = $this->payment_params->product_id; $pay_item_id = $this->payment_params->pay_item_id; $amount = round($order->cart->full_total->prices[0]->price_value_with_tax,2)*100; //The order's amount, here in kobo and rounded with 2 decimals because of the payment plateform's requirements $site_redirect_url = $this->payment_params->returnurl; $Unique_Key = $this->payment_params->Unique_Key; //Process the hash now //First join the data $data_to_hash = $ReferenceT; $data_to_hash .=$product_id; $data_to_hash .=$pay_item_id; $data_to_hash .=$amount; $data_to_hash .=$site_redirect_url; $data_to_hash .=$Unique_Key; //the hash algorithm to be used $hashAlgorithm = 'sha512'; //Now perform the hash $hashedData = hash($hashAlgorithm, $data_to_hash, false); //This array contains all the required parameters by the payment plateform //Not all the payment platforms will need all these parameters and they will probably have a different name. //You need to look at the payment gateway integration guide provided by the payment gateway in order to know what is needed here $vars = array( //product_id, amount, currency, site_redirect_url, ReferenceT, hash and pay_item_id "product_id" => $product_id, "amount" => $amount, "currency" => $this->payment_params->currencyCodeNaira, "site_redirect_url" => $site_redirect_url, "ReferenceT" => $ReferenceT, "hash" => $hashedData, "pay_item_id" => $pay_item_id, //"site_name" => $this->payment_params->site_name, ); $this->vars = $vars; //Ending the checkout, ready to be redirect to the plateform payment final form //The showPage function will call the example_end.php file which will display the redirection form containing all the parameters for the payment platform return $this->showPage('end'); } } //To set the specific configuration (back end) default values (see $pluginConfig array) function getPaymentDefaultValues(&$element) { $element->payment_name='Example'; $element->payment_description='You can pay by credit card using this payment method'; $element->payment_images='MasterCard,VISA,Credit_card'; $element->payment_params->address_type="billing"; $element->payment_params->notification=1; $element->payment_params->invalid_status='cancelled'; $element->payment_params->verified_status='confirmed'; } //After submiting the plateform payment form, this is where the website will receive the response information from the payment gateway servers and then validate or not the order function onPaymentNotification(&$statuses) { $method_id = JRequest::getInt('notif_id', 0); $this->pluginParams($method_id); $this->payment_params =& $this->plugin_params; if(empty($this->payment_params)) return false; //We first create a filtered array from the parameters received $vars = array(); $data = array(); $filter = JFilterInput::getInstance(); // A loop to create an array $var with all the parameters sent by the payment gateway with a POST method, and loaded in the $_REQUEST foreach($_POST as $key => $value) { $key = $filter->clean($key); $value = JRequest::getString($key); $vars[$key]=$value; } ////////////// // Hold the response from the Example payment gateway in variable names // load the parameters of the plugin in $this->payment_params and the order data based on the order_id coming from the payment platform $txnrefSentBack = @$vars['txnref']; $payRefSentBack = @$vars['PaymentRef']; $refRefSentBack = @$vars['MerchantRef']; //extract the order_ID from the txnref $order_id = $txnrefSentBack; $order_id = strchr($order_id,"_", true); //now retrieve the amount from Hikashop database $app =JFactory::getApplication(); $orderClass = hikashop_get('class.order'); $currencyClass = hikashop_get('class.currency'); $fullOrder = $orderClass->get($order_id); $amountInHakashop = $currencyClass->round($fullOrder->order_full_price * 100,2); /* ///////////////////////// Here write code to confirm or not the Order, depending of the information received $this->modifyOrder($order_id, $this->payment_params->verified_status, true, true); ///////////////////////// */ //Configure the "succes URL" and the "fail URL" to redirect the user if necessary (not necessary for our example platform $return_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id='.$order_id.$this->url_itemid; //$cancel_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=order&task=cancel_order&order_id='.$order_id.$this->url_itemid; $this->app->redirect($return_url); return true; } }