Partner Docs
Search…
πŸ›Ή
Getting Started
Learn how to setup your API to use PayPI
Interact with PayPI using our SDKs:
Get started creating an API or check out some of our example implementations:
  • ​Go Yoda (A text to Yoda speak API in Go)
  • ​Express Yoda (A text to Yoda speak API in NodeJS)
  • ​EmailVerify (Email verification API from PayPI)

1. Setup Partner Account

To setup a PayPI team to become a partner, switch to that team and click "Sell on PayPI", this will allow you access to the API Manager via the marketplace icon in the main menu, where you can start creating and managing your APIs.

2. Create an API

Create an API on the PayPI website and keep note of your API Secret (you'll use this to authenticate your API) and your Share URL (your users need this to subscribe to your API).

Create a charge

To accept payments you need to decide what to charge your users. Charges are created in the β€œcharges” section of your API dashboard, they state what you are going to be charging your users for and how much.
We recommend the following when creating charges:
  • Make it simple, keep the number of charges to a minimum.
  • Write a detailed description so users know exactly what they’re being charged for.
  • Use dynamic charges wherever your charge may change per request, like charging more per request

3. Setup your API Application

Install PayPI's library, where you plan to do your authentication.
Go
Node JS
Python
1
go get -u github.com/paypi/paypi-go
Copied!
1
npm install paypi
2
yarn add paypi
Copied!
1
pip install paypi
Copied!

Setup API

Import the PayPI library and set your API Secret.
Go
Node JS
Python
1
import (
2
"http"
3
"github.com/paypi/paypi-go/paypi"
4
)
5
​
6
paypi.Key = "<API_SECRET_KEY>"
Copied!
1
import PayPI from 'paypi'
2
​
3
const paypi = new PayPI("<Your API secret")
Copied!
1
from paypi import PayPI
2
​
3
paypi = PayPI("<Your API Secret>")
Copied!
​

Authenticate users

To take payments, you must first check that the API token they have given you is valid.
You may retrieve the API token from your users in any way you see fit, although we recommend this is done in the Authentication header if HTTP is being used.
Go
Node JS
Python
1
user, err := paypi.Authenticate("<Subscriber secret>")
2
if err != nil {
3
http.Error(w, "User token is unauthorized", http.StatusUnauthorized)
4
return
5
}
Copied!
1
const user = await paypi.authenticate("<Subscriber secret>")
Copied!
1
# Async
2
user = await paypi.authenticate("<Users Subscription Secret>")
3
​
4
# Synchronously
5
user = paypi.authenticate_sync("Users Subscription Secret")
Copied!
If this method returns without error you can continue processing the request. If it fails you should immediately return an unauthorised response from your API.
​

4. Make Charges

Go
Node JS
Python
user.MakeCharge is used to charge users on the platform. When user.MakeCharge is called the user is charged for their usage on your platform. This should be done at the end of your request, when you are sure that their request is going to be fulfilled successfully.

Static Charges

Static charges need only provide the charge identifier
1
user, _ := paypi.Authenticate("<USER_TOKEN>")
2
​
3
charge, err := user.MakeCharge(paypi.MakeChargeInput{
4
ChargeIdentifier: "<CHARGE_IDENTIFIER>",
5
})
Copied!
Dynamic Charges
If a charge is dynamic, you must provide the number of units used. This is usually representative of seconds of processing time, or MB of data processed. This unit is multiplied by the price set for the dynamic charge to calculate the total cost to the user.
1
user, _ := paypi.Authenticate("<USER_TOKEN>")
2
​
3
charge, err := user.MakeCharge(paypi.MakeChargeInput{
4
ChargeIdentifier: "<CHARGE_IDENTIFIER>",
5
UnitsUsed: 5,
6
})
Copied!
user.makeCharge is used to charge users on the platform. When user.makeCharge is called the user is charged for their usage on your platform. This should be done at the end of your request, when you are sure that their request is going to be fulfilled successfully.

Static Charges

Static charges need only provide the charge identifier
1
const user = await paypi.authenticate("<Subscriber secret>")
2
​
3
await user.makeCharge("<CHARGE_IDENTIFIER>")
Copied!
Dynamic Charges
If a charge is dynamic, you must provide the number of units used. This is usually representative of seconds of processing time, or MB of data processed. This unit is multiplied by the price set for the dynamic charge to calculate the total cost to the user.
1
const user = await paypi.authenticate("<Subscriber secret>")
2
​
3
const unitsUsed = 4
4
await user.makeCharge("<CHARGE_IDENTIFIER>", unitsUsed)
Copied!
user.make_charge is used to charge users on the platform. When user.make_charge is called the user is charged for their usage on your platform. This should be done at the end of your request, when you are sure that their request is going to be fulfilled successfully.

Static Charges

Static charges need only provide the charge identifier
1
# Async
2
user = await paypi.authenticate("<Subscription Secret>")
3
await user.make_charge("<CHARGE_IDENTIFIER>")
4
​
5
# Sync
6
user = paypi.authenticate_sync("<Subscription Secret>")
7
user.make_charge_sync("<CHARGE_IDENTIFIER>")
Copied!
Dynamic Charges
If a charge is dynamic, you must provide the number of units used. This is usually representative of seconds of processing time, or MB of data processed. This unit is multiplied by the price set for the dynamic charge to calculate the total cost to the user.
1
units_used = 4
2
​
3
# Async
4
user = await paypi.authenticate("<Subscription Secret>")
5
await user.make_charge("<CHARGE_IDENTIFIER>", units_used)
6
​
7
# Sync
8
user = paypi.authenticate_sync("<Subscription Secret>")
9
user.make_charge_sync("<CHARGE_IDENTIFIER>", units_used)
Copied!
​

Example Usage

Go
Node JS
Python
1
package main
2
​
3
import (
4
"http"
5
"github.com/paypi/paypi-go/paypi"
6
)
7
​
8
// Set the API secret key on initialising your application
9
paypi.Key = "<API_SECRET_KEY>"
10
​
11
func handleRequest(w http.ResponseWriter, r *http.Request) {
12
// Check if a user's token is valid, this token usually comes from the
13
// Authorization header, but can be given in any way you choose.
14
user, err := paypi.Authenticate(r.Header.Get("Authorization"))
15
if err != nil {
16
http.Error(w, "User token is unauthorized", http.StatusUnauthorized)
17
return
18
}
19
​
20
// Do some processing, fetch the response etc...
21
​
22
// If request was successful, make a static charge
23
charge, err := user.MakeCharge(paypi.MakeChargeInput{
24
ChargeIdentifier: "<STATIC_CHARGE_IDENTIFIER>",
25
})
26
​
27
// Make a dynamic charge based on processing
28
charge, err = user.MakeCharge(paypi.MakeChargeInput{
29
ChargeIdentifier: "<DYNAMIC_CHARGE_IDENTIFIER>",
30
UnitsUsed: 2.34,
31
})
32
​
33
fmt.Fprintf(w, "Request Successful")
34
}
Copied!
1
import PayPI from 'paypi';
2
import express from 'express'
3
​
4
const app = express()
5
const port = 3000
6
const paypi = new PayPI("<YOUR API SECRET>")
7
​
8
app.get('/', async (req, res) => {
9
const subscriberSecret = req.get("Authentication")
10
const user = await paypi.authenticate(subscriberSecret)
11
12
// Do some processing, fetch response data, etc
13
14
// Once request is going to go through, charge the user using a ChargeID.
15
await user.makeCharge("cid-R4tfSt4")
16
await user.makeCharge("cid-U7dhaf3", 34) // Dynamic charges need to be given unitsUsed.
17
18
res.send('Hello World!')
19
})
20
​
21
app.listen(port, () => {
22
console.log(`Example app listening at http://localhost:${port}`)
23
})
Copied!
1
from paypi import PayPI
2
​
3
paypi = PayPI("<Your API Secret>")
4
​
5
​
6
@app.route("/")
7
async def hello():
8
user = await paypi.authenticate("<Users Subscription Secret>")
9
​
10
# do some work...
11
​
12
await user.make_charge("<Charge ID>")
13
14
# charge is now made, return the response
Copied!
​

5. Share your API

Inform your users they can pay with PayPI by redirecting them to the Share URL link for your API.