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:
3. Setup your API Application
Install PayPI's library, where you plan to do your authentication.
import PayPI from'paypi'constpaypi=newPayPI("<Your API secret")
from paypi import PayPIpaypi =PayPI("<Your API Secret>")
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.
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
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
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.
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
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.
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
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.
packagemainimport ("http""github.com/paypi/paypi-go/paypi")// Set the API secret key on initialising your applicationpaypi.Key ="<API_SECRET_KEY>"funchandleRequest(w http.ResponseWriter, r *http.Request) {// Check if a user's token is valid, this token usually comes from the// Authorization header, but can be given in any way you choose. user, err := paypi.Authenticate(r.Header.Get("Authorization"))if err !=nil { http.Error(w, "User token is unauthorized", http.StatusUnauthorized)return }// Do some processing, fetch the response etc...// If request was successful, make a static charge charge, err := user.MakeCharge(paypi.MakeChargeInput{ ChargeIdentifier: "<STATIC_CHARGE_IDENTIFIER>", })// Make a dynamic charge based on processing charge, err = user.MakeCharge(paypi.MakeChargeInput{ ChargeIdentifier: "<DYNAMIC_CHARGE_IDENTIFIER>", UnitsUsed: 2.34, }) fmt.Fprintf(w, "Request Successful")}
import PayPI from'paypi';import express from'express'constapp=express()constport=3000constpaypi=newPayPI("<YOUR API SECRET>")app.get('/',async (req, res) => {constsubscriberSecret=req.get("Authentication")constuser=awaitpaypi.authenticate(subscriberSecret)// Do some processing, fetch response data, etc// Once request is going to go through, charge the user using a ChargeID.awaituser.makeCharge("cid-R4tfSt4")awaituser.makeCharge("cid-U7dhaf3",34) // Dynamic charges need to be given unitsUsed.res.send('Hello World!')})app.listen(port, () => {console.log(`Example app listening at http://localhost:${port}`)})
from paypi import PayPIpaypi =PayPI("<Your API Secret>")@app.route("/")asyncdefhello(): user =await paypi.authenticate("<Users Subscription Secret>")# do some work...await user.make_charge("<Charge ID>")# charge is now made, return the response
5. Share your API
Inform your users they can pay with PayPI by redirecting them to the Share URL link for your API.