How to integrate BuddyForms and PayPal
In this tutorial we’ll show you how to integrate the PayPal payment platform with BuddyForms in case you want to charge a fee for each post submitted on your form. To achieve this, it is necessary to have the following:
BuddyForms: To create the post type form that users will use to make the submission.
BuddyForms Moderation: This extension will allow us to moderate each post to publish it once the payment has been verified and the post has been reviewed.
PayPal Account: This account must meet the necessary requirements at least to receive payments.
Step one: Create a new Post form
You just have to click on BuddyForms > Add new, and select the fields you want or simply click on one of the predefined templates:
When you are creating the form, an important step is to add a radiobutton type field and specify in each variant of the product/service. For example, let's say you have a pet website where users can list their pet for sale. So, the price should vary depending on the type of pet, something like:
Once you have given it an appropriate title and published the form, scroll down to enable moderation (remember you must first install BuddyForms Moderation). The option you must choose is the following:
Step Two: Get your Client ID in PayPal
To check your Client ID you have to log in at https://developer.paypal.com/ and click on APICredentials.
PayPal includes a default application you can use or you can create a new one for your project. By clicking on the app name you can see the credentials and copy your client ID key:
Step three: Add the script
You can do it in two ways. The first, and easiest way is to use your page builder's code block. For example, if you use Divi you have to click on Insert Module > Code and paste here the script with your client ID and the components you want to enable.
The other way you can add the script is by creating a custom template on your site. This can be achieved by going into your active theme folder and duplicating the page.php file under another name. Then you must edit this new copy and add to the beginning of the file
After including the PayPal script, the file should look like:
Finally, you just have to create a new page and within the settings select this template that you just created.
Step Four: Using BuddyForms Hooks
To complete the integration, you have to use one of our hooks to redirect to the page with the PayPal checkout button. The hook you have to edit is the following:
You should replace 'Field-Slug' with the name you gave your radiobutton in the form settings:
In this particular case it should be "$_POST[‘pet-type’]"