Forum Documentation Showcase Pricing Learn more

Paypal Payout API Integration


#1

Hello,

I want to create a payout functionality in my website using PayPal. PayPal has a payout API to integrate into your website but I have no experiences with API’s (and the API connector plugin) and I do not know where to start.
Is there a plugin I can use to integrate this into my website or did some of you already integrate this functionality and want to provide some information? That would really help me.

Thanks.


#2

Hello @thimowaanders,

Here’s how I have been using it for the user to sign up for a subscription plan (recurring payment):

STEP 1 - Login with PayPal


Login Dialog Redirect: https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize
Access Token Endpoint: https://api.sandbox.paypal.com/v1/oauth2/token
User Profile Endpoint: https://api.sandbox.paypal.com/v1/identity/openidconnect/userinfo?schema=openid

STEP 2 - Create Billing Plan


Here’s the link to the Official PayPal API documentation where you get the template JSON Body: https://developer.paypal.com/docs/api/payments.billing-plans/v1/#billing-plans_create

Step 3 - Create Billing Agreement

Step 4 - Redirect the user to the agreement approval after creating the agreement:

Step 5 - Execute the agreement:

That’s it, @thimowaanders.
If you want to make a simple payment (not recurring), I suggest you use “Payments” or “Orders” from https://developer.paypal.com/docs/api/overview/.

Now, the thing is, I’m not too happy about this UX:

  1. First, the user has to click a button to Login to PayPal, so we can get his OAuth token.
  2. When the user is back in our app, he clicks another button so we can make an API request to create his billing agreement (assuming you already have a billing plan), and then redirect him (again!) to PayPal to approve this agreement.
  3. And then, when the user is once more back in our app, he clicks a button (or we perform an action any other way) to Execute the billing agreement.

Could anyone shed a light? Is this the best way to setup this payment flow?
Is there any way we could make the initial OAuth call and perform an API request in the same login, so the user doesn’t get redirected twice?

Thank you very much, and I hope I’ve helped, @thimowaanders.


#3

Thank you so much for this great explanation! You helped a lot! I will try to integrate this API into my site and maybe I’ll find a solution for your problem.

Thanks again!


#4

Hi,
Did you manage to implement it with only one redirect?
Thanks,
Yon


#5

Hello @yon1,

Yes, I did it with 2 steps :grin:

The main thing is that I learned how to connect with PayPal without having to login, just with a basic auth:

So, here’s how it goes:

Step 1 (Admin) - Create Billing Plans
Create every single billing plan you might use. My SaaS, for example, has 10 billing plans, each one with a different name, description and value. Here’s how you create a billing plan:


The Body JSON is:

{
  "name": "<Plan Name>",
  "description": "<Plan Description>",
  "type": "INFINITE",
  "payment_definitions": [
    {
      "name": "<Nome Def. Pgto>",
      "type": "REGULAR",
      "frequency": "MONTH",
      "frequency_interval": "1",
      "amount": {
        "value": "<Plan Amount>",
        "currency": "USD"
      },
      "cycles": "0"
    }
  ],
  "merchant_preferences": {
    "setup_fee": {
      "value": "<Setup Fee Amount>",
      "currency": "USD"
    },
    "return_url": "https://yourapp.com/api/1.1/oauth_redirect",
    "cancel_url": "https://yourapp.com/api/1.1/oauth_redirect",
    "auto_bill_amount": "YES",
    "initial_fail_amount_action": "CANCEL",
    "max_fail_attempts": "0"
  }
}

(That’s the way I setup the JSON. You can do it differently, just check out PayPal API Documentation with the full code, and change it however you like. I recommend using Postman to analyze if the code is correct)

Step 2 (Admin) - Activate Billing Plan
Change state to ACTIVE:

Ok, everything is set up for the user to subscribe to a plan now:

Step 1 (User) - Choose Plan and Approve
When the user clicks the button below, the app will “Create a Billing Agreement” and redirect the user to the Approval URL (I already showed how in the previous post).


This will redirect him to PayPal to choose how he’s going to pay.

Step 2 (User) - Confirm
When he gets back from the PayPal Approval Page, he will have a “token” parameter automatically set up by PayPal. Just “Execute Agreement” with this token, and show a Success Screen to the user.

So, basically, the user just has to click once to go to PayPal and choose payment method, and then click again to confirm when he gets back to the page.
It was possible by learning how to request APIs using BASIC (not Oauth), and by redesigning UX.

FYI, It’s already live and working in my app.

Hope I could help.

Cheers!

Renato