A developer friendly [Paystack](https://paystack.com/) API wrapper.
Project description
PyPaystack2
A developer friendly Paystack API wrapper.
Installation
- Create your Paystack account to get your Authorization key that is required to use this package.
- Store your authorization key in your environment variable as
PAYSTACK_AUTHORIZATION_KEY
or pass it into the pypaystack api wrappers at instantiation. - Install pypaystack2 package.
pip install -U pypaystack2
What's Pypaystack2
So Paystack provides restful API endpoints for developers from different platforms
to integrate their services into their projects. So for python developers, to use
these endpoints, you might opt for a package like requests
to handle all the
API calls which involves a lot of boilerplate. Pypaystack2 abstracts this process
by handling all these complexities under the hood and exposing simple APIs for
your python project.See Pypaystack2's Documentation. You're encouraged to
use this documentation alongside Paystack's official documentation
from pypaystack2 import Paystack # assumes you have installed pypaystack2
from pypaystack2.utils import Country
paystack = Paystack() # assumes that your paystack auth key is in
# your environmental variables i.e. PAYSTACK_AUTHORIZATION_KEY=your_paystack_secret_key otherwise instantiate
# the Miscellaneous API wrapper as it is done below.
# paystack = Paystack(auth_key=your_paystack_secret_key)
response = paystack.miscellaneous.get_banks(country=Country.NIGERIA, use_cursor=False) # Requires internet connection.
print(response)
With the code snippet above, you have successfully queried Paystack's Miscellaneous API
to get a list of banks supported by paystack. A requests
equivalent of the above will
be like
import requests # assumes you have requests installed.
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <your_auth_key>"
}
paystack_url = 'https://api.paystack.co/bank?perPage=50&country=ng&use_cursor=false'
response = requests.get(paystack_url, headers=headers) # requires internet connection
print(response.json())
While both approaches achieve the same goal, pypaystack2
uses requests
under the hood and
manages the headers and URL routes to endpoints, so you can focus more on the actions. with the paystack
in the example above, you can call all endpoints provided by paystack via paystack.[api_group_name].[method]
so for
example associated with the Miscellaneous API with
methods
provided like .get_banks
, .get_providers
, .get_countries
and .get_states
to use them, you can that by
paystack.miscellaneous.get_banks()
, paystack.miscellaneous.get_providers
. Say you wanted to verify a transaction
with Paystack's Transaction API you can achieve that like
so paystack.transactions.verify(reference="transaction-reference")
Pypaystack2 currently provides wrappers to the following Paystack APIs via
from pypaystack2 import Paystack # assumes you have installed pypaystack2
paystack = Paystack() # assumes that your paystack auth key is in
# your environmental variables i.e. PAYSTACK_AUTHORIZATION_KEY=your_paystack_secret_key otherwise instantiate
# the Miscellaneous API wrapper as it is done below.
# paystack = Paystack(auth_key=your_paystack_secret_key)
paystack.apple_pay # Apple Pay API e.g paystack.apple_pay.get_domains()
paystack.bulk_charges # e.g. paystack.bulk_charges.get_batch()
paystack.charge # e.g. paystack.charge.check_pending_charge()
For more, See Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pypaystack2-1.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 282fab89091841a4cd1dbfe2c8f854943998d3cf0e43ccd4ebdf420846bfcc24 |
|
MD5 | 530c7c3fdce2e73cb610802085c0da9f |
|
BLAKE2b-256 | 30a2bf9463bbcaabbe93fd64fa0440e2a95bd2057cf023ffa304ba88915bb0a4 |