RSForm and Conflicts with Paypal IPN

We have lately developed a solution for one of our clients, whereby if one customer purchases anything from his (our client’s) Joomla website using PayPal, a new Joomla account for that person is automatically created based on the person’s name and email address entered in PayPal. Additionally, the person receives a notification email (to his PayPal email address) containing his username and password to our client’s website. If the person already exists in the jos_users table, then what we do is just re-send a reminder email including the person’s credentials. We have accomplished this task by creating the user creation and email sending script inside a file called paypal.php, and by setting PayPal’s IPN (Instant Payment Notification) listener (in our client’s PayPal account) to that file. By doing the latter, every payment that is made towards our client’s account will automatically call the paypal.php file. (Check this link on PayPal if you want to know how to set the PayPal IPN).

Everything worked like a charm, but, after a while, our client came back to us and told us that some of the payments were not creating new users. Strange, we thought. We re-tested the script and everything seemed OK. We called back our client, and then he gave us the link of the page where the payments were not creating new users. It was a page containing an RSForm that had PayPal integration. We made a test payment there and to our surprise, the paypal.php file was not called.

The first thing we checked was if the payments were going to the same account, we checked this by logging in to his Joomla website’s backend, and then by going to Components->RSForm Pro! and then by clicking on Configuration in the tabbed menu, and then by clicking on PayPal in the sub-menu. The email was different (which meant it was a different account), so we informed the client, and so the client also updated the IPN listener for that PayPal account to paypal.php. We thought that the problem would be immediately solved. We were wrong. Our paypal.php was still not being notified. We then thought that since the other account is proven to be working, then why not change the email account for PayPal in RSForms to the email of the other (proven to be working) account. So we did that, and we tried a different payment, but still, no user was created (because the paypal.php was not called).

We then pondered, what if the RSForm component was overriding the PayPal notification URL (IPN). So we did a research, and then we discovered that there’s a System plugin, called, rsfppaypal.php, that invokes PayPal for any RSForm transaction, and that overrides the default PayPal IPN. Here’s the code that does that (it was located in line 439 of that file):

$link = $paypal_link . '?cmd=_xclick&business=' . urlencode(RSFormProHelper::getConfig('paypal.email')) . '&item_name=' . $products . '¤cy_code=' . urlencode(RSFormProHelper::getConfig('paypal.currency')). '&amount=' . $price . '&return_url='.urlencode(JURI::root().'index.php?option=com_rsform&formId='.$args['formId'].'&task=plugin&plugin_task=paypal.return&code='.$code).'¬ify_url='.urlencode(JURI::root().'index.php?option=com_rsform&formId='.$args['formId'].'&task=plugin&plugin_task=paypal.notify&code='.$code).'&return='.urlencode(RSFormProHelper::getConfig('paypal.return')).'&charset=utf-8'.$cancel_link.$language.$tax_code;

Take a look at this part from the above code:

notify_url='.urlencode(JURI::root().'index.php?option=com_rsform&formId='.$args['formId'].'&task=plugin&plugin_task=paypal.notify&code='.$code)

The above code is telling PayPal to use a component-set IPN instead of the default one. If you take a closer look, you’ll see that the above code is telling PayPal to notify a certain task, which is paypal.notify inside the rsfppaypal.php plugin. We searched for this task (inside the same System plugin) and here’s the code that we found:

			case 'paypal.notify':
				$this->rsfp_f_paypalNotify();
				exit();
			break;

As you can see, the paypal.notify case above handles all PayPal payments by invoking the $this->rsfp_f_paypalNotify(), so, in order to invoke our paypal.php file, we modified the above code to:

			case 'paypal.notify':
				$this->rsfp_f_paypalNotify();
				if ($_POST['payment_status'] == 'Completed')
					require_once('/path_to_file/paypal.php');
				exit();
			break;

And the problem was fixed! Our standard IPN file is now working even on RSForms, new users are being created, and notification emails are being sent!

We understand that the above might be a bit complicated, especially for those with no programming background, and that’s why we’re here to help. Just contact us if you want us to do the above for you and we’ll do it in record time and at a very competitive price!

No comments yet.

Leave a comment