Skip to content

Commit 6765666

Browse files
committed
first push
0 parents  commit 6765666

11 files changed

Lines changed: 273 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
env/

License.txt

Whitespace-only changes.

README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
</p>
2+
# Lazerpay v1 Python SDK
3+
4+
### How to use
5+
6+
`pip install lazerpay-python-sdk`
7+
8+
```python
9+
from lazerpay.resource import LazerPayClient
10+
11+
lazerpay = LazerPayClient(pubKey=LAZER_PUBLIC_KEY, secretKey=LAZER_SECRET_KEY)
12+
```
13+
14+
For staging, Use TEST API Keys and for production, use LIVE API KEYS.
15+
You can get your LAZER_PUBLIC_KEYS from the Lazerpay dashboard.
16+
17+
## Lazerpay Methods exposed by the sdk
18+
19+
**1**. **PAYMENT**
20+
21+
* Initialize Payment
22+
* Confirm Payments
23+
24+
#### `Initialize Payment`
25+
26+
This describes to allow your customers to initiate a crypto payment transfer.
27+
28+
```python
29+
from lazerpay.resource import LazerPayClient
30+
31+
lazerpay = LazerPayClient(pubKey=LAZER_PUBLIC_KEY, secretKey=LAZER_SECRET_KEY)
32+
33+
34+
try:
35+
response = lazerpay.initTransaction(
36+
reference="YOUR_REFERENCE", # Replace with a reference you generated
37+
amount="10",
38+
customer_name="Njoku Emmanuel",
39+
customer_email="kalunjoku123@gmail.com",
40+
coin="USDC",
41+
currency="NGN",
42+
accept_partial_payment=True # By default, it's false
43+
)
44+
except Exception as e:
45+
raise e
46+
```
47+
48+
#### `Confirm Payment`
49+
50+
This describes to allow you confirm your customers transaction after payment has been made.
51+
52+
```python
53+
from lazerpay.resource import LazerPayClient
54+
55+
lazerpay = LazerPayClient(pubKey=LAZER_PUBLIC_KEY, secretKey=LAZER_SECRET_KEY)
56+
57+
try:
58+
response = lazerpay.confirmPayment(
59+
identifier="address generated or the reference generated by you from initializing payment"
60+
)
61+
except Exception as e:
62+
raise e
63+
```
64+
65+
#### `Get Accepted Coins`
66+
67+
This gets the list of accepted cryptocurrencies on Lazerpay
68+
69+
```python
70+
from lazerpay.resource import LazerPayClient
71+
72+
lazerpay = LazerPayClient(pubKey=LAZER_PUBLIC_KEY, secretKey=LAZER_SECRET_KEY)
73+
74+
try:
75+
response = lazerpay.getAcceptedCoins()
76+
except Exception as e:
77+
raise e
78+
```
79+
80+
#### `Payout`
81+
82+
Payout funds to an address
83+
84+
```python
85+
from lazerpay.resource import LazerPayClient
86+
87+
lazerpay = LazerPayClient(pubKey=LAZER_PUBLIC_KEY, secretKey=LAZER_SECRET_KEY)
88+
89+
try:
90+
response = lazerpay.payout(amount=1,
91+
recipient="0x0B4d358D349809037003F96A3593ff9015E89efA",
92+
coin="BUSD",
93+
blockchain="Binance Smart Chain"
94+
)
95+
except Exception as e:
96+
raise e
97+
```

lazerpay/__init__.py

Whitespace-only changes.

lazerpay/resource.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import json
2+
import requests
3+
4+
from .utils.constants import (API_URL_INIT_TRANSACTION, API_URL_GET_ACCEPTED_COINS,
5+
API_URL_CONFIRM_TRANSACTION, API_URL_TRANSFER_FUNDS
6+
)
7+
8+
9+
class LazerPayClient():
10+
11+
"""
12+
Base Resource Client
13+
"""
14+
15+
def __init__(self, pubKey, secretKey):
16+
self.pubKey = pubKey
17+
self.secretKey = secretKey
18+
self.headers = {"Content-Type":"Application/json", "x-api-key": self.pubKey}
19+
20+
def __to_format(self, response):
21+
if type(response) == "json":
22+
return response.json()
23+
else:
24+
return response.content
25+
26+
def __get_data(self, url, headers=None):
27+
return self.__to_format(requests.get(url, headers=headers or self.headers))
28+
29+
def __post_data(self, url, data, headers=None):
30+
return self.__to_format(requests.post(url, data=json.dumps(data), headers=headers or self.headers))
31+
32+
33+
34+
35+
def initTransaction(self, reference, amount, customer_name, customer_email, coin, currency, accept_partial_payment=False):
36+
"""
37+
Initiate a crypto payment transfer.
38+
39+
Attributes:
40+
reference (string): unique transaction reference
41+
amount (string): fiat amount
42+
customer_name (string): Customer's name
43+
customer_email (string): Customer's email
44+
coin (string): Coin
45+
currency (string): Currency
46+
accept_partial_payment (boolean):
47+
48+
Returns:
49+
reponse dict from Lazerpay
50+
"""
51+
52+
data = {"reference": reference, "amount": amount, "customer_name":customer_name, "customer_email": customer_email,
53+
"coin": coin, "currency": currency, "accept_partial_payment": accept_partial_payment
54+
}
55+
return self.__post_data(url=API_URL_INIT_TRANSACTION, data=data)
56+
57+
def getAcceptedCoins(self):
58+
"""
59+
Gets the list of accepted cryptocurrencies on Laz
60+
"""
61+
return self.__get_data(url=API_URL_GET_ACCEPTED_COINS)
62+
63+
def confirmPayment(self, identifier):
64+
"""
65+
Confirm your customer's transaction after payment has been made.
66+
"""
67+
return self.__get_data(url=f'{API_URL_CONFIRM_TRANSACTION}/{identifier}')
68+
69+
def payout(self, amount, recipient, coin, blockchain):
70+
"""
71+
Pay
72+
73+
Attributes:
74+
amount (int):
75+
recipient (string):
76+
coin (string):
77+
blockchain (string):
78+
79+
Returns:
80+
reponse dict from Lazerpay
81+
"""
82+
83+
data = {"amount": amount, "recipient": recipient, "coin": coin, "blockchain": blockchain}
84+
self.headers["Authorization"] = f"Bearer {self.secretKey}"
85+
return self.__post_data(url=API_URL_TRANSFER_FUNDS, data=data, headers=self.headers)

lazerpay/utils/__init__.py

Whitespace-only changes.

lazerpay/utils/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
API_URL = 'https://api.lazerpay.engineering/api/v1'
2+
3+
API_URL_INIT_TRANSACTION = f'{API_URL}/transaction/initialize'
4+
API_URL_CONFIRM_TRANSACTION = f'{API_URL}/transaction/verify'
5+
API_URL_GET_ACCEPTED_COINS = f'{API_URL}/coins'
6+
API_URL_TRANSFER_FUNDS = f'{API_URL}/transfer'

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
certifi==2021.10.8
2+
charset-normalizer==2.0.12
3+
idna==3.3
4+
requests==2.27.1
5+
urllib3==1.26.8

setup.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from distutils.core import setup
2+
setup(
3+
name = 'lazerpay-python-sdk', # How you named your package folder (MyLib)
4+
packages = ['lazerpay-python-sdk'], # Chose the same as "name"
5+
version = '0.1', # Start with a small number and increase it with every change you make
6+
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
7+
description = 'API Wrapper for LazerPay', # Give a short description about your library
8+
author = 'John Shodipo', # Type in your name
9+
author_email = 'newtonjohn043@gmail.com', # Type in your E-Mail
10+
url = 'https://github.com/johnkayode/lazerpay-python-sdk', # Provide either the link to your github or to your website
11+
download_url = 'https://github.com/johnkayode/lazerpay-python-sdk/archive/v_01.tar.gz', # I explain this later on
12+
keywords = ['lazerpay', 'python', 'crypto'], # Keywords that define your package best
13+
install_requires=[ # I get to this in a second
14+
'validators',
15+
'beautifulsoup4',
16+
],
17+
classifiers=[
18+
'Development Status :: 3 - Alpha', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
19+
'Intended Audience :: Developers', # Define that your audience are developers
20+
'Topic :: Software Development :: Build Tools',
21+
'License :: OSI Approved :: MIT License', # Again, pick a license
22+
'Programming Language :: Python :: 3', #Specify which pyhton versions that you want to support
23+
'Programming Language :: Python :: 3.6',
24+
'Programming Language :: Python :: 3.7',
25+
'Programming Language :: Python :: 3.8',
26+
],
27+
)

test/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)