Skip to content

Commit f410aaa

Browse files
committed
Created some model files in settlement, created setup, added docstrings in invoice and added relative imports
1 parent 02dbb99 commit f410aaa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+377
-57
lines changed

setup.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import setuptools
2+
setuptools.setup(
3+
name="bitpay",
4+
package_dir={"": "src"},
5+
packages=setuptools.find_packages(where="src"),
6+
version="2.0.0",
7+
description="Accept bitcoin with BitPay",
8+
author="Antonio Buedo",
9+
author_email="[email protected]",
10+
url="https://github.com/bitpay/python-bitpay-client",
11+
download_url="",
12+
keywords=["bitcoin", "payments", "crypto", "cash", "ethereum", "online payments"],
13+
python_requires=">=3.0",
14+
install_requires=["requests", "ecdsa"],
15+
classifiers=[
16+
'Programming Language :: Python :: 3.8',
17+
"Development Status :: 5 - Production/Stable",
18+
'Intended Audience :: Developers',
19+
'Natural Language :: English',
20+
"Environment :: Web Environment",
21+
"Intended Audience :: Developers",
22+
"License :: OSI Approved :: MIT License",
23+
"Operating System :: OS Independent",
24+
"Topic :: Software Development :: Libraries :: Python Modules",
25+
"Topic :: Office/Business :: Financial"
26+
],
27+
long_description="""\
28+
Python Library for integrating with BitPay
29+
30+
This library is a simple way to integrate your application with
31+
BitPay for taking Bitcoin payments. It exposes three basic
32+
functions, authenticating with BitPay, creating invoices,
33+
and retrieving invoices. It is not meant as a replacement for
34+
the entire BitPay API. However, the key_utils module contains
35+
all of the tools you need to use the BitPay API for other
36+
purposes.
37+
38+
This version requires only Python 3.8.
39+
""",
40+
long_description_content_type='text/markdown'
41+
)

src/bitpay_sdk/__init__.py

Whitespace-only changes.

src/bitpay_sdk/client.py

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33

44
from .config import Config
5+
from .exceptions.invoice_creation_exception import InvoiceCreationException
56
from .tokens import Tokens
67
from .models.facade import Facade
78
from .models.bill.bill import Bill
@@ -30,6 +31,13 @@
3031

3132

3233
class Client:
34+
"""
35+
* Class Client
36+
* @package Bitpay
37+
* @author Antonio Buedo
38+
* @version 1.0.0
39+
* See bitpay.com/api for more information.
40+
"""
3341
__configuration = None
3442
__env = None
3543
__ec_key = None
@@ -150,23 +158,46 @@ def get_access_token(self, key: str):
150158
# ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
151159

152160
def create_invoice(self, invoice: Invoice, facade: str = Facade.Merchant, sign_request: bool = True) -> Invoice:
161+
"""
162+
Create a BitPay invoice
163+
164+
:param Invoice invoice: An Invoice object with request parameters defined
165+
:param str facade: The facade used to create it
166+
:param str sign_request: Signed request
167+
:return: A BitPay generated Invoice object
168+
:rtype: Invoice
169+
:raises BitPayException
170+
:raises InvoiceCreationException
171+
"""
153172
try:
154173
invoice.set_token(self.get_access_token(facade))
155174
invoice_json = invoice.to_json()
156175
response_json = self.__restcli.post("invoices", invoice_json, sign_request)
157176
except BitPayException as e:
158-
raise InvoiceQueryException("failed to serialize Invoice object : %s" % str(e), e.get_api_code())
177+
raise InvoiceCreationException("failed to serialize Invoice object : %s" % str(e), e.get_api_code())
159178
except Exception as e:
160-
raise InvoiceQueryException("failed to serialize Invoice object : %s" % str(e))
179+
raise InvoiceCreationException("failed to serialize Invoice object : %s" % str(e))
161180

162181
try:
163182
invoice = Invoice(**response_json)
164183
except Exception as e:
165-
raise InvoiceQueryException("failed to deserialize BitPay server response (Invoice) : %s" % str(e))
184+
raise InvoiceCreationException("failed to deserialize BitPay server response (Invoice) : %s" % str(e))
166185

167186
return invoice
168187

169188
def get_invoice(self, invoice_id: str, facade: str = Facade.Merchant, sign_request: bool = True) -> Invoice:
189+
"""
190+
Retrieve a BitPay invoice by invoice id using the specified facade. The client must have been previously
191+
authorized for the specified facade (the public facade requires no authorization)
192+
193+
:param str invoice_id: The id of the invoice to retrieve
194+
:param str facade: The facade used to create it
195+
:param bool sign_request: Signed request
196+
:return: A BitPay Invoice object
197+
:rtype: Invoice
198+
:raises BitPayException
199+
:raises InvoiceQueryException
200+
"""
170201
try:
171202
params = {"token": self.get_access_token(facade)}
172203
response_json = self.__restcli.get("invoices/%s" % invoice_id, params, sign_request)
@@ -184,6 +215,20 @@ def get_invoice(self, invoice_id: str, facade: str = Facade.Merchant, sign_reque
184215

185216
def get_invoices(self, date_start: str, date_end: str, status: str = None, order_id: str = None, limit: int = None,
186217
offset: int = None) -> [Invoice]:
218+
"""
219+
Retrieve a collection of BitPay invoices.
220+
221+
:param str date_start: The first date for the query filter.
222+
:param str date_end: The last date for the query filter.
223+
:param str status: The invoice status you want to query on.
224+
:param str order_id: The optional order id specified at time of invoice creation.
225+
:param int limit: Maximum results that the query will return (useful for paging results).
226+
:param int offset: Number of results to offset (ex. skip 10 will give you results starting with the 11th
227+
:return: A list of BitPay Invoice objects.
228+
:rtype: [Invoice]
229+
:raises BitPayException
230+
:raises InvoiceQueryException
231+
"""
187232
try:
188233
params = {"token": self.get_access_token(Facade.Merchant), "dateStart": date_start, "date_end": date_end}
189234
if status:
@@ -211,6 +256,16 @@ def get_invoices(self, date_start: str, date_end: str, status: str = None, order
211256
return invoices
212257

213258
def update_invoice(self, invoice_id: str, buyer_email: str) -> Invoice:
259+
"""
260+
Update a BitPay invoice with communication method.
261+
262+
:param str invoice_id: The id of the invoice to updated.
263+
:param str buyer_email: The buyer's email address.
264+
:return: A BitPay generated Invoice object.
265+
:rtype: Invoice
266+
:raises BitPayException
267+
:raises InvoiceUpdateException
268+
"""
214269
try:
215270
params = {'token': self.get_access_token(Facade.Merchant), 'buyer_email': buyer_email}
216271
response_json = self.__restcli.update("invoices/%s" % invoice_id, params)
@@ -227,6 +282,15 @@ def update_invoice(self, invoice_id: str, buyer_email: str) -> Invoice:
227282
return invoice
228283

229284
def cancel_invoice(self, invoice_id: str) -> Invoice:
285+
"""
286+
Delete a previously created BitPay invoice.
287+
288+
:param str invoice_id: The Id of the BitPay invoice to be canceled.
289+
:return: A BitPay generated Invoice object.
290+
:rtype: Invoice
291+
:raises BitPayException
292+
:raises InvoiceCancellationException
293+
"""
230294
try:
231295
params = {'token': self.get_access_token(Facade.Merchant)}
232296
response_json = self.__restcli.delete("invoices/%s" % invoice_id, params)
@@ -243,6 +307,15 @@ def cancel_invoice(self, invoice_id: str) -> Invoice:
243307
return invoice
244308

245309
def request_invoice_notifications(self, invoice_id: str) -> bool:
310+
"""
311+
Request a BitPay Invoice Webhook.
312+
313+
:param str invoice_id: A BitPay invoice ID.
314+
:return: True if the webhook was successfully requested, false otherwise.
315+
:rtype: bool
316+
:raises BitPayException
317+
:raises InvoiceNotificationException
318+
"""
246319
try:
247320
invoice = self.get_invoice(invoice_id)
248321
except Exception as e:

src/bitpay_sdk/env.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Test="Test"
2+
Prod="Prod"
3+
TestUrl="https://test.bitpay.com/"
4+
ProdUrl="https://bitpay.com/"
5+
BitpayApiVersion="2.0.0"
6+
BitpayPluginInfo="BitPay_Python_Client_v6.0.2111"
7+
BitpayApiFrame="std"
8+
BitpayApiFrameVersion="1.0.0"

src/bitpay_sdk/exceptions/__init__.py

Whitespace-only changes.

src/bitpay_sdk/exceptions/bill_creation_exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from src.bitpay_sdk.exceptions.bill_exception import BillException
1+
from .bill_exception import BillException
22

33

44
class BillCreationException(BillException):

src/bitpay_sdk/exceptions/bill_delivery_exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from src.bitpay_sdk.exceptions.bill_exception import BillException
1+
from .bill_exception import BillException
22

33

44
class BillDeliveryException(BillException):

src/bitpay_sdk/exceptions/bill_query_exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from src.bitpay_sdk.exceptions.bill_exception import BillException
1+
from .bill_exception import BillException
22

33

44
class BillQueryException(BillException):

src/bitpay_sdk/exceptions/bill_update_exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from src.bitpay_sdk.exceptions.bill_exception import BillException
1+
from .bill_exception import BillException
22

33

44
class BillUpdateException(BillException):

src/bitpay_sdk/exceptions/bitpay_exception.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
class BitPayException(Exception):
42
__bitpay_message = "Unexpected Bitpay exception."
53
__bitpay_code = "BITPAY-GENERIC";

0 commit comments

Comments
 (0)