Skip to content

Commit c3ac659

Browse files
committed
Added requirements,travis and improved code quality
1 parent ed2bf9b commit c3ac659

Some content is hidden

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

55 files changed

+596
-283
lines changed

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: python
2+
python:
3+
- "3.7"
4+
- "3.8"
5+
- "3.9"
6+
- "3.9-dev"
7+
- "nightly" # nightly build
8+
# command to install dependencies
9+
install:
10+
- pip install -r requirements.txt
File renamed without changes.

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ecdsa==0.17.0
2+
requests==2.27.1
3+

setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Setup file
33
"""
44
import setuptools
5+
56
setuptools.setup(
67
name="bitpay",
78
package_dir={"": "src"},
@@ -16,16 +17,16 @@
1617
python_requires=">=3.7",
1718
install_requires=["requests", "ecdsa"],
1819
classifiers=[
19-
'Programming Language :: Python :: 3.7, 3.8, 3.9, 3.10',
20+
"Programming Language :: Python :: 3.7, 3.8, 3.9, 3.10",
2021
"Development Status :: 5 - Production/Stable",
21-
'Intended Audience :: Developers',
22-
'Natural Language :: English',
22+
"Intended Audience :: Developers",
23+
"Natural Language :: English",
2324
"Environment :: Web Environment",
2425
"Intended Audience :: Developers",
2526
"License :: OSI Approved :: MIT License",
2627
"Operating System :: OS Independent",
2728
"Topic :: Software Development :: Libraries :: Python Modules",
28-
"Topic :: Office/Business :: Financial"
29+
"Topic :: Office/Business :: Financial",
2930
],
3031
long_description="""\
3132
Python Library for integrating with BitPay
@@ -40,5 +41,5 @@
4041
4142
This version requires only Python 3.8.
4243
""",
43-
long_description_content_type='text/markdown'
44+
long_description_content_type="text/markdown",
4445
)

setup/bitpay_setup.py

Lines changed: 63 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from src.bitpay.exceptions.bitpay_exception import BitPayException
1212

1313
# Will be set to Test otherwise
14-
private_key_name = 'private_key.pem' # Add here the name for your Private key
14+
private_key_name = "private_key.pem" # Add here the name for your Private key
1515
private_key_path = os.path.join(os.path.abspath(os.curdir), private_key_name)
1616
plain_private_key = None
1717
proxy = None
@@ -25,12 +25,12 @@ def select_env():
2525
global environment
2626
try:
2727
print("Select target environment: ")
28-
target_environment = input('Press T for testing or P for production: \n')
28+
target_environment = input("Press T for testing or P for production: \n")
2929

30-
if target_environment.lower() == 't':
31-
environment = 'Test'
32-
elif target_environment.lower() == 'p':
33-
environment = 'Prod'
30+
if target_environment.lower() == "t":
31+
environment = "Test"
32+
elif target_environment.lower() == "p":
33+
environment = "Prod"
3434
else:
3535
select_env()
3636

@@ -42,16 +42,18 @@ def select_env():
4242

4343
def set_environment(env):
4444
global api_url
45-
if env == 'Test':
46-
api_url = 'https://test.bitpay.com'
45+
if env == "Test":
46+
api_url = "https://test.bitpay.com"
4747
else:
48-
api_url = 'https://bitpay.com'
48+
api_url = "https://bitpay.com"
4949

5050

5151
def select_create_key():
5252
try:
53-
input_value = input('Press enter to generate a brand new key or enter your private key location:')
54-
if input_value == '':
53+
input_value = input(
54+
"Press enter to generate a brand new key or enter your private key location:"
55+
)
56+
if input_value == "":
5557
create_new_key()
5658
else:
5759
load_key()
@@ -71,15 +73,17 @@ def store_key(private_key):
7173
global plain_private_key, private_key_path
7274
try:
7375
print("Select the way you want to store your private key:")
74-
input_value = input("Press F for storing in a pem file or T for plain text in your config file: ")
76+
input_value = input(
77+
"Press F for storing in a pem file or T for plain text in your config file: "
78+
)
7579

76-
if input_value.lower() == 'f':
80+
if input_value.lower() == "f":
7781
with open(str(private_key_path), "wb") as f:
7882
f.write(private_key.encode())
7983
plain_private_key = None
8084
print("Private key saved at path:", private_key_path)
8185
select_tokens(private_key)
82-
elif input_value.lower() == 't':
86+
elif input_value.lower() == "t":
8387
plain_private_key = private_key
8488
private_key_path = None
8589
print("Saving private key... \n")
@@ -93,8 +97,8 @@ def store_key(private_key):
9397
def select_tokens(private_key):
9498
try:
9599
print("Select the tokens that you would like to request:")
96-
input_value = input('Press M for merchant, P for payout, or B for both: \n')
97-
if input_value.lower() in ['m', 'p', 'b']:
100+
input_value = input("Press M for merchant, P for payout, or B for both: \n")
101+
if input_value.lower() in ["m", "p", "b"]:
98102
print("Requesting Tokens... \n")
99103
request_tokens(input_value.lower(), private_key)
100104
else:
@@ -112,27 +116,37 @@ def request_tokens(token_type, private_key):
112116
url = "%s/tokens" % api_url
113117
headers = {"content-type": "application/json", "X-accept-version": "2.0.0"}
114118

115-
if token_type in ['m', 'b']:
119+
if token_type in ["m", "b"]:
116120
print("Requesting Merchant token... \n")
117-
facade = 'merchant'
118-
payload = {'id': sin, 'facade': facade}
121+
facade = "merchant"
122+
payload = {"id": sin, "facade": facade}
119123

120-
response = requests.post(url, verify=True, data=json.dumps(payload), headers=headers)
124+
response = requests.post(
125+
url, verify=True, data=json.dumps(payload), headers=headers
126+
)
121127
if response.ok:
122-
merchant_token = response.json()['data'][0]['token']
123-
print("Merchant Token: ", response.json()['data'][0]['token'])
124-
print("Merchant Token Pairing Code: ", response.json()['data'][0]['pairingCode'] + "\n")
125-
126-
if token_type in ['p', 'b']:
128+
merchant_token = response.json()["data"][0]["token"]
129+
print("Merchant Token: ", response.json()["data"][0]["token"])
130+
print(
131+
"Merchant Token Pairing Code: ",
132+
response.json()["data"][0]["pairingCode"] + "\n",
133+
)
134+
135+
if token_type in ["p", "b"]:
127136
print("Requesting Payout token... \n")
128-
facade = 'payout'
129-
payload = {'id': sin, 'facade': facade}
137+
facade = "payout"
138+
payload = {"id": sin, "facade": facade}
130139

131-
response = requests.post(url, verify=True, data=json.dumps(payload), headers=headers)
140+
response = requests.post(
141+
url, verify=True, data=json.dumps(payload), headers=headers
142+
)
132143
if response.ok:
133-
payout_token = response.json()['data'][0]['token']
134-
print("Payout Token: ", response.json()['data'][0]['token'])
135-
print("Payout Token Pairing Code: ", response.json()['data'][0]['pairingCode'] + "\n")
144+
payout_token = response.json()["data"][0]["token"]
145+
print("Payout Token: ", response.json()["data"][0]["token"])
146+
print(
147+
"Payout Token Pairing Code: ",
148+
response.json()["data"][0]["pairingCode"] + "\n",
149+
)
136150

137151
update_config_file()
138152
except BitPayException as exe:
@@ -150,23 +164,30 @@ def update_config_file():
150164
"PrivateKey": plain_private_key,
151165
"ApiTokens": {
152166
"merchant": merchant_token,
153-
"payout": payout_token
167+
"payout": payout_token,
154168
},
155-
"proxy": proxy
169+
"proxy": proxy,
156170
}
157-
}
171+
},
158172
}
159173
}
160174

161-
with open(os.path.abspath("bitpay.config.json"), 'w') as outfile:
175+
with open(os.path.abspath("bitpay.config.json"), "w") as outfile:
162176
json.dump(config, outfile)
163-
print('Generated configuration file at path: ', os.path.abspath("bitpay.config.json"))
164-
165-
print('Configuration generated successfully! \n')
166-
print("\r\nPlease, copy the above pairing code/s and approve on your BitPay Account at the following link:\r\n")
177+
print(
178+
"Generated configuration file at path: ",
179+
os.path.abspath("bitpay.config.json"),
180+
)
181+
182+
print("Configuration generated successfully! \n")
183+
print(
184+
"\r\nPlease, copy the above pairing code/s and approve on your BitPay Account at the following link:\r\n"
185+
)
167186
print(f"{api_url}/dashboard/merchant/api-tokens\r\n")
168-
print("\r\nOnce you have this Pairing Code/s approved you can move the generated files to a secure location "
169-
"and start using the Client.\r\n")
187+
print(
188+
"\r\nOnce you have this Pairing Code/s approved you can move the generated files to a secure location "
189+
"and start using the Client.\r\n"
190+
)
170191
except BitPayException as exe:
171192
print(exe)
172193

@@ -176,6 +197,5 @@ def load_key():
176197
pass
177198

178199

179-
if __name__ == '__main__':
200+
if __name__ == "__main__":
180201
select_env()
181-

src/bitpay/models/Rate/rate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def __init__(self, **kwargs):
1717
for key, value in kwargs.items():
1818
try:
1919
getattr(self, "set_%s" % change_camel_case_to_snake_case(key))(value)
20-
except AttributeError as exe:
21-
print(exe)
20+
except AttributeError:
21+
pass
2222

2323
def get_name(self):
2424
"""

src/bitpay/models/Rate/rates.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,35 @@ class Rates:
1717
__rates = None
1818

1919
def __init__(self, rates, b_p, **kwargs):
20-
self.__bp = b_p
21-
self.__rates = rates
20+
self.set_bp(b_p)
21+
self.set_rates(rates)
22+
2223
for key, value in kwargs.items():
2324
try:
2425
getattr(self, "set_%s" % change_camel_case_to_snake_case(key))(value)
25-
except AttributeError as exe:
26-
print(exe)
26+
except AttributeError:
27+
pass
28+
29+
def get_bp(self):
30+
"""
31+
Get method for the bp
32+
:return: bp
33+
"""
34+
return self.__bp
35+
36+
def set_bp(self, b_p):
37+
"""
38+
Set method for the b_p
39+
:param b_p: b_p
40+
"""
41+
self.__bp = b_p
42+
43+
def set_rates(self, rates):
44+
"""
45+
Set method for the rates
46+
:param rates: rates
47+
"""
48+
self.__rates = rates
2749

2850
def get_rates(self):
2951
rates = []

src/bitpay/models/bill/bill.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ class Bill:
2525
__city = None
2626
__state = None
2727
__zip = None
28-
# TODO: Country should not have default value
29-
__country = "US"
28+
__country = None
3029
__cc = None
3130
__delivered = None
3231
__phone = None
@@ -40,9 +39,9 @@ class Bill:
4039
__merchant = None
4140

4241
def __init__(self, number=None, currency=None, email=None, **kwargs):
43-
self.__number = number
44-
self.__currency = currency
45-
self.__email = email
42+
self.set_number(number)
43+
self.set_currency(currency)
44+
self.set_email(email)
4645

4746
for key, value in kwargs.items():
4847
try:
@@ -59,8 +58,8 @@ def __init__(self, number=None, currency=None, email=None, **kwargs):
5958
else:
6059
value = klass(**value)
6160
getattr(self, "set_%s" % change_camel_case_to_snake_case(key))(value)
62-
except AttributeError as exe:
63-
print(exe)
61+
except AttributeError:
62+
pass
6463

6564
def get_currency(self):
6665
"""

src/bitpay/models/bill/item.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def __init__(self, **kwargs):
1818
for key, value in kwargs.items():
1919
try:
2020
getattr(self, "set_%s" % change_camel_case_to_snake_case(key))(value)
21-
except AttributeError as exe:
22-
print(exe)
21+
except AttributeError:
22+
pass
2323

2424
def get_id(self):
2525
"""

src/bitpay/models/currency.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,15 @@ class Currency:
214214
def is_valid(cls, value):
215215
try:
216216
return hasattr(Currency(), value)
217-
except Exception as exe:
217+
except Exception:
218218
return False
219219

220220
def __init__(self, **kwargs):
221221
for key, value in kwargs.items():
222222
try:
223223
getattr(self, "set_%s" % change_camel_case_to_snake_case(key))(value)
224-
except AttributeError as e:
225-
print(e)
224+
except AttributeError:
225+
pass
226226

227227
def get_code(self):
228228
"""

0 commit comments

Comments
 (0)