No Payment Menthod?

  • Posts: 31
  • Thank you received: 10
11 years 11 months ago #88539

Hi,

I have 2 currency set up, USD and JMD with USD as the main. My payment gateway accepts both currencies.

At checkout, when everything is in USD everything show up and works fine, checkout and all. When I switch using the Currency Switcher to JMD, everything converts and shows JMD fine, but when I go to checkout, the payment method doesn't show.

When I switch back to USD the payment method shows. I have no zone restrictions on the payment method. Any idea how to fix this?

Any help would be greatly appreciated. Thanks in advance.

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
11 years 11 months ago #88571

Hi,

Can you show me screenshots of how did you configured your payment methods ? and can you uncheck all currencies through the "Currency" option of your payment method ?

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 10
11 years 11 months ago #88608

Hi Mohamed. Thank you very much for helping. Here's the screenshot in USD.



This is what happens when I switch to JMD.



Right now, none of the shipping or payment methods have any zone restrictions applied to them.

Any idea what could be causing this?

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
11 years 11 months ago #88725

Hi,

Like I said earlier, I was talking about your payment method configuration so can you check if you had set any currency limitation through the "Currency" option of your payment method ?.

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 10
11 years 11 months ago #88832

Hi Mohamed.

Both currencies are selected. I made sure of that. (See below)



All published shipping methods are selected also and no Zones selected.

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 10
11 years 11 months ago #88904

Is it possible to use the same payment module more than once? I could set one exclusively for USD and the other exclusively for JMD. I could add a zone restriction to Jamaica only for the one with JMD and leave the other one open for all zones. Is this possible?

What if I duplicate the payment plugin and change all the occurrence of the payment plugin's to something else.. e.g. "authorize" to "authorizejmd".. Could this work?

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 11 months ago #88975

Hi,

Yes you can duplicate the payment plugin, be sure to change all the occurrence of "authorize"

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 10
11 years 11 months ago #89072

I tried duplicating the plugin and setting it for JMD currency on it's own and still nothing. I tested the dupped plugin by configuring it like I did the first one and it shows up and works fine when the currency is in USD.

Any other idea how? Is this a bug you think?

Please Log in or Create an account to join the conversation.

  • Posts: 83050
  • Thank you received: 13412
  • MODERATOR
11 years 11 months ago #89211

The authorize.net payment plugin only displays for USD.
That's because authorize.net only allows payment to be made in USD.

I see that you're using an emulator and changed the URL of the payment gateway to use plug'n'pay instead of authorize.net
However, the authorize.net payment gateway doesn't have any parameter to give the currency of the payment since it's always USD, so even if we were to add the display of auhtorize.net plugin for JMD (which is quite easy), I don't see how HikaShop could pass JMD payments to plug'n'pay via the authorize.net emulator since there is no variable to specify the currency in the API.

Maybe plug'n'pay only allows for USD payments if you use the emulator and allows for other currencies if you develop a plugin for their API ?

I would recommend you to contact their support to find out about all that. Maybe it's just one or two lines of code to add to the plugin...

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 10
11 years 11 months ago #89245

That's a good point Nicolas. Thanks.

I've been trying to figure out how to create a proper plugin for Plug 'n Pay. I'm not much of a coder, but if I get good instruction and explanations, I can pull it together myself. Unfortunately, the development documentations here don't really offer much.

I downloaded the documentations necessary for creating a plugin from Plug 'n Pay website. They also offer a PHP plugin for download from. Their PHP script is a simple implementation with with all the information that may be sent to Plug 'n Pay for a proper transaction. I'm not sure where what goes and HikaShop doesn't have all the information needed to pull it together.

What would be great is a basic starter plugin with comments. Any idea where to go for this?

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 10
11 years 11 months ago #89264

From what I'm reading from Authorize.net, the card type (x_currency_code) is optional. It seems that the Authorize.net plugin doesn't send this info.

Although Authorize.net only expects x_currency_code to carry the values of USD, CAD or GBP, maybe if we force it to only send USD or JMD, the PnP emulator may pick it up. I'm willing to give this a try.


So how do I implement that currency parameter into the authorize plugin? I've done some modification to my Authorize.net plugin already in trying to get rid of the plugin sending PostAuth by forcing it to send Auth_only. This disables the Instant Capture parameter (doesn't seems to be working anyways).

authorize.php file:

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.0.0
 * @author	hikashop.com
 * @copyright	(C) 2010-2012 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
class plgHikashoppaymentAuthorize extends JPlugin
{
		var $debugData = array();
		function onPaymentDisplay(&$order,&$methods,&$usable_methods){
			if(!empty($methods)){
				foreach($methods as $method){
				if($method->payment_type!='authorize' || !$method->enabled){
					continue;
				}


				if(!empty($method->payment_zone_namekey)){
					$zoneClass=hikashop_get('class.zone');
						$zones = $zoneClass->getOrderZones($order);
					if(!in_array($method->payment_zone_namekey,$zones)){
						return true;
					}
				}


				$currencyClass = hikashop_get('class.currency');
				$null=null;
				$currency_id = intval(@$order->total->prices[0]->price_currency_id);
				$currency = $currencyClass->getCurrencies($currency_id,$null);
				if(!empty($currency) && @$currency[$currency_id]->currency_code != 'USD'){
					return true;
				}

				$this->needCC($method);

				$usable_methods[$method->ordering]=$method;
				}
			}
			return true;
		}

	function needCC(&$method) {
		if(@$method->payment_params->api=='aim'){
			$method->ask_cc=true;
			if($method->payment_params->ask_ccv){
				$method->ask_ccv = true;
			}
			return true;
		}
		return false;
	}

		function onPaymentSave(&$cart,&$rates,&$payment_id){
			$usable = array();
			$this->onPaymentDisplay($cart,$rates,$usable);
			$payment_id = (int) $payment_id;
			foreach($usable as $usable_method){
				if($usable_method->payment_id==$payment_id){
					return $usable_method;
				}
			}

			return false;
		}

		function onBeforeOrderCreate(&$order,&$do){
			$app =& JFactory::getApplication();
			if($app->isAdmin()){
				return true;
			}
			if(empty($order->order_payment_method) || $order->order_payment_method != 'authorize'){
				return true;
			}

			$db = JFactory::getDBO();
			$query = 'SELECT * FROM '.hikashop_table('payment').' WHERE payment_type='.$db->Quote($order->order_payment_method);
		$db->setQuery($query);
		$paymentData = $db->loadObjectList('payment_id');
		$pluginsClass = hikashop_get('class.plugins');
		$pluginsClass->params($paymentData,'payment');
		$method =& $paymentData[$order->order_payment_id];
		if(@$method->payment_params->api!='aim'){
			return true;
		}
		if(!function_exists('curl_init')){
			$app->enqueueMessage('The Authorize.net payment plugin in AIM mode needs the CURL library installed but it seems that it is not available on your server. Please contact your web hosting to set it up.','error');
			return false;
		}
		$vars = $this->_loadStandardVars($order,$method);

		$vars["x_delim_data"]= "TRUE";
		$vars["x_delim_char"] = "|";

		$this->cc_number = $app->getUserState( HIKASHOP_COMPONENT.'.cc_number');
		if(!empty($this->cc_number)){
			$this->cc_number = base64_decode($this->cc_number);
		}
		$this->cc_month = $app->getUserState( HIKASHOP_COMPONENT.'.cc_month');
		if(!empty($this->cc_month)){
			$this->cc_month = base64_decode($this->cc_month);
		}
		$this->cc_year = $app->getUserState( HIKASHOP_COMPONENT.'.cc_year');
		if(!empty($this->cc_year)){
			$this->cc_year = base64_decode($this->cc_year);
		}
		$vars["x_card_num"] = $this->cc_number;
		if($method->payment_params->ask_ccv){
			$this->cc_CCV = $app->getUserState( HIKASHOP_COMPONENT.'.cc_CCV');
			if(!empty($this->cc_CCV)){
				$this->cc_CCV = base64_decode($this->cc_CCV);
			}
			$vars["x_card_code"] = $this->cc_CCV;
		}
		$vars["x_exp_date"] = $this->cc_month.$this->cc_year;
		$vars["x_tran_key"] = $method->payment_params->transaction_key;
		$post_string = "";

		foreach( $vars as $key => $value ){
			if(is_array($value)){
				foreach($value as $v){
					$post_string .= "$key=" . urlencode( $v ) . "&";
				}
			}else{
				$post_string .= "$key=" . urlencode( $value ) . "&";
			}
		}
		$post_string = rtrim( $post_string, "& " );
		$request = curl_init($method->payment_params->url);
		curl_setopt($request, CURLOPT_HEADER, 0);
		curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($request, CURLOPT_POSTFIELDS, $post_string);
		curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE);
		$post_response = curl_exec($request);

		if(empty($post_response)){
			$app->enqueueMessage('The connection to the payment plateform did not succeed. It is often caused by the hosting company blocking external connections so you should contact him for further guidance. The cURL error message was: '.curl_error($request),'error');
			return false;
		}
		curl_close ($request);
		$response_array = explode("|",$post_response);
		$response_code        = (int)@$response_array[0];
		$response_subcode     = @$response_array[1];
		$response_reason_code = @$response_array[2];
		$response_reason_text = @$response_array[3];
		$this->response_code = $response_code;
		switch($response_code) {
			case 2:
				$app->enqueueMessage(JText::_('TRANSACTION_DECLINED_WRONG_CARD'));
				$app->setUserState( HIKASHOP_COMPONENT.'.cc_number','');
				$app->setUserState( HIKASHOP_COMPONENT.'.cc_month','');
				$app->setUserState( HIKASHOP_COMPONENT.'.cc_year','');
				$app->setUserState( HIKASHOP_COMPONENT.'.cc_CCV','');
				$app->setUserState( HIKASHOP_COMPONENT.'.cc_owner','');
				$app->setUserState( HIKASHOP_COMPONENT.'.cc_valid',0);
				$do = false;
				break;
			case 3:
			default:
				$app->enqueueMessage(JText::sprintf('TRANSACTION_PROCESSING_ERROR',$response_reason_code.' '.$response_reason_text));
				$app->setUserState( HIKASHOP_COMPONENT.'.cc_number','');
				$app->setUserState( HIKASHOP_COMPONENT.'.cc_month','');
				$app->setUserState( HIKASHOP_COMPONENT.'.cc_year','');
				$app->setUserState( HIKASHOP_COMPONENT.'.cc_CCV','');
				$app->setUserState( HIKASHOP_COMPONENT.'.cc_owner','');
				$app->setUserState( HIKASHOP_COMPONENT.'.cc_valid',0);
				$do = false;
				break;
				case 1:
					$order->history->history_reason=JText::sprintf('AUTOMATIC_PAYMENT_NOTIFICATION');
				$order->history->history_notified=0;
				$order->history->history_amount= round($order->cart->full_total->prices[0]->price_value_with_tax,2).'USD';
				$order->history->history_payment_id = $order->order_payment_id;
				$order->history->history_payment_method =$order->order_payment_method;
				$order->history->history_data = '';
				$order->history->history_type = 'payment';
				$order->order_status = $method->payment_params->verified_status;
				break;
				case 4:
				$order->history->history_reason=JText::sprintf('AUTOMATIC_PAYMENT_NOTIFICATION');
				$order->history->history_notified=0;
				$order->history->history_amount= round($order->cart->full_total->prices[0]->price_value_with_tax,2).'USD';
				$order->history->history_payment_id = $order->order_payment_id;
				$order->history->history_payment_method =$order->order_payment_method;
				$order->history->history_data = '';
				$order->history->history_type = 'payment';
				$order->order_status = $element->payment_params->pending_status;
				break;
		}
		return true;
		}
		function onAfterOrderCreate(&$order,&$send_email){
			$app =& JFactory::getApplication();
			if($app->isAdmin()){
				return true;
			}
			if($order->order_payment_method!='authorize'){
				return true;
			}
			$db = JFactory::getDBO();
			$query = 'SELECT * FROM '.hikashop_table('payment').' WHERE payment_type='.$db->Quote($order->order_payment_method);
		$db->setQuery($query);
		$paymentData = $db->loadObjectList('payment_id');
		$pluginsClass = hikashop_get('class.plugins');
		$pluginsClass->params($paymentData,'payment');
		$method =& $paymentData[$order->order_payment_id];
		if(@$method->payment_params->api!='aim'){
			return true;
		}

		if(!empty($this->response_code)){
			switch($this->response_code){
				case 1:
					$mailer = JFactory::getMailer();
					$config =& hikashop_config();
					$sender = array(
							$config->get('from_email'),
							$config->get('from_name') );
					$mailer->setSender($sender);
					$mailer->addRecipient(explode(',',$config->get('payment_notification_email')));
					$url = HIKASHOP_LIVE.'administrator/index.php?option=com_hikashop&ctrl=order&task=listing';
					$order_text = "\r\n".JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE',$order->order_number,HIKASHOP_LIVE);
					$order_text .= "\r\n".str_replace('<br/>',"\r\n",JText::sprintf('ACCESS_ORDER_WITH_LINK',$url));
					$mailer->setSubject(JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER','Authorize.net','Accepted',$order->order_number));
					$body = str_replace('<br/>',"\r\n",JText::sprintf('PAYMENT_NOTIFICATION_STATUS','Authorize.net','Accepted')).' '.JText::sprintf('ORDER_STATUS_CHANGED',$order->order_status)."\r\n\r\n".$order_text;
					$mailer->setBody($body);
					$mailer->Send();
					break;
				case 4:
					$mailer = JFactory::getMailer();
					$config =& hikashop_config();
					$sender = array(
							$config->get('from_email'),
							$config->get('from_name') );
					$mailer->setSender($sender);
					$mailer->addRecipient(explode(',',$config->get('payment_notification_email')));
					$url = HIKASHOP_LIVE.'administrator/index.php?option=com_hikashop&ctrl=order&task=listing';
					$order_text = "\r\n".JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE',$order->order_number,HIKASHOP_LIVE);
					$order_text .= "\r\n".str_replace('<br/>',"\r\n",JText::sprintf('ACCESS_ORDER_WITH_LINK',$url));
					$mailer->setSubject(JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER','Authorize.net','Pending',$order->order_number));
					$body = str_replace('<br/>',"\r\n",JText::sprintf('PAYMENT_NOTIFICATION_STATUS','Authorize.net','Pending')).' '.JText::sprintf('ORDER_STATUS_CHANGED',$order->order_status)."\r\n\r\n".$order_text;
					$mailer->setBody($body);
					$mailer->Send();
					break;
			}
		}
		}

		function _loadStandardVars(&$order,&$method){
		$tax_total = '';
		$discount_total = '';
		$currencyClass = hikashop_get('class.currency');
		$currencies=null;
		$currencies = $currencyClass->getCurrencies($order->order_currency_id,$currencies);
		$currency=$currencies[$order->order_currency_id];
		$user = hikashop_loadUser(true);
		$debug = $method->payment_params->debug;
		$vars = Array(
		"x_amount" => round($order->cart->full_total->prices[0]->price_value_with_tax,(int)$currency->currency_locale['int_frac_digits']),
		"x_version" => '3.1',
		"x_test_request" => $debug,
		);
		$vars["x_relay_response"] = 'FALSE';
		$vars["x_customer_ip"] = $order->order_ip;
		/*
		if(!isset($this->element->payment_params->capture))$this->element->payment_params->capture=1;
		if($this->element->payment_params->capture){
			$vars["x_type"] = 'AUTH_CAPTURE';
		}else{
			$vars["x_type"] = 'AUTH_ONLY';
		}
		*/
		$vars["x_type"] = 'AUTH_ONLY'; // Removed config option and just use the one needed

		$vars["x_login"] = $method->payment_params->login_id;
		if(!empty($order->order_id)){
			$vars["x_invoice_num"] = $order->order_id;
			$vars["x_po_num"] = $vars["x_invoice_num"];
		}

		$vars["x_email"]=$user->user_email;

		$app =& JFactory::getApplication();
		$cart = hikashop_get('class.cart');
		$address=$app->getUserState( HIKASHOP_COMPONENT.'.billing_address');
		if(!empty($address)){
			$cart->loadAddress($order->cart,$address,'object','billing');
			$vars["x_first_name"]=substr(@$order->cart->billing_address->address_firstname,0,50);
			$vars["x_last_name"]=substr(@$order->cart->billing_address->address_lastname,0,50);
			$vars["x_address"]=substr(@$order->cart->billing_address->address_street,0,60);
			$vars["x_company"]=substr(@$order->cart->billing_address->address_company,0,50);
			$vars["x_country"]=substr(@$order->cart->billing_address->address_country->zone_name_english,0,60);
			$vars["x_zip"]=substr(@$order->cart->billing_address->address_post_code,0,20);
			$vars["x_city"]=substr(@$order->cart->billing_address->address_city,0,40);
			$vars["x_state"]=substr(@$order->cart->billing_address->address_state->zone_name_english,0,40);
			$vars["x_phone"]=substr(@$order->cart->billing_address->address_telephone,0,25);
		}
			$address=$app->getUserState( HIKASHOP_COMPONENT.'.shipping_address');
		if(!empty($address)){
			$cart->loadAddress($order->cart,$address,'object','shipping');
			$vars["x_ship_to_first_name"]=substr(@$order->cart->shipping_address->address_firstname,0,50);
			$vars["x_ship_to_last_name"]=substr(@$order->cart->shipping_address->address_lastname,0,50);
			$vars["x_ship_to_address"]=substr(@$order->cart->shipping_address->address_street,0,60);
			$vars["x_ship_to_company"]=substr(@$order->cart->shipping_address->address_company,0,50);
			$vars["x_ship_to_country"]=substr(@$order->cart->shipping_address->address_country->zone_name_english,0,60);
			$vars["x_ship_to_zip"]=substr(@$order->cart->shipping_address->address_post_code,0,20);
			$vars["x_ship_to_city"]=substr(@$order->cart->shipping_address->address_city,0,40);
			$vars["x_ship_to_state"]=substr(@$order->cart->shipping_address->address_state->zone_name_english,0,40);
		}

		$i = 1;
		$tax = 0;
		$vars["x_line_item"]=array();
		foreach($order->cart->products as $product){
			if(bccomp($product->order_product_tax,0,5)){
				$tax+=$product->order_product_quantity*round($product->order_product_tax,(int)$currency->currency_locale['int_frac_digits']);
				$has_tax = 'TRUE';
			}else{
				$has_tax = 'FALSE';
			}
			$vars["x_line_item"][]=substr($product->order_product_code,0,30).'<|>'.substr(strip_tags($product->order_product_name),0,30).'<|><|>'.$product->order_product_quantity.'<|>'.round($product->order_product_price,(int)$currency->currency_locale['int_frac_digits']).'<|>'.$has_tax;
		}

		if(!empty($order->cart->coupon) && @$order->cart->coupon->discount_value>0){
			$vars["x_line_item"][]='coupon<|>'.JText::_('HIKASHOP_COUPON').'<|><|>1<|>'.round($order->cart->coupon->discount_value,(int)$currency->currency_locale['int_frac_digits']).'<|>N';
		}
		if(!empty($order->order_payment_price)){
			$vars["x_line_item"][]='payment<|>'.JText::_('HIKASHOP_PAYMENT').'<|><|>1<|>'.round($order->order_payment_price,(int)$currency->currency_locale['int_frac_digits']).'<|>N';
		}

		if(bccomp($tax,0,5)){
			$vars['x_tax']=$tax;
			$vars['x_tax_exempt']='FALSE';
		}else{
			$vars['x_tax_exempt']='TRUE';
		}
		if(!empty($order->order_shipping_price)){
			$vars["x_freight"]=round($order->order_shipping_price,(int)$currency->currency_locale['int_frac_digits']);
		}
		return $vars;
		}

		function onAfterOrderConfirm(&$order,&$methods,$method_id){
			$method =& $methods[$method_id];
			if(@$method->payment_params->api=='aim'){
				$viewType='_thankyou';
			global $Itemid;
			$url_itemid='';
			if(!empty($Itemid)){
				$url_itemid='&Itemid='.$Itemid;
			}
			$return_url =  HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id='.$order->order_id.$url_itemid;
			$this->removeCart = true;
			}else{
			$method->payment_params->iframe = 1;
			$vars = $this->_loadStandardVars($order,$method);
			$viewType = '_end';

			$vars["x_show_form"] = 'PAYMENT_FORM';
			if(@$method->payment_params->notification){
				$vars["x_relay_response"] = 'TRUE';

				$lang = &JFactory::getLanguage();
				$locale=strtolower(substr($lang->get('tag'),0,2));
				global $Itemid;
				$url_itemid='';
				if(!empty($Itemid)){
					$url_itemid='&Itemid='.$Itemid;
				}
				$vars["x_relay_url"] = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify&notif_payment=authorize&tmpl=component&lang='.$locale.$url_itemid;
			}
			$vars["x_fp_sequence"] = $vars["x_invoice_num"];
			$vars["x_fp_timestamp"] = time();
			$vars["x_fp_hash"] = hash_hmac("md5", $vars["x_login"] . "^" . $vars["x_fp_sequence"] . "^" . $vars["x_fp_timestamp"] . "^" . $vars["x_amount"] . "^", $method->payment_params->transaction_key);
			if(!empty($method->payment_params->x_logo_url)){
				$vars['x_logo_url']=$method->payment_params->x_logo_url;
			}
		}

		if(!HIKASHOP_J30)
			JHTML::_('behavior.mootools');
		else
			JHTML::_('behavior.framework');
		$app =& JFactory::getApplication();
		$name = $method->payment_type.$viewType.'.php';
			$path = JPATH_THEMES.DS.$app->getTemplate().DS.'hikashoppayment'.DS.$name;
			if(!file_exists($path)){
				if(version_compare(JVERSION,'1.6','<')){
					$path = JPATH_PLUGINS .DS.'hikashoppayment'.DS.$name;
				}else{
					$path = JPATH_PLUGINS .DS.'hikashoppayment'.DS.$method->payment_type.DS.$name;
				}
				if(!file_exists($path)){
					return true;
				}
			}
			require($path);

			return true;
		}

		function onPaymentNotification(&$statuses){
			$pluginsClass = hikashop_get('class.plugins');
		$elements = $pluginsClass->getMethods('payment','authorize');

		if(empty($elements)) return JText::_('ORDER_VALID_AFTER_PAYMENT');

		$element = reset($elements);
		global $Itemid;
		$url_itemid='';
		if(!empty($Itemid)){
			$url_itemid='&Itemid='.$Itemid;
		}
		$return_url =  HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id='.@$order->order_id.$url_itemid;
		$vars = array();
		$data = array();
		$filter = JFilterInput::getInstance();
		foreach($_REQUEST as $key => $value){
			$key = $filter->clean($key);
			$value = JRequest::getString($key);
			$vars[$key]=$value;
		}
		$app =& JFactory::getApplication();
		if($element->payment_params->debug){
			echo print_r($vars,true)."\n\n\n";
		}
		if(@$element->payment_params->api=='dpm' && @$_GET['iframe']){
			$vars = unserialize(base64_decode($vars['iframe']));
			$method =& $element;
			if(!HIKASHOP_J30)
				JHTML::_('behavior.mootools');
			else
				JHTML::_('behavior.framework');
			$name = $element->payment_type.'_end.php';
		}else{
			$name = $element->payment_type.'_thankyou.php';
		}
			$path = JPATH_THEMES.DS.$app->getTemplate().DS.'hikashoppayment'.DS.$name;
			if(!file_exists($path)){
				if(version_compare(JVERSION,'1.6','<')){
					$path = JPATH_PLUGINS .DS.'hikashoppayment'.DS.$name;
				}else{
					$path = JPATH_PLUGINS .DS.'hikashoppayment'.DS.$element->payment_type.DS.$name;
				}
				if(!file_exists($path)){
				}
			}
			ob_start();
			require($path);

			$msg = ob_get_clean();
			if(@$element->payment_params->api=='dpm'&&@$_GET['iframe']){
				echo $msg;
				ob_start();
				return;
			}
		if(!$element->payment_params->notification){
			echo 'Notification not activated for authorize.net';
			return $msg;
		}

			$vars['x_MD5_Hash_calculated']=$this->md5Hash(@$element->payment_params->md5_hash,@$element->payment_params->login_id,@$vars['x_trans_id'],@$vars['x_amount']);

		if($element->payment_params->debug){
			echo print_r($vars,true)."\n\n\n";
		}
		$orderClass = hikashop_get('class.order');
		$dbOrder = $orderClass->get((int)@$vars['x_po_num']);
		$order = new stdClass();
		$order->order_id = @$dbOrder->order_id;
		if(!empty($dbOrder)){
			$order->old_status->order_status=$dbOrder->order_status;
			$url = HIKASHOP_LIVE.'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id='.$order->order_id;
			$order_text = "\r\n".JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE',$dbOrder->order_number,HIKASHOP_LIVE);
			$order_text .= "\r\n".str_replace('<br/>',"\r\n",JText::sprintf('ACCESS_ORDER_WITH_LINK',$url));
		}else{
			echo "Could not load any order for your notification ".@$vars['x_po_num'];
			return $msg;
		}

		if($element->payment_params->debug){
			echo print_r($dbOrder,true)."\n\n\n";
		}
		$mailer = JFactory::getMailer();
		$config =& hikashop_config();
		$sender = array(
				$config->get('from_email'),
				$config->get('from_name') );
		$mailer->setSender($sender);
		$mailer->addRecipient(explode(',',$config->get('payment_notification_email')));


			if (@$vars['x_MD5_Hash']!=$vars['x_MD5_Hash_calculated']) {
				$mailer->setSubject(JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER','Authorize.net').'invalid response');
			$body = JText::sprintf("Hello,\r\n An Authorize.net notification was refused because the response from the Authorize.net server was invalid. The hash received was ".$vars['x_MD5_Hash']." while the calculated hash was ".$vars['x_MD5_Hash_calculated'].". Please cehck that you're set the same md5 hash key in Authorize.net and the plugin")."\r\n\r\n".$order_text;
			$mailer->setBody($body);
			$mailer->Send();
			if($element->payment_params->debug){
				echo 'invalid md5'."\n\n\n";

			}
				return $msg;
			}
			$vars['x_response_code']=(int)@$vars['x_response_code'];

		if(!in_array($vars['x_response_code'],array(1,4))) {
			if($vars['x_response_code']==2){
				$vars['payment_status']='Declined';
			}else{
				$vars['payment_status']='Error';
			}
			$body = str_replace('<br/>',"\r\n",JText::sprintf('PAYMENT_NOTIFICATION_STATUS','Authorize.net',$vars['payment_status'])).' '.JText::_('STATUS_NOT_CHANGED')."\r\n\r\n".$order_text;
		 	$mailer->setSubject(JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER','Authorize.net',$vars['payment_status'],$dbOrder->order_number));
			$mailer->setBody($body);
			$mailer->Send();
			if($element->payment_params->debug){
				echo 'payment with code '.@$vars['x_response_code'].' : '.@$vars['x_response_reason_text']."\n\n\n";
			}
			return $msg;
		 }


		$order->history->history_reason=JText::sprintf('AUTOMATIC_PAYMENT_NOTIFICATION');
		$order->history->history_notified=0;
		$order->history->history_amount=@$vars['x_amount'].'USD';
		$order->history->history_payment_id = $element->payment_id;
		$order->history->history_payment_method =$element->payment_type;
		$order->history->history_data = ob_get_clean();
		$order->history->history_type = 'payment';

	 	$price_check = round($dbOrder->order_full_price, 2 );
	 	if($price_check != @$vars['x_amount']){
	 		$order->order_status = $element->payment_params->invalid_status;
	 		$orderClass->save($order);
	 		$mailer->setSubject(JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER','Authorize.net').JText::_('INVALID_AMOUNT'));
			$body = str_replace('<br/>',"\r\n",JText::sprintf('AMOUNT_RECEIVED_DIFFERENT_FROM_ORDER','Authorize.net',$order->history->history_amount,$price_check.'USD'))."\r\n\r\n".$order_text;
			$mailer->setBody($body);
			$mailer->Send();
	 		return $msg;
	 	}

	 	if($vars['x_response_code']==1){
	 		$order->order_status = $element->payment_params->verified_status;
	 		$vars['payment_status']='Accepted';
	 	}else{
	 		$order->order_status = $element->payment_params->pending_status;
	 		$order_text =@$vars['x_response_reason_text']."\r\n\r\n".$order_text;
	 		$vars['payment_status']='Pending';
	 	}

	 	$config =& hikashop_config();
		if($config->get('order_confirmed_status','confirmed')==$order->order_status){
			$order->history->history_notified=1;
		}

	 	$mailer->setSubject(JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER','Authorize.net',$vars['payment_status'],$dbOrder->order_number));
		$body = str_replace('<br/>',"\r\n",JText::sprintf('PAYMENT_NOTIFICATION_STATUS','Authorize.net',$vars['payment_status'])).' '.JText::sprintf('ORDER_STATUS_CHANGED',$statuses[$order->order_status])."\r\n\r\n".$order_text;
		$mailer->setBody($body);
		$mailer->Send();
	 	$orderClass->save($order);

			return $msg;
		}

		function onPaymentConfiguration(&$element){
			$subtask = JRequest::getCmd('subtask','');
			$this->authorize = JRequest::getCmd('name','authorize');
		if(empty($element)){
			$element = new stdClass();
				$element->payment_name='Authorize';
				$element->payment_description='You can pay by credit card using this payment method';
				$element->payment_images='MasterCard,VISA,Credit_card,American_Express';
				$element->payment_type=$this->authorize;
				$element->payment_params=new stdClass();
				$element->payment_params->url='https://secure.authorize.net/gateway/transact.dll';
				$element->payment_params->api='sim';
				$element->payment_params->invalid_status='cancelled';
				$element->payment_params->pending_status='created';
				$element->payment_params->verified_status='confirmed';
				$element = array($element);
			}
		$this->toolbar = array(
			'save',
			'apply',
			'cancel',
			'|',
			array('name' => 'pophelp', 'target' =>'payment-authorize-form')
		);

		hikashop_setTitle('Authorize','plugin','plugins&plugin_type=payment&task=edit&name='.$this->authorize);
		$app = JFactory::getApplication();
		$app->setUserState( HIKASHOP_COMPONENT.'.payment_plugin_type', $this->authorize);
		$this->address = hikashop_get('type.address');
		$this->category = hikashop_get('type.categorysub');
		$this->category->type = 'status';
		}

		function onPaymentConfigurationSave(&$element){
		return true;
		}



	function md5Hash($md5Hash, $login_id, $trans_id, $amount) {
		if ($amount == '' || $amount == '0'){
			$amount = '0.00';
		}
		return strtoupper(md5($md5Hash.$login_id.$trans_id.$amount));
	}
}

if(!function_exists('hash_hmac')){
	function hash_hmac($algo, $data, $key, $raw_output = false){
		$algo = strtolower($algo);
		$pack = 'H'.strlen($algo('test'));
		$size = 64;
		$opad = str_repeat(chr(0x5C), $size);
		$ipad = str_repeat(chr(0x36), $size);

		if (strlen($key) > $size) {
			$key = str_pad(pack($pack, $algo($key)), $size, chr(0x00));
		} else {
			$key = str_pad($key, $size, chr(0x00));
		}

		for ($i = 0; $i < strlen($key) - 1; $i++) {
			$opad[$i] = $opad[$i] ^ $key[$i];
			$ipad[$i] = $ipad[$i] ^ $key[$i];
		}

		$output = $algo($opad.pack($pack, $algo($ipad.$data)));

		return ($raw_output) ? pack($pack, $output) : $output;
	}
}

authorize_configuration.php file:
No modifications were made to this file. I figured that I would hardcode any parameters I wanted into the authorize.php file.


authorize_end.php
Nothing to really change in this file. This file seems to just gather the fields and values and sends it off to the authorize.net/PnP emulator.

authorize_thankyou.php
No changes made to this file. I made my changes to checkout/after_end.php file for my ending displays.

I figure my next step is to add the code that will get the currency from HikaShop and then define "x_currency_code" with the currency.

I know I'll need to add this code to a conditional statement
if ($currency == "JMD"){
  $vars["x_currency_code"] = 'JMD';
}else{
  $vars["x_currency_code"] = 'USD';
}

How would I get the plugin to grab the currency from HikaShop?

Like you said, maybe the PnP emulator only accept USD from the authorize plugin, but it's worth a try. The only alternative would be to write a proper plugin for PnP and I'll need a lot more help with this.

Any input will be appreciated and thank you in advanced.

Last edit: 11 years 11 months ago by trueblue.

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 10
11 years 11 months ago #89311

Can someone tell me please if I'm on the right track with this?

Please Log in or Create an account to join the conversation.

  • Posts: 83050
  • Thank you received: 13412
  • MODERATOR
11 years 11 months ago #89568

Hi,

That's sounds worth a try yes. You can add that code to add the x_currency_code :

$currencyClass = hikashop_get('class.currency');
$currencies = null;
$currencies = $currencyClass->getCurrencies($order->order_currency_id,$currencies);
$currency = $currencies[$order->order_currency_id];
$vars["x_currency_code"] = $currency->currency_code;
Let us know how that goes and if it's ok, we could add it in the next version of the authorize.net plugin.

We actually have lot of payment plugins from which you can take example from. HikaShop ships with more than 20. So you can simply look in them to see how we did if you want to create a new one :) The files are in the folder plugins/hikashoppayment

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 10
11 years 11 months ago #89580

Thank you very much Nicolas. I will give it a try and let you know how it turns out.

Like I said before, I'm not really a coder, but I do plan on giving a proper plugin for Plug 'n Pay a try, but after I'm done with this project. I know I will need help, but if it works well I will be happy to share with the HikaShop community.

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 10
11 years 11 months ago #89582

Just a quick question.

I found that this code is already there.

				$currencyClass = hikashop_get('class.currency');
				$null=null;
				$currency_id = intval(@$order->total->prices[0]->price_currency_id);
				$currency = $currencyClass->getCurrencies($currency_id,$null);
				if(!empty($currency) && @$currency[$currency_id]->currency_code != 'USD'){
					return true;
				}

Should I replace it with the one you gave me? Or just add your code below this one.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 11 months ago #89680

Hi,

I think that you can just try to add the line:

$vars["x_currency_code"] = $currency[$currency_id]->currency_code;
Before:
if(!empty($currency) && @$currency[$currency_id]->currency_code != 'USD'){
	return true;
}

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 10
11 years 10 months ago #90506

Ok.. It seems that the codes Nicolas gave worked. It allowed the plugin to work with JMD.

Here are the codes I used:

/*
// Replaced with the codes below
$currencyClass = hikashop_get('class.currency');
$null=null;
$currency_id = intval(@$order->total->prices[0]->price_currency_id);
$currency = $currencyClass->getCurrencies($currency_id,$null);
if(!empty($currency) && @$currency[$currency_id]->currency_code != 'USD'){
	return true;
}
*/
// Modified to accept JMD. This will allow the plugin to send a currency value to the gateway.
// By default it assumes USD if no currency value is sent.
$currencyClass = hikashop_get('class.currency');
$currencies = null;
$currencies = $currencyClass->getCurrencies($order->order_currency_id,$currencies);
$currency = $currencies[$order->order_currency_id];
$vars["x_currency_code"] = $currency->currency_code;

However, it can't work for me as I'm using the Authorize.net plugin for Plug 'n Pay via PnP's emulator. Authorize does not support the "Rate" value and so the emulator is not looking for it. Be default the currency is assumed to be in USD, so sending a currency value is only optional.

Anyways, now I'm going to have to create a dedicated plugin for Plug 'n Pay. And one that will work with JMD. It seems they have partnered with one of our (Jamaica) local bank, NCB to allow JMD currency. So, this plugin has to be developed with this in mind.

Like I said before is my previous posts, I'm not really a developer. In fact, I'm really just a designer. However, I do know my way around a bit and is somewhat capable of figuring out stuff. And so, I will need a lot of help with this.

I'm going to start with copying some codes from another payment plugin and then try to add the PnP data requirements to it. I will post it here for your review with the hopes that if I'm doing something wrong, someone can point it out to me.

Thank you for your help so far.

Please Log in or Create an account to join the conversation.

  • Posts: 14
  • Thank you received: 4
11 years 10 months ago #91448

Ok... I added the code to the onPaymentDisplay function:

/*
// Replaced with the codes below
$currencyClass = hikashop_get('class.currency');
$null=null;
$currency_id = intval(@$order->total->prices[0]->price_currency_id);
$currency = $currencyClass->getCurrencies($currency_id,$null);
if(!empty($currency) && @$currency[$currency_id]->currency_code != 'USD'){
	return true;
}
*/
// Modified to accept JMD. This will allow the plugin to send a currency value to the gateway.
// By default it assumes USD if no currency value is sent.
$currencyClass = hikashop_get('class.currency');
$currencies = null;
$currencies = $currencyClass->getCurrencies($order->order_currency_id,$currencies);
$currency = $currencies[$order->order_currency_id];
$vars["x_currency_code"] = $currency->currency_code;

And this allows the plugin for display when the currency is changed to JMD via the switcher. It worked fine and even sends to the emulator/payment gateway fine. The only issue now left to resolve is that it's not sending the currency attribute to the emulator/payment gateway.

I looked at the code further down the page and realize that there was another function that handled the preparation of the data for the payment gateway attributes. So, I'm thinking... I should repeat the code below somewhere in that function, right?
function _loadStandardVars(&$order,&$method){
	$tax_total = '';
	$discount_total = '';
	$currencyClass = hikashop_get('class.currency');
	$currencies=null;
	$currencies = $currencyClass->getCurrencies($order->order_currency_id,$currencies);
	$currency=$currencies[$order->order_currency_id];
	$vars["x_currency_code"] = $currency->currency_code; // To add the currency code to the vars.
        ...
}

I had to ask, because the testing for the Jamaican currency card is don't by the bank. I can test Visa card myself for USD (which is working fine), but I didn't get one for the local cc...

BTW: TrueBlue = Me :)

Please Log in or Create an account to join the conversation.

  • Posts: 14
  • Thank you received: 4
11 years 10 months ago #91483

Great news!! It worked fine!! Yay!!

Ok.. Just one last thing now. The site can now accept 3 CC brands; Visa & MasterCard for USD Only and KeyCard for JMD only. I'm thinking I need a way to ensure that Visa & MasterCard only are accepted when the site is showing USD and KeyCard only when the site is showing JMD.

Now I'm thinking that the most obvious way to do this is to duplicate the payment plugin and have set them for each of the available cards/currencies accordingly.

Is there a better way to handle this? Or duplicating the plugin is the best way?

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 10 months ago #91650

Hi,

I think that you have to duplicate the plugins.
When duplicating don't forget to rename all the instance of the plugin name in the php and xml files.

Please Log in or Create an account to join the conversation.

Time to create page: 0.120 seconds
Powered by Kunena Forum