Skip to content

Commit 331f2b1

Browse files
authored
Merge pull request #37 from mwarzybok-sumoheavy/feature/SP-656
Feature/sp 656
2 parents cb686d7 + f64e8ef commit 331f2b1

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

src/bitpay/client.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ def create_pos_client(self, pos_token: str, environment: Environment = Environme
8181
return Client(bitpay_client, token_container, GuidGenerator())
8282

8383
@staticmethod
84-
def create_client_by_private_key( # type: ignore
85-
private_key: str,
84+
def create_client( # type: ignore
85+
private_key_or_private_key_path: str,
8686
token_container: TokenContainer,
8787
environment: Environment = Environment.PROD,
8888
proxy: Optional[str] = None,
8989
):
9090
try:
9191
base_url = Client.get_base_url(environment)
92-
ec_key = Client.get_ec_key(private_key)
92+
ec_key = Client.get_ec_key(private_key_or_private_key_path)
9393
bitpay_client = BitPayClient(base_url, ec_key, proxy)
9494
guid_generator = GuidGenerator()
9595

@@ -103,42 +103,44 @@ def create_client_by_config_file_path(config_file_path: str): # type: ignore
103103
raise BitPayException("Configuration file not found")
104104

105105
try:
106-
read_file = open(config_file_path, "r")
107-
json_data = json.loads(read_file.read())
106+
with open(config_file_path, "r") as read_file:
107+
json_data = json.loads(read_file.read())
108108

109109
environment = json_data["BitPayConfiguration"]["Environment"]
110110
config = json_data["BitPayConfiguration"]["EnvConfig"][environment]
111111
proxy = config["proxy"]
112-
ec_key = config["PrivateKey"]
112+
private_key_path = config["PrivateKeyPath"]
113+
if private_key_path is None:
114+
private_key_or_private_key_path = config["PrivateKey"]
115+
else:
116+
private_key_or_private_key_path = private_key_path
117+
113118
token_container = TokenContainer()
114119
token_container.add_pos(config["ApiTokens"].get("pos", None))
115120
token_container.add_merchant(config["ApiTokens"].get("merchant", None))
116121
token_container.add_payout(config["ApiTokens"].get("payout", None))
117-
read_file.close()
118122

119123
if "test" == environment.lower():
120124
environment = Environment.TEST
121125
else:
122126
environment = Environment.PROD
123127

124-
return Client.create_client_by_private_key(
125-
ec_key, token_container, environment, proxy
128+
return Client.create_client(
129+
private_key_or_private_key_path, token_container, environment, proxy
126130
)
127131
except Exception as exe:
128132
raise BitPayException("Error when reading configuration file. " + str(exe))
129133

130134
@staticmethod
131-
def get_ec_key(private_key: Optional[str]) -> str:
132-
if private_key is None:
135+
def get_ec_key(private_key_or_private_key_path: Optional[str]) -> str:
136+
if private_key_or_private_key_path is None:
133137
raise BitPayException("Private Key file not found")
134138

135-
if os.path.exists(private_key):
136-
read_file = open(private_key, "r")
137-
plain_private_key = read_file.read()
138-
read_file.close()
139-
return plain_private_key
139+
if os.path.exists(private_key_or_private_key_path):
140+
with open(private_key_or_private_key_path, "r") as read_file:
141+
return read_file.read()
140142

141-
return private_key
143+
return private_key_or_private_key_path
142144

143145
@staticmethod
144146
def get_base_url(environment: Environment) -> str:

src/bitpay/models/settlement/refund_info.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class RefundInfo:
1515
__support_request = None
1616
__currency = None
1717
__amounts = None
18+
__refund_request_eid = None
1819

1920
def __init__(self, **kwargs: dict) -> None:
2021
for key, value in kwargs.items():
@@ -66,6 +67,20 @@ def set_amounts(self, amounts: Optional[dict]) -> None:
6667
"""
6768
self.__amounts = amounts
6869

70+
def get_refund_request_eid(self) -> Optional[str]:
71+
"""
72+
Get refund request eid
73+
:return: refund request eid
74+
"""
75+
return self.__refund_request_eid
76+
77+
def set_refund_request_eid(self, value: Optional[str]) -> None:
78+
"""
79+
Set refund request eid
80+
:return: refund request eid
81+
"""
82+
self.__refund_request_eid = value
83+
6984
def to_json(self) -> dict:
7085
"""
7186
:return: data in json

tests/unit/models/settlement/test_refund_info.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,12 @@ def test_modify_amounts():
4242
refund_info.set_amounts(value)
4343

4444
assert refund_info.get_amounts() == value
45+
46+
47+
@pytest.mark.unit
48+
def test_refund_request_eid():
49+
refund_info = RefundInfo()
50+
value = "someValue"
51+
refund_info.set_refund_request_eid(value)
52+
53+
assert refund_info.get_refund_request_eid() == value

0 commit comments

Comments
 (0)