official python sdk for interacting with thepeer payment processing infrastructure
Thepeer python-sdk
Thepeer's official python sdk for developers to use in their python projects.
- To start using this sdk, create an account at https://thepeer.co/ if you haven't already.
- You can then retrieve your API keys from your dashboard
Installation
To install this sdk, run the command:pip install pythepeer
Usage
Instantiate class like so:
from thepeer import Thepeer
create an instance of Thepeer class
thepeerinstance = Thepeer("YOURAPIKEYHERE")
Available methods exposed by the sdk
Note: - For more info about the exposed methods, please refer to the general documentation - Be sure to keep your API Credentials securely in environment variables
Indexing a user
This method describes how to index a user on your account (this is usually the first step before using other methods)test = thepeerinstance.indexuser("Osagie Iyayi", "iyayiemmanuel1@gmail.com", "iyayiemmanuel1@gmail.com")
Parameters supported
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| | | name of user to be indexed. | | | | identifier of the account(either email or username). | | | | email of the user |
Validating a HMAC signature
This method validates incoming an hmac signature with the payload and credentials that was passed with itPro Tip: it is used to verify that an incoming webhook event/response is coming from thepeer's servers
test = thepeerinstance.validatesignature(data,signature)
Parameters supported
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| | | payload containing the data to be authenticated | | | | HMAC signature |
Get an indexed user
This method gets the information of an indexed usertest = thepeerinstance.viewuser("3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd")
Parameters supported
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| | | unique reference returned when the user was indexed
Get all indexed users
This method returns all indexed users for a specific accounttest = thepeerinstance.allusers(1,15)
Parameters supported
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| | | first page displaying all the indexed users. defaults to 1 | | | | number of users to display per page. defaults to 15 |
Update an indexed user
This method helps to update the details of an indexed usertest = thepeerinstance.updateuser(reference,**data)
Parameters supported
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| | | unique reference returned when the user was indexed | | | | keyword argument which contains on or more of the indexed user's email, name or identifier |
Sample
test = thepeerinstance.updateuser("3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd", identifier="dwave101@yahoo.com",
name="Edmond Kirsch",
email="dwave101@gmail.com")
Remove an indexed user
This method helps to remove the details of an indexed user from a specific accounttest = thepeerinstance.deleteuser("3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd")
Parameters supported
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| | | unique reference returned when the user was indexed
### Get Businesses This method returns businesses based on the API they integrated.
test = thepeerinstance.getbusinesses("checkout")
Parameters supported
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| | | specific API to return businesses of. supported values are send, checkout, and direct_charge
Generate a Checkout
This method allows you to generate a link for your customer to make a one-time payment withtest = thepeerinstance.generatecheckout({
"amount": 1000000,
"currency": "NGN",
"redirect_url": "https://esportfolio.netlify.app",
"email": "jevede6918@muzitp.com",
"meta":{
"name": "Eddie Kirsch",
"identifier": "eddiekirsch",
}
})
Parameters required
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| | | url Thepeer should redirect to after the customer completes payment. | | | | amount you are debiting the customer. This should be in kobo. The minimum value is 10000 | | | | customer’s email address | | | | | currency the transaction should be carried out in. The supported value is NGN. | | | | object containing additional attributes you will like to have in your transaction response.
Get user links
This method returns all linked accounts of a user, the user’s account details, as well as the business the account is on.
test = thepeerinstance.getuser_links("3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd") Parameters required
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| | | unique reference returned when the user was indexed
Get single link (linked account)
This method returns a user's linked account's details.
test = thepeerinstance.getsingle_link("da14a90c-61c2-4cf7-a837-e3112a2d0c3d")
Parameters required
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| | | link’s identifier
Charge a link
This method allows a business to charge a user via their linked accounttest = thepeerinstance.chargelink(link_id, amount, remark, currency)
Parameters required
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| | | link’s identifier | | | | amount of the whole transaction | | | | detail about the transaction | | | | | denomination medium of paying (either one of NGN and USD). defaults to NGN
Authorize charge
This method allows a business to authorize a direct charge request made by a usertest = thepeerinstance.authorizecharge(charge_reference, event)
Parameters required
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| | | reference associated to a pending charge request | | | | type of webhook event |
Pro Tip: the various types of webhook events are available here
Get transaction detail
This method gets the details of a transactiontest = thepeerinstance.gettransaction_detail("eda58ee3-4f2c-4aa4-9da7-10a2b8ced453")
Parameters required
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| | | unique transaction identifier
Refund transaction
This method allows a business to refund a transaction back to the user for obvious reasonstest = thepeerinstance.refundtransaction("28e52edf-16d9-4921-8a54-ef34d7029707", "possible threat actor"):
Parameters required
| Parameters | Data type | Required | Description | |----------------------|---------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | | | | unique transaction identifier
| | | | short sentence explaining reasons for the refund |