Print

3 ways to create a small Joomla! shopping cart with RSForm!Pro and PayPal - payment confirmation

Posted by Mihaela in RSForm!Pro

Created on 04 Jul 2011

And tagged with: forms , PayPal


RSForm!Pro with PayPal integration

When we first started to write this article, we were planning to structure it as a 3 part series.
Yet, our readers' feedback has determined us to write the 4th part of the article, to further analyze the payment process, once the user completes the transaction.

While the first 3 articles have coverred the required steps in setting up a small shopping cart with RSForm!Pro, whether by using the PayPal plugin or a given custom script, this article we'll explain how can you receive the payment confirmation right in the RSForm!Pro "Manage submissions" tab.

We're going to extend the custom script used in the 3rd part of the article, to record through a hidden field, the payment status: confirmed or not.

Once the user submits the form and completes the transaction, the RSForm!Pro status field value will be updated as "confirmed". By default, this field is "not confirmed".

Backend preview:

RSForm!Pro Paypal payment confirmation - Joomla! back-end area

You can later check the payment status by accessing the backend Joomla! panel >>Components >> RSForm!Pro >> Manage Submissions.

RSForm!Pro Paypal payment confirmation - manage submissions

The 4th part of the article comes with a new form field (hidden field), that allows us to trigger the payment status. That involves several script changes.

Basically, the steps of creating the PayPal form are as described in the 3rd article.
In this article, we will only show the changes made to the above mentioned script to receive the payment confirmation.

Step 1: Add products, prices and quantities

In addition to the form components described in the previous article (textboxes for the First Name, Last Name, Email Address and Total, checkbox groups for products, dropdown for the quantity), you will need to create a hidden field , used to record the payment status: confirmed or not.

Step 2. Modify form layout

Once you have created the hidden field, head to the RSForm!Pro "Form layout" tab and add, at the end of the HTML code, the corresponding placeholder: {status:body}

Step 3: check the 3rd part of the article

Step 4:

When submitting the form, just before redirecting to PayPal, we need to pass the URL that will receive the confirmation. This will be the direct URL for the form. The new script is as follows:

if($_POST['form']['Total'] != '0')
{
$business = 'me@mybusiness.com';
$item_name = 'Products';
$currency_code = 'USD';
$amount = $_POST['form']['Total'];
$return = JURI::root();
$db = JFactory::getDBO();
$notify = urlencode(JURI::root().'index.php?option=com_rsform&formId='.$db->getEscaped($_POST['form']['formId']).'&submission='.$SubmissionId);
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business='.$business.'&item_name='.$item_name.'&currency_code='.$currency_code.'&amount='.$amount.'&return='.$return.'&notify_url='.$notify;
header('Location: '.$url);
exit();
}

Explanations

The new addition is the use of the PayPal notify URL parameter: ┬Čify_url . This will simply point back to the form with a parameter that will uniquely identify the submission that is being processed.
Notice the $SubmissionId variable.

Up next, we need to process the confirmation and update the status field. We can easily do this by using the following script, placed in the "Scripts called on form display" area, "Manage forms" tab :

$db = JFactory::getDBO();
$sid = $db->getEscaped(JRequest::getVar('submission'));
if(!empty($sid))
{
$db->setQuery("UPDATE #__rsform_submission_values SET `FieldValue` = 'confirmed' WHERE `SubmissionId` = '".$sid."' AND `FieldName` = 'status'");
$db->query();
die();
}

Explanations

Based on the earlier mentioned $SubmissionId variable, we can identify the submission that is being confirmed and update the value of the status field. Note that the script will be executed only if the submission confirmation is received.

Notice:

You can read more on the RSForm!Pro scripting areas here.

The example is available for download on the www.rsjoomla.com website. Notice that you must have at least RSForm!Pro rev. 36 in order to work.

Once you have downloaded the sample form, head to the Joomla! backend panel >> Components >> RSForm!Pro >>"Backup/Restore" tab and restore the package that you've just downloaded. You will find the Custom PayPal example listed in the RSForm!Pro "Manage Forms" tab.

Download the PayPal example with payment confirmation

Related articles: