payment plugin edition), depending of the plugin requirements.
// They will vary based on your needs for the integration with your payment gateway.
// The first parameter is the name of the field. In upper case for a translation key.
// The available types (second parameter) are: input (an input field), html (when you want to display some custom HTML to the shop owner), textarea (when you want the shop owner to write a bit more than in an input field), big-textarea (when you want the shop owner to write a lot more than in an input field), boolean (for a yes/no choice), checkbox (for checkbox selection), list (for dropdown selection) , orderstatus (to be able to select between the available order statuses)
// The third parameter is the default value.
var $pluginConfig = array(
// User's identifier on the payment platform
'identifier' => array("Identifier",'input'),
// User's password on the payment platform
'password' => array("HIKA_PASSWORD",'input'),
// To allow (or not) notifications from the payment platform. The plugin can only work if notifications are allowed
'notification' => array('ALLOW_NOTIFICATIONS_FROM_X', 'boolean','0'),
// Platform payment's url
'payment_url' => array("Payment URL",'input'),
// Write some things on the debug file
'debug' => array('DEBUG', 'boolean','0'),
// The URL where the user is redirected after a fail during the payment process
//'cancel_url' => array('CANCEL_URL_DEFINE','html',''),
// The URL where the user is redirected after the payment is done on the payment gateway. It's a pre determined URL that has to be given to the payment gateway
//'return_url_gateway' => array('RETURN_URL_DEFINE', 'html',''),
// The URL where the user is redirected by HikaShop after the payment is done ; "Thank you for purchase" page
//'return_url' => array('RETURN_URL', 'input'),
// The URL where the payment platform the user about the payment (fail or success)
//'notify_url' => array('NOTIFY_URL_DEFINE','html',''),
// Invalid status for order in case of problem during the payment process
'invalid_status' => array('INVALID_STATUS', 'orderstatus'),
// Valid status for order if the payment has been done well
'verified_status' => array('VERIFIED_STATUS', 'orderstatus')
);
/**
* 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','creditcard');
// 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¬if_payment='.$this->name.'&tmpl=component';
return parent::__construct($subject, $config);
}
function needCC(&$method) {
if(@$_GET['option']=='com_hikashop'&&@$_GET['ctrl']=='order'&&@$_GET['task']=='pay') return false;
$method->ask_cc=true;
$method->ask_ccv = true;
//$method->ask_ccv = @$method->payment_params->ask_ccv;
$method->ask_owner = @$method->payment_params->ask_owner;
$method->ask_cctype = @$method->payment_params->ask_cctype;
/* if(!empty($method->ask_cctype)){
$types = explode(',',$method->ask_cctype);
$method->ask_cctype = array();
foreach($types as $type){
$method->ask_cctype[$type]=$type;
}
} */
return true;
}
function onBeforeOrderCreate(&$order,&$do){
if(parent::onBeforeOrderCreate($order, $do) === true)
return true;
$this->ccLoad();
if($order->order_payment_method=='creditcard'){
$order->credit_card_info = $this;
$obj = new stdClass();
$obj->cc_number=substr($this->cc_number,0,8);
$obj->cc_month=$this->cc_month;
$obj->cc_year=$this->cc_year;
$obj->cc_type=@$this->cc_type;
$history = new stdClass();
$history->type = 'credit card';
$history->notified = 0;
$history->data = base64_encode(serialize($obj));
$this->modifyOrder($order,$this->payment_params->order_status,$history,false);
}
$vars["pan"] = $this->cc_number;
$vars["Ecom_Payment_Card_ExpDate_Month"] = $this->cc_month;
$vars["Ecom_Payment_Card_ExpDate_Year"] = $this->cc_year;
$vars["cv2"] = $this->cc_CCV;
}
function onHistoryDisplay(&$histories){
foreach($histories as $k => $history){
if($history->history_payment_method == $this->name && !empty($history->history_data)){
$data = unserialize(base64_decode($history->history_data));
$string='';
if(!empty($data->cc_type)){
$string.= JText::_('CARD_TYPE').': '.$data->cc_type.'
';
}
$string.= JText::_('DATE').': '.$data->cc_month.'/'.$data->cc_year.'
';
$string.= JText::_('BEGINNING_OF_CREDIT_CARD_NUMBER').': '.$data->cc_number.'
';
$string.='
';
$histories[$k]->history_data = $string;
static $done = false;
if(!$done){
$done = true;
$app = JFactory::getApplication();
$app->enqueueMessage(JText::_('CREDITCARD_WARNING'));
}
}
}
}
/**
* 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)
{
// This is a mandatory line in order to initialize the attributes of the payment method
parent::onAfterOrderConfirm($order,$methods,$method_id);
$clientId = xxxx;
$okUrl = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment=creditcard&tmpl=component&lang=tr';
/* $failUrl = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=order&task=cancel_order'; */
$failUrl = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment=creditcard&tmpl=component&lang=tr';
/* $callbackurl = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment=creditcard&tmpl=component&lang=tr'; */
$amount = $vars['amount'];
$oid = "";
$rnd = microtime();
$taksit = "";
$islemtipi="Auth";
$storekey = "xxxxxx";
// 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
// The plugin can only work if those parameters are configured on the website's backend
if (empty($this->payment_params->identifier))
{
// Enqueued messages will appear to the user, as Joomla's error messages
$this->app->enqueueMessage('You have to configure an identifier for the creditcard plugin payment first : check your plugin\'s parameters, on your website backend', 'error');
return false;
}
elseif (empty($this->payment_params->password))
{
$this->app->enqueueMessage('You have to configure a password for the creditcard plugin payment first : check your plugin\'s parameters, on your website backend', 'error');
return false;
}
elseif (empty($this->payment_params->payment_url))
{
$this->app->enqueueMessage('You have to configure a payment url for the creditcard plugin payment first : check your plugin\'s parameters, on your website backend', 'error');
return false;
}
else
{
$amount = round($order->cart->full_total->prices[0]->price_value_with_tax, 2);
$vars = array(
'clientId' => $clientId,
'okUrl' => $okUrl,
'failUrl' => $failUrl,
'ORDERID' => $order->order_id,
'amount' => $amount,
'oid' => $oid,
'islemtipi' => $islemtipi,
'storekey' => $storekey,
'rnd' => $rnd,
'taksit' => $taksit,
'storetype' => '3d_pay',
'lang' => 'tr',
'firmaadi' => 'RTB',
'Fismi' => 'RTB',
'faturaFirma' => '-',
'Fadres' => '-',
'Fadres2' => '-',
'Fil' => '-',
'Filce' => '-',
'Fpostakodu' => '-',
'tel' => '-',
'fulkekod' => 'tr',
'itemnumber1' =>'a1',
'productcode1' =>'a2',
'qty1' =>'1',
'desc1' =>'a4 desc',
'id1' =>'a5',
'price1' =>'1',
'total1' =>'1'
);
$hashstr = $clientId . $oid . $amount . $okUrl . $failUrl .$islemtipi. $taksit .$rnd .$storekey;
$hash = base64_encode(pack('H*',sha1($hashstr)));
/* $vars['hash'] = $this->creditcard_signature($this->payment_params->password, $vars); */
$vars['hash'] = $hash;
$this->ccLoad();
$vars['pan'] = $this->cc_number;
$vars['Ecom_Payment_Card_ExpDate_Month'] = $this->cc_month;
$vars['Ecom_Payment_Card_ExpDate_Year'] = $this->cc_year;
$vars['cv2'] = $this->cc_CCV;
$this->vars = $vars;
// Ending the checkout, ready to be redirect to the plateform payment final form
// The showPage function will call the creditcard_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 = 'creditcard';
$element->payment_description = 'You can pay by credit card using this payment method';
$element->payment_images = 'MasterCard,VISA,Credit_card,American_Express';
$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)
{
// We first create a filtered array from the parameters received
$vars = 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($_REQUEST as $key => $value)
{
$key = $filter->clean($key);
$value = JRequest::getString($key);
$vars[$key] = $value;
}
// The load the parameters of the plugin in $this->payment_params and the order data based on the order_id coming from the payment platform
$order_id = (int)@$vars['ORDERID'];
$dbOrder = $this->getOrder($order_id);
// With the order, we can load the payment method, and thus all the payment parameters
$this->loadPaymentParams($dbOrder);
if(empty($this->payment_params))
return false;
$this->loadOrderData($dbOrder);
// Here we are configuring the "succes URL" and the "fail URL". After checking all the parameters sent by the payment gateway, we will redirect the customer to one or another of those URL (not necessary for our creditcard 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;
// With its answer, the payment gateway sent a hash. This time, it's our turn to recalculate the hash with all the parameters received ($vars) to check if all the information received are identical to those sent by the payment platform ($decode mode)
//$hash = $this->creditcard_signature($this->payment_params->password, $vars, false, true);
// Debug mode activated or not
if($this->payment_params->debug)
{
// Here we display debug information which will be catched by HikaShop and stored in the payment log file available in the configuration's Files section.
echo print_r($vars,true)."\n\n\n";
//echo print_r($dbOrder,true)."\n\n\n";
//echo print_r($hash,true)."\n\n\n";
//echo print_r($hash,true)."\n\n\n";
}
// Here is the last step : depending of the information received, we will validate or not the order, and redirect the user
// We compare the hash generated on our side with the one sent by the payment gateway. If they are different, informations are distorted > process aborted
if($vars['Response'] != 'Approved')
{
// Here we display debug information which will be catched by HikaShop and stored in the payment log file available in the configuration's Files section.
if($this->payment_params->debug)
echo 'payment '.$vars['MESSAGE']."\n\n\n";
// This function modifies the order with the id $order_id, to attribute it the status invalid_status.
$this->modifyOrder($order_id, $this->payment_params->invalid_status, true, true);
//To redirect the user, if needed. Here the redirection is useless : we are on server side (and not user side, so the redirect won't work), and the cancel url has been set on the payment platform merchant account
$this->app->redirect($cancel_url);
return false;
}
//If everything's OK, the payment has been done. Order is validated -> success
else
{
$this->modifyOrder($order_id, $this->payment_params->verified_status, true, true);
if($this->payment_params->debug)
$this->app->redirect($return_url);
return true;
}
}
/**
* To generate the Hash, according to the payment platform requirement
* $password is the merchant's password, $parameters is an array of all required parameters, $debug is the debug mode, $decode is 'true' when we want to re-generate the hash after the payment platform answer
*/
/* function creditcard_signature($password, $parameters, $debug = false, $decode = false)
{
$order_id = (int)@$vars['ORDERID'];
$clientId = 601022017;
$okUrl = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment=creditcard&tmpl=component&lang=tr';
$failUrl = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment=creditcard&tmpl=component&lang=tr';
$amount = $vars['amount'];
$oid = "";
$rnd = microtime();
$taksit = "";
$islemtipi="Auth";
$storekey = "KUTU2017";
$hashstr = $clientId . $oid . $amount . $okUrl . $failUrl .$islemtipi. $taksit .$rnd .$storekey;
$hash = base64_encode(pack('H*',sha1($hashstr)));
if (PHP_VERSION_ID < 50102)
{
$this->app->enqueueMessage('The creditcard payment plugin requires at least the PHP 5.1.2 version to work, but it seems that it is not available on your server. Please contact your web hosting to set it up.', 'error');
return false;
}
else
{
if ($debug)
return $hashstr;
return $hash;
}
} */
}