IPN Listener

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #7986

Hi there.
I am a newbie here and would like to add my PHP script, In the listener file of the component where after the successful payment of PAYPAL, the component turns the order status to confirmed. I want to find that file and that part of code so, I can add more of my custom code there.

Will you please give me the location of the file that handles the information sent fron IPN system of PAYPAL?

By the way this component ROCKS! :lol:

Thank you very much

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #7988

Hi,

You don't need to hack hikashop for that (it's better not to, otherwise, you will have to reapply your changes each time). You can create a plugin and define the method onAfterOrderUpdate(&$order,&$send_email) following our developer documentation:
www.hikashop.com/en/support/documentatio...r-documentation.html

That way, in that method, you can just do like this:

if(@$order->order_status=='confirmed'){
// my custom code
}

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

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #7990

I am just surprised how fast a moderator can reply to a forum! I really appreciate your quick response.
Thank you very much..

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

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #8000

Thank you very much for your reply. I created the plugin for usage. Now I would like to know which information the order object can give me? Is there a list for options that I can check? (Mainly I want to use my customer email address in my custom code.)

And maybe it is irrelevant question but is there a way I can use the paypal sandbox system for testing purposes?
I saw a link given to paypal that can be changed, but I'm not sure which url I should use instead of default one.

Thank you very much.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #8001

The $order object doesn't contain much data.
If you want to load the email address of the user, you can use the code:
//first, I need to load the data of the order as it might not contain the user id
$orderClass = hikashop::get('class.order');
$orderInfos = $orderClass->get($order_id);
//then, I load the user data
$userClass = hikashop::get('class.user');
$customer = $userClass->get($orderInfos->order_user_id);
echo $customer->user_email;

The paypal sandbox URL is: www.sandbox.paypal.com/cgi-bin/webscr

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

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #8002

Thank you again...

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

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #8356

Hi there, I encountered to some problems again.
This is my case scenario:
I have two PDF files that I want to sell.
During the shopping I don't collect any information from the costumer.
After the successful payment I want to send an email to the buyer.
The email will be the same email of payer from the paypal that is get back to me through IPN system (You told me what to do for getting the email address but I couldn't manage to make it work.)
Then I will need the code number of products the buyer purchased to know which product link I should send to customer.
(If the customer buys both of PDFs I should send him/her two links, so maybe there are more than one product code needed to handle).
Also I should get the payment ID from paypal to show on my Thank you page. I don't know what code I should use in my thank you page for showing the payment ID.

Will you please help me on this matter?

Thank you very much.

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

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #8372

Hi there, I encountered to some problems again.
This is my case scenario:
I have two PDF files that I want to sell.
During the shopping I don't collect any information from the costumer.
After the successful payment I want to send an email to the buyer.
The email will be the same email of payer from the paypal that is get back to me through IPN system (You told me what to do for getting the email address but I couldn't manage to make it work.)
Then I will need the code number of products the buyer purchased to know which product link I should send to customer.
(If the customer buys both of PDFs I should send him/her two links, so maybe there are more than one product code needed to handle).
Also I should get the payment ID from paypal to show on my Thank you page. I don't know what code I should use in my thank you page for showing the payment ID.

Will you please help me on this matter?

Thank you very much.

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

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #8381

Hi there. I have found the ipn post variables.
I want to know how can I get the given information of the ipn for next usage.
I tested the IPN with my settings and got some information.
Now I want to access that information like:
item_number1= (the product ID)
item_number1= (the product ID)
payer_email= (this is so important for me cuz I dont have any othe contact information from my customer except this)

As you said I can make a plugin to handle but how can I access the information above in my plugin?

Thank you very much and waiting for your reply

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #8382

Hi,

On the thank you page the payment might not be validated by PayPal so it doesn't return any information to HikaShop which would enable you to display the payment ID. That information is sent with IPN to HikaShop on a different communication channel later on and securily. And it's at that point that the onAfterOrderUpdate function is triggered by HikaShop. You say that you couldn't make work the code I gave you. Maybe it's because you thought that it would display something on the thank you page where in fact it's not called at that point ?

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

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #8383

yea I made a mistake about the thank you page.
I want the information of the IPN available for me at onAfterOrderUpdate in my plugin.
information such as payer_email , mc_gross , ....
How can I access them on my plugin?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #8384

You should be able to read it directly in the $_REQUEST variable.
Like this: $price = $_REQUEST;

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

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #8386

THATS THE POINT! THAAAAAAAAAAAAAAAAAAAAAANK YOU! I think most of developers would want this. I am ready to help documenting the procedure to be added at documentation section. are there any interests? I am really getting into Hikashop and really want to do something to benefit this system, It saved a huge amount of time for me!

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #8389

If you write the procedure, we can of course add it to our documentation. I'm sure that Other developers would benefit from it.

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

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #8452

Thank you for your guidance.
I am getting closer to achieve the results.
I coded the plugin. and now my code should work after the order is confirmed.
I post the code I wrote using your help. Unfortunately the event does not trigger on confirmed order.
Will you please check where did I mistake?

<?php
defined('_JEXEC') or die('Restricted access');
?>

<?php
class plgChristopher extends JPlugin
{
function plgChristopher(&$subject, $config){
parent::__construct($subject, $config);
if(!isset($this->params)){
$plugin =& JPluginHelper::getPlugin('hikashop', 'christopher');
jimport('joomla.html.parameter');
$this->params = new JParameter( $plugin->params );
}
}
function onAfterOrderUpdate(&$order,&$send_email){
if(@$order->order_status=='confirmed'){
$customerEmail = $_REQUEST;
$to = $customerEmail;
$from = "This email address is being protected from spambots. You need JavaScript enabled to view it.";
$subject = "Your payment has been verified";
$message = "This is a test";
mail($to, $subject, $message);
}
}
}
?>

As you see I used the same coding rules of the history plugin. The plugin installed ok.
I want to send a simple email after the payment, using the email address I get from the IPN answer.
I followed your instructions and still have problem.
The event does not trigger.

Would be thankful to help me in this matter.

Thank you very much


?>

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #8459

How do you know that the event does not work ? :)
Because the email is not sent ? In that case, you should try to use the joomla emailing functions and not the php mail function. That way, the system will use the standard joomla mail sending configuration :

$mailer =& JFactory::getMailer();
$config =& hikashop::config();
$sender = array(
$config->get('from_email'),
$config->get('from_name') );
$mailer->setSender($sender);
$mailer->addRecipient(array($customerEmail));
$mailer->setSubject("Your payment has been verified");
$mailer->setBody("This is a test");
$mailer->Send();

Also, you need to have your plugin published in the joomla plugin manager. Is that the case ?

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

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #8464

First of all thank you for your reply.
Yes I always publish the plugin before I use.
I tested the code and it works when I code it directly to joomla article using Jumi.
But it does not send email when it is coded in plugin.(I used the same code)

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

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #8467

How can I test that the event is triggering? Is there any way ?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #8475

You should try to write in a file:
jimport('joomla.filesystem.file');
JFile::write(HKASHOP_ROOT.'mylogfile.txt','event is triggered');

Then, you will be able to access that log file in your website's root folder via FTP. Also, make sure that this file is writable.

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

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #8487

Oh I see. a great trick for loggin' so if I go and change one order status manually from the administrator section it should trigger the event I think.

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

Time to create page: 0.092 seconds
Powered by Kunena Forum