Formidable PayPal

Knowledge BaseExtend Formidable ProAdd Ons → Formidable PayPal

This plugin allows you to collect PayPal payments using Formidable Pro. You can send users and a payment amount directly to PayPal after submitting a Formidable form. Your users do NOT need to have a Paypal account in order to pay with Paypal.

Download and Set Up

  1. Download latest version:
    Please log in to download

    Note: Versions 2.0rc2+ require Formidable v1.6+. View the change log to see a complete list of changes made in each version.

  2. In your WordPress admin, go to “Plugins” → “Add New” and click the “Upload” link at the top of the page.
  3. Click the “Browse” button and select the zip file you just downloaded. Once the plugin is installed, click “Activate Plugin” or go to the “Plugins” page, find “Formidable Payment” and click “Activate”.
  4. Now that the plugin is activated, go to “Formidable” → “Global Settings” and click the “Payment” tab.
  5. Insert your PayPal email address and update any other settings. For live sites, make sure the “PayPal” environment is set to “Live”, otherwise, users will be prompted to set up new PayPal accounts.
  6. Go into edit the form you would like to use with PayPal. Click “Settings” → “Payment”.
  7. Check the box to Send users to PayPal after submitting this form.
  8. Choose an Item Name that will appear on the PayPal page and on the PayPal receipt. You can either type in the product name if it is not changing or select a field from your form if it will change depending on your user’s selection.
  9. Select an Amount Field from your form. This field should contain the payment amount that will be sent to Paypal.
  10. If you would like to send users to Paypal after form submission depending on a selection in the form, you will need to add Conditional Logic as shown above.
  11. Don’t forget to hit “Update” so these settings will be saved.

Set up Instant Payment Notifications

In order for your payments to get correctly marked as paid, you must configure your PayPal account to send payment notifications.

  1. Log into your PayPal account.
  2. Go to your “Profile” page and then “My Selling Tools”.
  3. Click the “Update” link next to “Instant Payment Notifications”.
  4. Edit and enter a notification URL. It doesn’t matter what URL you insert since Formidable PayPal will override it.
  5. Enable IPN Messages.
  6. Click Save.

Additional Customizations

These code examples can be added to your theme functions.php file or a new plugin. If you want to insert code into your theme functions.php, add it at the very end of the file, before the last ?> if there is one. If you plan to update your theme, be sure to put it in a new plugin so the code won’t be lost on update.

Automatically publish a post after payment.

If your entry is set up to create WordPress posts, you can prevent the post from being created until payment is successful:

add_action('frm_payment_paypal_ipn', 'publish_paid_post');
function publish_paid_post($args){ if(!$args['pay_vars']['completed']) return; //don't publish if the payment was not completed
if(!$args['entry']->post_id) return; //don't publish if not linked to a post
wp_update_post(array('ID' => $args['entry']->post_id, 'post_status' => 'publish'));
}

Set payment status field to complete after payment

If your form is not setup to create WordPress posts, you may add a field to your form to hold the payment status. For example, a drop-down or radio field with two options: Yes, and No. Set the Visibility to “Administrator”, and select “No” as the default value. Then, add this code to your theme functions.php or a new plugin to change the value to “Yes” when the payment is completed:

add_action('frm_payment_paypal_ipn', 'mark_as_complete');
function mark_as_complete($vars){
   if(!$vars['pay_vars']['completed'])
      return; //don't change value if the payment was not completed
   global $frmdb, $wpdb;
   $wpdb->update($frmdb->entry_metas, array('meta_value' => 'Yes'), array('item_id' => $vars['payment']->item_id, 'field_id' => 25)); //change 25 to the ID of the completed field
}

Change the user role after payment

The only change needed in the example is the user role the user should have: $new_role = ‘contributor’;

add_action('frm_payment_paypal_ipn', 'change_paid_user_role');

function change_paid_user_role($args){
    $new_role = 'contributor'; //change this to the role paid users should have
        
    if(!$args['pay_vars']['completed'])
       return; //don't continue if the payment was not completed

    if(!$args['entry']->user_id or !is_numeric($args['entry']->user_id))
       return; //don't continue if not linked to a user

    $user = get_userdata($args['entry']->user_id);
    if(!$user)
        return; //don't continue if user doesn't exist

    $updated_user = (array)$user;

    // Get the highest/primary role for this user  
    $user_roles = $user->roles;
    $user_role = array_shift($user_roles);
    if ( $user_role == 'administrator' ) 
        return; //make sure we don't downgrade any admins

    $updated_user['role'] = $new_role;
	
    wp_update_user($updated_user);
}

Change return URL

add_filter('formidable_paypal_url', 'formidable_paypal_url', 10, 3);
function formidable_paypal_url($paypal_url, $entry_id, $form_id){
  if($form_id == 5) //change 5 to the ID of your form
    $paypal_url .= '&return='. urlencode('http://example.com');
  return $paypal_url;
}

Use different currencies

add_action('frm_after_create_entry', 'change_my_return_url', 40, 2);
function change_my_return_url($entry_id, $form_id){
    //check if sending to PayPal
    if ( !$_POST || !isset($_POST['frm_payment']) || (is_admin() && !defined('DOING_AJAX')) ) {
        return;
    }

    if($form_id == 18){ //change 18 to the ID of the form to override the currency
        add_filter('frm_paypal_settings', 'change_my_GBP_currency');
    }else if($form == 19){
        add_filter('frm_paypal_settings', 'change_my_USD_currency');
    }
}

function change_my_GBP_currency($settings){
  $settings->currency = 'GBP';
  return $settings;
}

function change_my_USD_currency($settings){
  $settings->currency = 'USD';
  return $settings;
}