├── .gitignore ├── License.txt ├── MANIFEST ├── README.md ├── lazerpay ├── __init__.py ├── resource.py └── utils │ ├── __init__.py │ └── constants.py ├── requirements.txt ├── setup.cfg ├── setup.py └── test ├── __init__.py └── test_transactions.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | Copyright (c) 2018 YOUR NAME 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | The above copyright notice and this permission notice shall be included in all 10 | copies or substantial portions of the Software. 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17 | SOFTWARE. -------------------------------------------------------------------------------- /MANIFEST: -------------------------------------------------------------------------------- 1 | # file GENERATED by distutils, do NOT edit 2 | setup.cfg 3 | setup.py 4 | lazerpay/__init__.py 5 | lazerpay/resource.py 6 | lazerpay/utils/__init__.py 7 | lazerpay/utils/constants.py 8 | test/test_transactions.py 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

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: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Johnkayode/lazerpay-python-sdk/37a15d368494fc0054283eef24bfd72a83ff64d6/lazerpay/__init__.py -------------------------------------------------------------------------------- /lazerpay/resource.py: -------------------------------------------------------------------------------- 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: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Johnkayode/lazerpay-python-sdk/37a15d368494fc0054283eef24bfd72a83ff64d6/lazerpay/utils/__init__.py -------------------------------------------------------------------------------- /lazerpay/utils/constants.py: -------------------------------------------------------------------------------- 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: -------------------------------------------------------------------------------- 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 6 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | # Inside of setup.cfg 2 | [metadata] 3 | description-file = README.md -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | setup( 3 | name = 'lazerpay-python-sdk', # How you named your package folder (MyLib) 4 | packages = ['lazerpay','lazerpay.utils'], # Chose the same as "name" 5 | version = '0.2', # 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/refs/tags/v_02.zip', # 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 | 'requests', 15 | ], 16 | classifiers=[ 17 | 'Development Status :: 3 - Alpha', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package 18 | 'Intended Audience :: Developers', # Define that your audience are developers 19 | 'Topic :: Software Development :: Build Tools', 20 | 'License :: OSI Approved :: MIT License', # Again, pick a license 21 | 'Programming Language :: Python :: 3', #Specify which pyhton versions that you want to support 22 | 'Programming Language :: Python :: 3.6', 23 | 'Programming Language :: Python :: 3.7', 24 | 'Programming Language :: Python :: 3.8', 25 | ], 26 | ) -------------------------------------------------------------------------------- /test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Johnkayode/lazerpay-python-sdk/37a15d368494fc0054283eef24bfd72a83ff64d6/test/__init__.py -------------------------------------------------------------------------------- /test/test_transactions.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import json 3 | import random 4 | import string 5 | from urllib import response 6 | 7 | from lazerpay.resource import LazerPayClient 8 | 9 | 10 | client = LazerPayClient(pubKey="pk_test_z0XAaAI8LhWzXWPKLVnvZrAlbqvNbfNBtSuDJTWjQDz9Wrq42p", secretKey="sk_test_gYS4TDjQTV8fGuJeMqAWJlS0eHeeFbJkupXJW9wvM9QXSdudox") 11 | 12 | 13 | 14 | class TransactionResourceTest(unittest.TestCase): 15 | """ 16 | TestCase class for the Lazerpay SDK. 17 | """ 18 | 19 | def setUp(self): 20 | self.client = LazerPayClient(pubKey="pk_test_z0XAaAI8LhWzXWPKLVnvZrAlbqvNbfNBtSuDJTWjQDz9Wrq42p", secretKey="sk_test_gYS4TDjQTV8fGuJeMqAWJlS0eHeeFbJkupXJW9wvM9QXSdudox") 21 | self.reference = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) 22 | 23 | def test_initTransaction(self): 24 | response = json.loads(self.client.initTransaction( 25 | reference=self.reference, # Replace with a reference you generated 26 | amount="10", 27 | customer_name="Njoku Emmanuel", 28 | customer_email="kalunjoku123@gmail.com", 29 | coin="USDC", 30 | currency="NGN", 31 | accept_partial_payment=True # By default, it's false 32 | )) 33 | self.assertEqual(response["statusCode"], 201) 34 | 35 | def test_getAcceptedCoins(self): 36 | response = json.loads(self.client.getAcceptedCoins()) 37 | self.assertEqual(response["status"], "success") 38 | 39 | def test_confirmPayment(self): 40 | response = json.loads(self.client.confirmPayment( 41 | identifier=self.reference 42 | )) 43 | self.assertEqual(response["statusCode"], 404) 44 | 45 | def test_payout(self): 46 | response = json.loads(self.client.payout(amount=1, 47 | recipient="0x0B4d358D349809037003F96A3593ff9015E89efA", 48 | coin="BUSD", 49 | blockchain="Binance Smart Chain" 50 | )) 51 | # Insufficient balance 52 | self.assertEqual(response["statusCode"], 400) --------------------------------------------------------------------------------