Create a subscription form using RSForm!Pro and PayPal


Since the default integration between RSForm!Pro and PayPal does not have this functionality available, you will need to generate this through custom scripting. This article will offer you a step by step tutorial on how to create such a form.

 

1. First you will need to create the form. This can be easily done from the Manage forms tab by clicking the New button. In the example form we have created for this functionality we will be using a hidden field to set the status of the payment. The subscription dropdown contains the membership plans available for the user to subscribe to, the items are set after the following syntax: price|membership name - cost.

 
 

2. After the form is built you will need to add the custom script needed in order to send the subscription details to PayPal. The following script needs to be placed in the Scripts called after form has been processed field from the PHP Scripts tab.

    if($_POST['form']['subscription'][0] != '0')
    {
    $business = 'your_paypal_account_email';       //the account the payment is made to
    $item_name = str_replace($replace, $with, '{subscription:text}'); //this sets membership name
    $currency_code = 'USD';               //the currency used in the transaction 
    $a3 = $_POST['form']['subscription'][0];           //the subscription cost
    $p3 = '1';                                     //the subscription duration
    $t3 = 'M';                     //the subscription units of duration : M stands for month
    $src = '1';                     //this defines the subscription as recurring
    $no_note = '1';
    $notify_url = JURI::root().'index.php?option=com_rsform&formId='.$formId.'&submission='.$SubmissionId;
    $url= 'https://www.paypal.com/cgi-bin/webscr?cmd=_xclick-subscriptions&business='.urlencode($business).'&item_name='
    .urlencode($item_name).'&currency_code='.urlencode($currency_code).'&a3='.urlencode($a3).'&p3='.urlencode($p3).'&t3='
    .urlencode($t3).'&src='.urlencode($src).'&no_note='.urlencode($no_note).'&notify_url='.urlencode($notify_url);
    $app = JFactory::getApplication();
    $app->redirect($url);
    exit();
    }

For a detailed description of each parameter used in the script please refer to the following article.

3. Next you will need to add the script that changes the status of the payment when the confirmation is sent by PayPal. The script should be placed in the Scripts called on form display field and should be similar to:

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

12 persons found this article helpful.


Was this article helpful?

Yes No
Sorry about that

You Should Also Read

How to add a quantity functionality to a PayPal form HOT

Personalize PayPal parameters per form HOT

RSform!Pro PayPal total field is not updated properly

I enabled the PayPal plugin to live mode but it still redirecting to sandbox

Form does not redirect to PayPal upon submission