Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,39 @@ In order to use our API, you will need to :
Visite [our website ](https://slick-pay.com/) and create an account. If you are merchant you have to add your satim information like username and password
#### 2. Get api's key
After logging in, from your dashboard, you will able to get your PUBLIC_KEY.
#### 3. Configure through environment variables
#### 3. Configure API Client
```python
from slickpay import slickPayApi

env = "dev"
api_client = slickPayApi()
api_client.config(environment=env, public_key="PUBLIC_KEY")
```
#### 4. Configure through environment variables
Create a .env file and inside your .env file create a variable like this:
```python
public_key= your_public_key
sandbox= True or False
```
Import environment variables
```python
import os
from dotenv import load_dotenv
load_dotenv()

from slickpay import slickPayApi

env = "prod"
api_client = slickPayApi()
api_client.config(environment=env, public_key=os.environ["public_key"])
```

# How to use?
## Concerning merchant account
## InvoiceTransferMerchant
### Create Invoice
```python
from slickpay import InvoiceTransferMerchant
invoiceMerchant = InvoiceTransferMerchant()
invoiceMerchant = InvoiceTransferMerchant(client=api_client)
data =
{
'amount': 10000,
Expand Down Expand Up @@ -80,7 +100,7 @@ from slickpay import InvoiceTransferMerchant
### Create
```python
from slickpay import Account
userAccount = Account()
userAccount = Account(client=api_client)
data = {
"title" : "Lorem Ipsum",
"lastname" : "Lorem",
Expand Down Expand Up @@ -115,7 +135,7 @@ from slickpay import Account
### Create Contact
```python
from slickpay import Contact
userContact = Contact()
userContact = Contact(client=api_client)
data = {
"title" : "Lorem Ipsum",
"lastname" : "Lorem",
Expand Down Expand Up @@ -151,7 +171,7 @@ from slickpay import Contact
### Calculate Commission
```python
from slickpay import Transfer
userTransfer = Transfer()
userTransfer = Transfer(client=api_client)
res=userTransfer.calculateCommission(amount)
return res
```
Expand Down Expand Up @@ -189,7 +209,7 @@ from slickpay import Transfer
### Calculate Commission
```python
from slickpay import PaymentAggregation
userPaymentAggregation = PaymentAggregation()
userPaymentAggregation = PaymentAggregation(client=api_client)
data = {
"type": "percentage",
"total": 10000,
Expand Down Expand Up @@ -266,7 +286,7 @@ from slickpay import PaymentAggregation
### Calculate Commission
```python
from slickpay import InvoiceTransfer
userInvoiceTransfer = InvoiceTransfer()
userInvoiceTransfer = InvoiceTransfer(client=api_client)
res=userInvoiceTransfer.calculateCommissionInvoice(amount)
return res
```
Expand Down Expand Up @@ -314,4 +334,4 @@ from slickpay import InvoiceTransfer
```
# More help
- [Slick-Pay website](https://slick-pay.com/)
- [devapi-slick-pay](https://www.devapi.slick-pay.com/)
- [devapi-slick-pay](https://www.devapi.slick-pay.com/)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='slick-pay',
packages=['slick-pay'], # Chose the same as "name"
version='0.3', # Start with a small number and increase it with every change you make
version='0.4', # Start with a small number and increase it with every change you make
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
description='slick-pay Gateway (Python Library)', # Give a short description about your library
author='Rahim', # Type in your name
Expand Down
2 changes: 1 addition & 1 deletion slickpay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from slickpay.user import Transfer
from slickpay.user import PaymentAggregation
from slickpay.user import InvoiceTransfer

from slickpay.client import SlickPayApi
58 changes: 58 additions & 0 deletions slickpay/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import requests

API_VERSION = "v2"
DEV_API_URL = "https://www.devapi.slick-pay.com/api/"
PROD_API_URL = "https://www.prodapi.slick-pay.com/api/"


class SlickPayApi:
def __init__(self) -> None:
self.api_version = API_VERSION
self._config = {}

def config(self, environment, public_key):
if environment in ["dev", "prod"]:
self._config["public_key"] = public_key

if environment == "dev":
self._config["base_url"] = DEV_API_URL

if environment == "prod":
self._config["base_url"] = PROD_API_URL

return self._config

def build_request_url(self, url_path):
return f'{self._config["base_url"]}{self.api_version}/{url_path}'

@property
def headers(self):
if self._config:
return {
"Authorization": f'Bearer {self._config["public_key"]}',
"Accept": "application/json",
}

def post(self, url_path, data):
request_url = self.build_request_url(url_path=url_path)
if self.headers:
response = requests.post(url=request_url, headers=self.headers, json=data)
return response.json()

def get(self, url_path):
request_url = self.build_request_url(url_path=url_path)
if self.headers:
response = requests.get(url=request_url, headers=self.headers)
return response.json()

def put(self, url_path, data):
request_url = self.build_request_url(url_path=url_path)
if self.headers:
response = requests.put(url=request_url, headers=self.headers, json=data)
return response.json()

def delete(self, url_path):
request_url = self.build_request_url(url_path=url_path)
if self.headers:
response = requests.delete(url=request_url, headers=self.headers)
return response.json()
70 changes: 17 additions & 53 deletions slickpay/merchant.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,28 @@
import os

import requests
from dotenv import load_dotenv

load_dotenv()


class InvoiceTransferMerchant:
def __init__(self, client) -> None:
self.client = client

def createInvoice(self, data):
print(self)
if os.environ["sandbox"]:
url = 'https://www.devapi.slick-pay.com/api/v2/merchants/invoices'
else:
url = 'https://www.prodapi.slick-pay.com/api/v2/merchants/invoices'
headers = {"Authorization": f'{str(os.environ["public_key"])}', "Accept": "application/json"}
res = requests.post(url, headers=headers, json=data)
body = res.json()
return body
url = "merchants/invoices"
response = self.client.post(url_path=url, data=data)
return response

def invoiceDetail(self, uid):
print(self)
if os.environ["sandbox"]:
url = f'https://www.devapi.slick-pay.com/api/v2/merchants/invoices/{int(uid)}'
else:
url = f'https://www.prodapi.slick-pay.com/api/v2/merchants/invoices/{int(uid)}'
headers = {"Authorization": f'{str(os.environ["public_key"])}', "Accept": "application/json"}
res = requests.get(url, headers=headers)

return res.json()
url = f"invoices/{int(uid)}"
response = self.client.get(url_path=url)
return response

def listInvoice(self, offset, page):
print(self)
if os.environ["sandbox"]:
url = f'https://www.devapi.slick-pay.com/api/v2/merchants/invoices?offset={int(offset)}&page={int(page)}'
else:
url = f'https://www.prodapi.slick-pay.com/api/v2/merchants/invoices?offset={int(offset)}&page={int(page)}'
headers = {"Authorization": f'{str(os.environ["public_key"])}', "Accept": "application/json"}
res = requests.get(url, headers=headers)

return res.json()
url = f"merchants/invoices?offset={int(offset)}&page={int(page)}"
response = self.client.get(url_path=url)
return response

def updateInvoice(self, data, uid):
print(self)
if os.environ["sandbox"]:
url = f'https://www.devapi.slick-pay.com/api/v2/merchants/invoices/{int(uid)}'
else:
url = f'https://www.prodapi.slick-pay.com/api/v2/merchants/invoices/{int(uid)}'
headers = {"Authorization": f'{str(os.environ["public_key"])}', "Accept": "application/json"}
res = requests.put(url, headers=headers, json=data)

return res.json()
url = f"merchants/invoices/{int(uid)}"
response = self.client.put(url_path=url, data=data)
return response

def deleteInvoice(self, uid):
print(self)
if os.environ["sandbox"]:
url = f'https://www.devapi.slick-pay.com/api/v2/merchants/invoices/{int(uid)}'
else:
url = f'https://www.prodapi.slick-pay.com/api/v2/merchants/invoices/{int(uid)}'
headers = {"Authorization": f'{str(os.environ["public_key"])}', "Accept": "application/json"}
res = requests.delete(url, headers=headers)

return res.json()
url = f"merchants/invoices/{int(uid)}"
response = self.client.delete(url_path=url)
return response
Loading