Need some help with a payment plugin.

  • Posts: 182
  • Thank you received: 15
12 years 1 month ago #65927

I am at the moment working on a payment plugin for one of the Swedish payment services, named Nets ePayment formerly known as Auriga.

They send back a response url with some parameters and I have some problems on how to pick them up.

I guess this line is the start of the code handling this in the "onPaymentNotification" function:

$url = parse_url($element->payment_params->url);


I need advise on where to put in the parameters I get in the returning URL.

They are as follows:

Merchant_id=_HIDDEN_&
Version=3&
Customer_refno=B5A4W8&
Status=A&
Status_code=0&
Currency=SEK&
MAC=_HIDDEN_


Customer_refno is the Hikashop $order->order_number

Status and Status_code are especially important since they show if the payment were successful or not.


This payment plugin will with a few tweaks also work for a few other Swedish payment services like Payson. When I am done with this I will make a Payson variant, I will share both to the Hikashop team.


Thanks


Jan

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 1 month ago #65929

The line
$url = parse_url($element->payment_params->url);
will give you the parameters of the URL you configured in the plugin.
If you want the parameters returned by the payment gateway, they are all in the variable $_REQUEST.

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

  • Posts: 182
  • Thank you received: 15
12 years 1 month ago #65931

Nicolas, thanks for a quick reply.

So they will be in the array of $url then?

I have debug on but the log is empty, what can I do to get entries in to the log?


Thanks


Jan

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 1 month ago #65932

Just turning on the debug option is not enough. You need to echo what you want to see so that it appears in the log.
If you look at all the other plugins, they echo variables and text when you turn on the debug mode.

Where is $url coming from ? I'm talking about the variable $_REQUEST which is where you will have to parameters.

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

  • Posts: 182
  • Thank you received: 15
12 years 1 month ago #66011

I'm sorry but I am not that experienced in PHP but I am learning along the way.
The $url I was refering to was from $url = parse_url($element->payment_params->url);


So If I have this line in the PaymentParams the return URL will be parsed?

$element->payment_params->url=$this->return_url;

is the codeline correct?

return_url will be:
$return_url = HIKASHOP_LIVE.'index.php?option=com_hikashop%26ctrl=checkout%26task=after_end%26order_id='.$order->order_id.$url_itemid;



Thanks

Jan

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 1 month ago #66012

Mmm.
In the notification function you don't need to deal with the return URL.
All you need to do is to get the parameters your payment gateway is sending you in the $_REQUEST array variable.

I don't understand why you keep trying to parse the return URL in the notification function ?

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

  • Posts: 182
  • Thank you received: 15
12 years 1 month ago #66017

nicolas wrote: Mmm.

I don't understand why you keep trying to parse the return URL in the notification function ?


I don't understand either :lol:

I am trying to do this on a trial and error basis...

What I need to do is based on the two keys "Status" and "Status_code" (from the payment service) that is returned set the order status to confirmed or cancelled.

In the PayPal plugin I found this in the notification function:
$vars = array();
		$data = array();
		$filter = & JFilterInput::getInstance();
		foreach($_REQUEST as $key => $value){
			$key = $filter->clean($key);
			if(preg_match("#^[0-9a-z_-]{1,30}$#i",$key)&&!preg_match("#^cmd$#i",$key)){
				$value = JRequest::getString($key);
				$vars[$key]=$value;
				$data[]=$key.'='.urlencode($value);
			}
		}

That part will create the $_REQUEST variable, right?

Jan

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

  • Posts: 182
  • Thank you received: 15
12 years 1 month ago #66023

Some slow progress :)

This is returned from the var_dump of $_REQUEST

array(30) { ["option"]=> string(12) "com_hikashop" ["ctrl"]=> string(8) "checkout" ["task"]=> string(9) "after_end" ["order_id"]=> string(3) "540" ["Merchant_id"]=> string(4) "_HIDDEN_" ["Version"]=> string(1) "3" ["Customer_refno"]=> string(6) "B5A4M0" ["Status"]=> string(1) "E" ["Status_code"]=> string(1) "3" ["Payment_method"]=> string(8) "KORTINSE" ["Currency"]=> string(3) "SEK" ["MAC"]=> string(32) "_HIDDEN_" _REMOVED SOME COOKIES AND SESSION STUFF_ ["Itemid"]=> NULL ["hikashop_front_end_main"]=> int(1) ["view"]=> string(8) "checkout" ["layout"]=> string(9) "after_end" }


Jan

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 1 month ago #66030

The variables are in $_REQUEST as I said.
So it's really easy to get them:
echo $_REQUEST;

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

  • Posts: 182
  • Thank you received: 15
12 years 1 month ago #66032

Yes I got that.

I have been looking thru the PayPal.php, the onPaymentNotification is used in its entirety and I have trouble to find where I should enter the statuses to switch between successful order or cancelled order.

In the VM plugin they have this line:

if (($Status == "A") AND ($Status_code == 0))

Then the order would be successful else cancelled.

Can you have some more patience with me, please...


Thanks


Jan

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 1 month ago #66035

It's simple really:

if( $_REQUEST['Status']=='A' AND $_REQUEST['Status_code']=='0'){
$orderClass = hikashop_get('class.order');
$order = null;
$order->order_id = (int)@$_REQUEST['order_id'];
$order->order_status = 'confirmed';
$orderClass->save($order);
}

Last edit: 12 years 1 month ago by nicolas.

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

  • Posts: 182
  • Thank you received: 15
12 years 1 month ago #66038

nicolas wrote: It's simple really:


Easy for you to say :lol:

Thanks a lot, I'll try it soon.


Hope to get this working, I think it would be great for Hikashop for the Swedish market. It's a unfortunatelly for Hikashop that there are so few payment modules for us here in Sweden.

Only option is VM and that is not an option anymore IMHO


Thanks again

Jan

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

  • Posts: 182
  • Thank you received: 15
12 years 1 month ago #66074

I have a question regarding the Order status.

Since this is a Swedish site the Order statuses names have been changed to the equivalent Swedish names. Does this affect the coding? Or is it using the Order Status ID?

For example "Cancelled" is changed to "Avbeställd".


Thanks

Jan

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 1 month ago #66077

The order status should always be in english, and thus stored in the database in english. They are translated automatically thanks to the translation file which already contains their translation.

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

  • Posts: 182
  • Thank you received: 15
12 years 1 month ago #66082

Thanks, just what I suspected.

However the import from VM apparently fouls that up.

And if you add some other statuses, should they also be in English and translated in the Language file?


Jan

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 1 month ago #66090

You can add statuses in your language, that's not a problem.
But the default statuses are in english in the database and should be left like that.

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

  • Posts: 182
  • Thank you received: 15
12 years 1 month ago #66098

I'm starting to get close now.

What is triggering the notification function? Is it the notify_url ?

The payment service I am working on only send back a Cancel_url and a Return_url.

I still have a problem with the payment service, I'm not getting the parameters approved all though everything is as the example they provide. I'm waiting for them to response on that.

Since I'm not getting thru to the payment service I'm expecting a cancellation when I'm making the order it's being processed but with a status of None. I would expect a status of cancelled.

I have added this to the If statement you earlier did provide, i.e when Status is not A.

else
			{
			$orderClass = hikashop_get('class.order');
			$order = null;
			$order->order_id = (int)@$_REQUEST['order_id'];
			$order->order_status = 'cancelled';
			$orderClass->save($order);


Jan

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 1 month ago #66358

The notification URL is triggered by the payment gateway when the payment is done.
In order to know the URL, you either have to give the URL to the payment gateway via a parameter in the form which is displayed at the end of the checkout, or configure it in the settings of your account in your payment gateway (it depends on how they handle it).

Sometimes, like with authorize.net, they use the return URL to directly notify the shopping cart while redirecting the user back to the shop. So in such case, you should give the notification URL in the return URL variable of the form at the end of the checkout.

Since I don't know how that payment gateway works I can't say if that's the case though, but it should be explained in their documentation.

By default the orders are created with the status "created" (if you selected that order status in the configuration for new orders).
Then, with the code I provided and your addition, it will set the status to cancelled or confirmed when a notification is received.
If you have another status, all I can think of is that you changed the new order status of the configuration and that you are not getting the notification, or that you got the notification and that you have some other code in the notification function which changes the status to none.

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

  • Posts: 182
  • Thank you received: 15
12 years 1 month ago #66362

Thanks, I'll take a look at it.

The default settings for orderstatus was not the correct one, again something from the VM import. So now I at least get the status Created for the order.

This is the return_url I get from the gateway:

http://meradog.colorconsult.se/index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id=511&Merchant_id=_HIDDEN_&Version=3&Customer_refno=511&Status=E&Status_code=4&Currency=SEK&MAC=_HIDDEN_

It directs me to the After_end page, and so it does, but page is blank. It catches the Status_code and Status all right.

Would you like to see the notification code I have?

Jan

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 1 month ago #66363

The you should change the return url so that it goes to the notification URL and at the end of the notification function of the plugin, you can redirect the user to the return url.

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

Time to create page: 0.088 seconds
Powered by Kunena Forum