Buy Now
Sign in

FAQ search

How to use the PayPal Redirect Action

Published: Tuesday, 30 November 1999 00:00

Many users contact me asking how to use the "PayPal Redirect" along with the "IPN" response feature, here is how in brief:

Note: this FAQ talks about the PayPal ReDirect action - the PayPal Pro action is similar though you need to add more entries than are shown here. 

I will assume that you have already created your form using the wizard or your own HTML code, in order to use the "PayPal Redirect", you will need to pass 2 fields values at least, the "Item Name" and the "Amount", I will assume that your item field name is "item" and the amount field name is "amount".

First drag a "PayPal Redirect" action to the "on Submit" event of your form as shown:

Next, click the configuration icon and enter the 2 basic fields names mentioned above as shown below:

Then go to the next tab and enter your PayPal's business email address:

Save, then add a new event to your form and name it "ipn", then drag a "PayPal Listener" action inside:

You should drag any actions which you need to process when the payment is verified inside the "On Verified" event, for example, I'm going to send an email and save some data into the database when PayPal sends a payment successful confirmation.

Now you need to enable the IPN in your PayPal account settings.

You should setup a "Notify URL" tso that PayPal can connect to the new form event you have created. The Notify URL should be like this:

If this is the only form that will connect to PayPal you can add the URL in your PayPal account settings. If you want to use more than one form then you should set it 'dynamically' in the form. To do this add a Custom Code action in the On Submit event before the PayPal ReDirect action and add code like this to it:

$form->data['notify_url'] = '';

Then, in the Extra Params box of the PayPal ReDirect action add 


Note: You should NOT add this notify url in the "return url" of the "PayPal Redirect" action, the IPN event is setup to run in the background by a call from PayPal, not using the user's browser.

Checking the PayPal Listener action

In order to make sure that PayPal IPN is working, please add an Email action (and configure it) as the first action in the IPN event - before the PayPal Listener action, if you receive this email after the purchase then the IPN is working.

You can check the data being passed by adding code like this to the Email template:

echo'<div>$_POST: '.print_r($_POST, true).'</div>';
You can add other things as well but that should dump into the email all of the data being returned from PayPal in the IPN request.
To test different conditions you can call the IPN URL directly from the IPN Simulator in a PayPal Developer account.
I believe that there may be a bug in the PayPal Listener that doesn’t correctly identify successful transactions from PayPal. You can test this by leaving all the PayPal Listener boxes empty and adding an email after the PayPal Listener with code like this to dump all of the form variables.
echo'<div>$form->data: '.print_r($form->data, true).'</div>';
Once you are sure that the PayPal Listener is working you can place two different emails, one in the "on verified" event and the other in the "invalid" event, this should tell you if you are receiving the response expected or not.

Passing data to the PayPal Listener

In some situations, users may need to pass some form data to the ipn event, you can do this by saving the data to DB (using a DB Save action) before the "PayPal Redirect" action then re-loading it later, but in order to load it later you will need the data record id, for this to work, just use this in the "Extra params" field in PayPal redirect: custom=chronoform_data_cf_id I have assumed that your data table is created using Chronoforms and the primary key is "cf_id" (double check that!!), and that the "DB Save" had the default model, hence the "chronoform_data", later under the "PayPal listener" "on verified" event, you should have a "DB Record loader" action, with the "Request param" setting set to "custom", that should load the stored record and make it ready for use in your Email for example.

If you however want to update the original record, then you can use a "DB Save" action instead of the "DB record loader", but you will need to add a "Custom code" action BEFORE it with this code (insert between PHP tags):

$form->data["cf_id"] = $form->data["custom"];
$form->data["field_to_update"] = "updated!";

It should work fine now, but you should purchase the "PayPal plugin" from our subscriptions page in order to be able to use it for live transactions as the trial version randomises the amount.