Curl & onPaymentNotification()

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #22347

Hello nicolas.

I must know a thing before i can continue programming with Hikashop, I am trying to get onPaymentNotification() to run when i call cURL like this:

$ch = curl_init(' www.4u2.co.il/index.php ');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS ,$params);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0); // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0;Windows NT 5.1)");
$result=curl_exec($ch);

note that $params are the paramters "notif_payment=banktransfer&option=com_hikashop&ctrl=checkout&task=notify&tmpl=component&lang=he" and some more parameter from the creditcard company.

Can the function work this way? I have tried few things and i can seem to run the function with this script..

Thanks in advance.

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 3 months ago #22349

$params should be appended to the URL like that so that they are in the $_GET and not in the $_POST :
$ch = curl_init(' www.4u2.co.il/index.php?'.$params );
Joomla probably doesn't like to not have anything in the $_GET...

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 3 months ago #22350

Otherwise, yes, it's totally possible to do what you're trying to do.

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

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #22361

great! but I changed the code as you said:

$ch = curl_init(' www.4u2.co.il/index.php ?' . $params);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0); // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0;Windows NT 5.1)");
$result=curl_exec($ch);

When I run the file in the browser the function is called, but through the checkout the function is not working, i checked farther and the file is executed after the checkout, but somehow the function is not called there.
What may be the cause of that?

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 3 months ago #22363

The checkout of HikaShop does not call the function onPaymentNotification. That function is called when someone access the URL index.php?notif_payment=banktransfer&option=com_hikashop&ctrl=checkout&task=notify&tmpl=component&lang=he
So you're saying that at one point, you have some trace that the curl code was called but that the function was not called.
If it works when you access with the browser the file of your curl code, it should work when that file is called automatically.

I don't know what could be the cause, but you could look at the log file of your apache to see if you get the curl request. If not, it means that the problem is either the curl code, or the connection which cannot be established. If yes, it means that the problem is before the onpaymentnotification function, maybe something from joomla interfering, like SEF ?

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

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #22409

The only errors I can see coming up all the time are:

(1).

[01-Aug-2011 11:53:56] PHP Warning: include(/home/ucoil/public_html/components/com_hikashop/controllers/index.php.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /home/ucoil/public_html/components/com_hikashop/hikashop.php on line 43
[01-Aug-2011 11:53:56] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening '/home/ucoil/public_html/components/com_hikashop/controllers/index.php.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ucoil/public_html/components/com_hikashop/hikashop.php on line 43

(2).

[01-Aug-2011 11:58:59] PHP Warning: include(/home/ucoil/public_html/components/com_hikashop/controllers/calander.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /home/ucoil/public_html/components/com_hikashop/hikashop.php on line 43
[01-Aug-2011 11:58:59] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening '/home/ucoil/public_html/components/com_hikashop/controllers/calander.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ucoil/public_html/components/com_hikashop/hikashop.php on line 43

I think the first one is coming before checkouts and the 2nd one is coming when completing the checkout.
I cannot seem to find what is that 2nd error..

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 3 months ago #22411

I was thinking of the apache access log, not the php error log ( these error messages comes from it ).
These errors means that there is a request with the parameters: option=com_hikashop&ctrl=calander or option=com_hikashop&ctrl=index.php but that's not possible since these controllers do not exist.

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

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #22421

Oh, sorry.. I found this:

[01/Aug/2011:12:44:04 +0300] "GET /external/cardcom_request.php?notif_payment=banktransfer&option=com_hikashop&ctrl=checkout&task=notify&tmpl=component&lang=he&terminalnumber=1000&lowprofilecode=bed017bd-b13a-4a6d-82db-f115a2d1378f&Operation=2&ProssesEndOK=0&DealRespone=0&InternalDealNumber=849036&TokenResponse=0&Token=cc1da2b2-ca01-4053-b851-061c88316409&TokenExDate=19900101&CardValidityYear=2016&CardValidityMonth=1&CardOwnerID=2532546456&InvoiceResponseCode=0&InvoiceNumber=1886&InvoiceType=1 HTTP/1.1" 200 658 "-" "-"

This is the page that runs the cURL to run the function with index.php?... (The page takes the parameters and cURL to index.php). As far as I know the 200 error is successful status code
and i think this is the cURL call:

[01/Aug/2011:12:44:04 +0300] "GET /index.php?notif_payment=banktransfer&option=com_hikashop&ctrl=checkout&task=notify&tmpl=component&lang=he&terminalnumber=1000&lowprofilecode=bed017bd-b13a-4a6d-82db-f115a2d1378f&Operation=2&ProssesEndOK=0&DealRespone=0&InternalDealNumber=849036&TokenResponse=0&Token=cc1da2b2-ca01-4053-b851-061c88316409&TokenExDate=19900101&CardValidityYear=2016&CardValidityMonth=1&CardOwnerID=2532546456&InvoiceResponseCode=0&InvoiceNumber=1886&InvoiceType=1 HTTP/1.1" 200 611 "-" "Mozilla/4.0 (compatible; MSIE 6.0;Windows NT 5.1)"

The only 404 i can see is:

[01/Aug/2011:12:41:33 +0300] "GET /en/index.php HTTP/1.1" 404 1417 " www.4u2.co.il/en/?ie= " "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 BTRS26718 Firefox/3.6.12"

but i dont think it's any harm.
Any ideas?

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 3 months ago #22429

If I run the URL:
www.4u2.co.il/index.php?notif_payment=ba...17bd-b13a-4a6d-82db- f115a2d1378f&Operation=2&ProssesEndOK=0&DealRespone=0&InternalDealNumber=849036&TokenResponse=0&Token=cc1da2b2-ca01-4053-b851- 061c88316409&TokenExDate=19900101&CardValidityYear=2016&CardValidityMonth=1&CardOwnerID=2532546456&InvoiceResponseCode=0&InvoiceNumber=1886&InvoiceType=1

in my browser, I don't get a 200 response. Instead, I get a 303 redirect response to:
www.4u2.co.il/he/?notif_payment=banktran...17bd-b13a-4a6d-82db- f115a2d1378f&Operation=2&ProssesEndOK=0&DealRespone=0&InternalDealNumber=849036&TokenResponse=0&Token=cc1da2b2-ca01-4053-b851- 061c88316409&TokenExDate=19900101&CardValidityYear=2016&CardValidityMonth=1&CardOwnerID=2532546456&InvoiceResponseCode=0&InvoiceNumber=1886&InvoiceType=1
which then gives a 200.

That's because of the SEF redirect of Joomla. And since your code probably don't handle the 303 response from the server, it just does not do anything.
The solution is to use the second URL in your code and not the first one. That way, you won't have the redirect response and your request will be processed by your onPaymentNotification function.

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

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #22433

Awesome! Finally it works!

Thank you so much!

Although i found a weird thing going on... after checkout complete Hikashop creates another empty order (sum = 0, no user and so on)

What causes Hikashop to create another order? ( i checked and onPaymentNotification() and onAfterOrderConfirm() only run once per order)

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 3 months ago #22435

HikaShop does not create 2 orders. It creates only one. I'm guessing that you maybe have some code which save the order without the order_id set in the object or something like that in your code?

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

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #22439

Thanks again!

Hikashop Order id came up wrong.

Thanks for everything, works flawlessly :)

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

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #22455

Hey again, i am trying to get the user class (Hikashop logged in user) at the onPaymentNotification() function (to save a in field something from the creditcard company).

it suppose to be something like that i think, but im not sure:

$userClass = hikashop_get('class.user');
$dbUser = $userClass->get(USER_ID);


is this thing will work, or is it done differently?

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 3 months ago #22456

Yes. That's ok.

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

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #22457

Great! so how can i get the user id from the order?

I tried $dbOrder->user_id but it didnt work..

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 3 months ago #22458

The variable is called order_user_id

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

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #22463

good thats working, but i cant reach the custom fields i created.
I tried using the $dbUser->user_params->CUSTOM_FIELD but that failed..

Any other way to call custom fields?
And is there a way i can see the non custom fields name so i wont be asking silly questions?

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 3 months ago #22473

You should be able to do that with $dbUser->CUSTOM_FIELD if you created custom fields of the table "user". However, you probably created custom fields of the table "address" which are in the address table, not in the user table.
So you need to load one of the addresses (a user can have several addresses) of the user from the address table. So you will have to make the query yourself.

Each custom field created will correspond to a new column on the corresponding table. If you created custom fields of the table address, you should see them in the address table structure.

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

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #22529

Yeah i know the understand the format, but i need this once per user so i created it at the user table.
I forgot the user didnt had value at the custom field so it came out empty. Thanks its working now :)

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

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #22534

Ok i found out another thing i cant figure out..

At one payment method i cant have the cart emptied at the end of the proccess (i need to empty the cart at the notification maybe), although not all payment must go to notification. i need 2 things:

1. Can i have the empty cart function for each payment method at onAfterOrderConfirm() or at onPaymentNotification()? (or do you have a better solution?)
2. Where is the cart been emptied now?

Thanks in advance.

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

Time to create page: 0.093 seconds
Powered by Kunena Forum