Skip to content

Commit

Permalink
Fix bugs and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
gray-adeyi committed Mar 10, 2023
1 parent 50e9231 commit ca5dc3f
Show file tree
Hide file tree
Showing 129 changed files with 33,440 additions and 35,241 deletions.
73 changes: 43 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# PyPaystack2

A fork of [PyPaystack](https://github.com/edwardpopoola/pypaystack). A simple python wrapper for Paystack API.
[![Downloads](https://static.pepy.tech/badge/pypaystack2)](https://pepy.tech/project/pypaystack2)
[![Downloads](https://static.pepy.tech/badge/pypaystack2/month)](https://pepy.tech/project/pypaystack2)
[![Downloads](https://static.pepy.tech/badge/pypaystack2/week)](https://pepy.tech/project/pypaystack2)

A developer friendly [Paystack](https://paystack.com/) API wrapper.

## Installation

1. Create your [Paystack account](https://paystack.com/) to get your Authorization key that is required to use this package.
2. Store your authorization key in your environment variable as `PAYSTACK_AUTHORIZATION_KEY` or pass it into the pypaystack api wrappers at instantiation.
1. Create your [Paystack account](https://paystack.com/) to get your Authorization key that is required to use this
package.
2. Store your authorization key in your environment variable as `PAYSTACK_AUTHORIZATION_KEY` or pass it into the
pypaystack api wrappers at instantiation.
3. Install pypaystack2 package.

```bash
Expand All @@ -19,16 +25,18 @@ to integrate their services into their projects. So for python developers, to us
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. for example
your python project.[See Pypaystack2's Documentation](https://gray-adeyi.github.io/pypaystack2/). You're encouraged to
use this documentation alongside [Paystack's official documentation](https://paystack.com/docs/)

```python
from pypaystack2.api import Miscellaneous # assumes you have installed pypaystack2
from pypaystack2 import Paystack # assumes you have installed pypaystack2
from pypaystack2.utils import Country
miscellaneous_wrapper = Miscellaneous() # assumes that your paystack auth key is in
# your environmental variables i.e. PAYSTACK_AUTHORIZATION_KEY=your_key otherwise instantiate

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.
# miscellaneous_wrapper = Miscellaneous(auth_key=your_paystack_auth_key)
response = miscellaneous_wrapper.get_banks(country=Country.NIGERIA,use_cursor=False) # Requires internet connection.
# paystack = Paystack(auth_key=your_paystack_secret_key)
response = paystack.miscellaneous.get_banks(country=Country.NIGERIA, use_cursor=False) # Requires internet connection.
print(response)
```

Expand All @@ -37,34 +45,39 @@ to get a list of banks supported by paystack. A `requests` equivalent of the abo
be like

```python
import requests # assumes you have requests installed.
import requests # assumes you have requests installed.

headers = {
"Content-Type":"application/json",
"Authorization": "Bearer <your_auth_key>"
}
"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
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 `miscellaneous_wrapper`
in the example above. you can call all endpoints associated with the Miscellaneous API with methods
provided like `.get_banks`, `.get_providers`, `.get_countries` and `.get_states`.

Pypaystack2 provides wrappers to all of Paystack APIs in its `pypaystack2.api` subpackage.
each of the wrappers is a python class named to closely match the Paystack API. so say you want
to use Paystack's Invoices API, you'd import the wrapper with `from pypaystack2.api import Invoice`
for the Invoices API. All endpoints available on the Invoices API are available as methods
in the `Invoice` wrapper. Say you wanted to create an invoice by sending a
`POST` request to Paystack's Invoice API endpoint `/paymentrequest`, you'll call
`Invoice` wrapper's `.create` method.
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

```python
from pypaystack2.api import Invoice
invoice_wrapper = Invoice()
response = invoice_wrapper.create(customer="CUS_xwaj0txjryg393b",amount=1000) # Creates an invoice with a charge of ₦100
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()
```

From here you can check out the tutorials section to get more examples and get familiar or surf the
documentation for wrappers and methods you'll need for your next project. Hurray!
For more, [See Documentation](https://gray-adeyi.github.io/pypaystack2/)
34 changes: 10 additions & 24 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Welcome to pypaystack2's documentation!

Pypaystack2 is a simple API wrapper for Paystack API Endpoints in python.
A fork of the initial pypaystack project. Inspired by the initial project,
It aims to improve on the good works of the initial project which is no
longer actively maintained. I'm not sure if i knew much about python and programming
in general when the original authors created it in 2016 but in my journey, the
project has proved useful in several python projects that I've written over
the years. The motivation for building on this package is that it's awesome,
but in recent years, the package breaks my django applications when deploying
to a hosting platform. So this is my attempt to provide a solution. Plus my
curiosity to feel what it's like to build and maintain a package. let's get
started!

## What's Pypaystack2

So Paystack provides restful API endpoints for developers from different platforms
Expand All @@ -22,15 +8,15 @@ by handling all these complexities under the hood and exposing simple APIs for
your python project. for example

```python
from pypaystack2.api import Miscellaneous # assumes you have installed pypaystack2
from pypaystack2 import Paystack # assumes you have installed pypaystack2
from pypaystack2.utils import Country

miscellaneous_api_wrapper = Miscellaneous() # assumes that your paystack auth key is in
# your enviromental variables i.e. PAYSTACK_AUTHORIZATION_KEY=your_key otherwise instatiate
paystack = Paystack() # assumes that your paystack auth key is in
# your enviromental variables i.e. PAYSTACK_AUTHORIZATION_KEY=<paystack-secret-key> otherwise instatiate
# the Miscellaneous API wrapper as it is done below.
# miscellaneous_wrapper = Miscellaneous(auth_key=your_paystack_auth_key)
response = miscellaneous_api_wrapper.get_banks(country=Country.NIGERIA,
use_cursor=False) # Requires internet connection.
# paystack = Paystack(auth_key=<paystack-secret-key>)
response = paystack.miscellaneous.get_banks(country=Country.NIGERIA,
use_cursor=False) # Requires internet connection.
print(response)
```

Expand Down Expand Up @@ -64,11 +50,11 @@ in the `Invoice` wrapper. Say you wanted to create an invoice by sending a
`Invoice` wrapper's `.create` method.

```python
from pypaystack2.api import Invoice
from pypaystack2 import Paystack

invoice_api_wrapper = Invoice()
response = invoice_api_wrapper.create(customer="CUS_xwaj0txjryg393b",
amount=1000) # Creates an invoice with a charge of ₦100
paystack = Paystack()
response = paystack.invoices.create(customer="CUS_xwaj0txjryg393b",
amount=1000) # Creates an invoice with a charge of ₦100
```

From here you can check out the tutorials section to get more examples and get familiar or surf the
Expand Down
1 change: 1 addition & 0 deletions docs/reference.md → docs/reference.md.bak
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
::: pypaystack2.api.splits
::: pypaystack2.api.subaccounts
::: pypaystack2.api.subscriptions
::: pypaystack2.api.terminals
::: pypaystack2.api.transactions
::: pypaystack2.api.transfer_recipients
::: pypaystack2.api.transfers
Expand Down
37 changes: 18 additions & 19 deletions docs/tutorials/tutorial1.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using only the test secret key. create a new file named `.env` within your proje
Now put in your test secret key in the `.env` file like so.

```env
PAYSTACK_AUTHORIZATION_KEY = "<your test secret key>"
PAYSTACK_AUTHORIZATION_KEY = "<your paystack test secret key>"
```

!!! warning
Expand Down Expand Up @@ -84,6 +84,7 @@ currently available as at the time of writing of this tutorial.
- Split
- SubAccount
- Subscription
- Terminal
- Transaction
- TransferReceipt
- TransferControl
Expand All @@ -94,15 +95,13 @@ So in a situation where you don't have your `PAYSTACK_AUTHORIZATION_KEY` as an e
you can pass it into any of the API wrappers. e.g.

```python
# When you don't have PAYSTACK_AUTHORIZATION_KEY in your environmental variables
from pypaystack2.api import Transaction, Plan
# When you don't have PAYSTACK_AUTHORIZATION_KEY(paystack secret key) in your environmental variables
from pypaystack2 import Paystack

txn_wrapper = Transaction(auth_key="<your test secret key>")
plan_wrapper = Plan(auth_key="<your test secret key>")
paystack = Paystack(auth_key="<your test secret key>")

# When you have PAYSTACK_AUTHORIZATION_KEY set in your environmental variables
txn_wrapper = Transaction()
plan_wrapper = Plan()
# When you have PAYSTACK_AUTHORIZATION_KEY(paystack secret key) set in your environmental variables
paystack = Paystack()
```

???+ note
Expand Down Expand Up @@ -180,13 +179,13 @@ at [Paystack's Customer Services API](https://paystack.com/docs/api/#customer)
# root-dir/main.py
from typing import Optional
from dotenv import load_dotenv
from pypaystack2.api import Customer
from pypaystack2 import Paystack
from typer import Typer

load_dotenv()
app = Typer()

customer_wrapper = Customer()
paystack = Paystack()


@app.command()
Expand All @@ -196,7 +195,7 @@ def new_customer(
last_name: Optional[str] = None,
phone: Optional[str] = None,
):
response = customer_wrapper.create(
response = paystack.customers.create(
email=email, first_name=first_name, last_name=last_name, phone=phone
)
print(response.status_code)
Expand All @@ -210,7 +209,7 @@ if __name__ == "__main__":
```

???+ note
All API wrappers are available in `pypaystack2.api`. e.g. `from pypaystack2.api import Split, Transaction`
All API wrappers are available on `pypaystack`. as attributes e.g. `paystack.transactions` for the Transactions API

Now if you run the script again.

Expand Down Expand Up @@ -268,7 +267,7 @@ object based on the response it gets from Paystack. This `Response` is just a `N
`status,status_code,message` and `data`. So this call

```python
response = customer_wrapper.create(email=email, first_name=first_name, last_name=last_name, phone=phone)
response = paystack.customers.create(email=email, first_name=first_name, last_name=last_name, phone=phone)
```

in our script returns the `Response` object just described, and you can access each of these attributes with
Expand All @@ -282,14 +281,14 @@ Let's add a few more commands to our **Paystack Command line Client**
# root-dir/main.py
from typing import Optional
from dotenv import load_dotenv
from pypaystack2.api import Customer
from pypaystack2 import Paystack
from typer import Typer

load_dotenv()

app = Typer()

customer_wrapper = Customer()
paystack = Paystack()


@app.command()
Expand All @@ -299,7 +298,7 @@ def new_customer(
last_name: Optional[str] = None,
phone: Optional[str] = None,
):
response = customer_wrapper.create(
response = paystack.customers.create(
email=email, first_name=first_name, last_name=last_name, phone=phone
)
print(response.status_code)
Expand All @@ -310,7 +309,7 @@ def new_customer(

@app.command()
def list_customers():
response = customer_wrapper.get_customers()
response = paystack.customers.get_customers()
print(response.status_code)
print(response.status)
print(response.message)
Expand All @@ -319,7 +318,7 @@ def list_customers():

@app.command()
def get_customer(ec: str):
response = customer_wrapper.get_customer(email_or_code=ec)
response = paystack.customers.get_customer(email_or_code=ec)
print(response.status_code)
print(response.status)
print(response.message)
Expand All @@ -328,7 +327,7 @@ def get_customer(ec: str):

@app.command()
def update_customer(code: str, last_name: str, first_name: str):
response = customer_wrapper.update(
response = paystack.customers.update(
code=code, last_name=last_name, first_name=first_name
)
print(response.status_code)
Expand Down
7 changes: 3 additions & 4 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ markdown_extensions:
nav:
- Introduction: index.md
- Tutorials:
- Table of contents: tutorials/index.md
- Paystack Command line Client: tutorials/tutorial1.md
Paystack Command line Client: tutorials/tutorial1.md
- How-To Guides: how-to-guides.md
- Reference: reference.md
- explanation.md
# - Reference: reference.md.bak
- Explanation: explanation.md

Loading

0 comments on commit ca5dc3f

Please sign in to comment.