Skip to content

Commit 360b6b7

Browse files
Format code with autopep8
1 parent d57778e commit 360b6b7

File tree

5 files changed

+31
-27
lines changed

5 files changed

+31
-27
lines changed

paywix/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@
101101
"var6": "instant_refund"
102102
}
103103

104-
}
104+
}

paywix/decorators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from paywix.config import PAYU_CONFIGS
33
from paywix.exceptions import PaywixValidationException
44

5+
56
def validate_params(pg, action):
67
"""
78
validate the function based on the args
@@ -27,5 +28,5 @@ def wrapper(*args, **kwargs):
2728
action
2829
)
2930
return func(*args, **kwargs)
30-
return wrapper
31+
return wrapper
3132
return decorator

paywix/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def __init__(self, *args):
66
f" requested args: {args}"
77
super().__init__(self.message)
88

9+
910
class PaywixValidationException(Exception):
1011

1112
def __init__(self, required_items, missing_items, pg, action):
@@ -16,4 +17,3 @@ def __init__(self, required_items, missing_items, pg, action):
1617
self.message = f" {self.pg} required {self.required_items} to process {self.action}" \
1718
f" requested data missing: {self.missing_items}"
1819
super().__init__(self.message)
19-

paywix/gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ def refund(self, *args, **kwargs):
3737

3838
@abstractmethod
3939
def refund_details(self, *args, **kwargs):
40-
pass
40+
pass

paywix/payu.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
from urllib import parse
88

99

10-
11-
1210
class Payu:
1311

1412
# Hash Sequence for transaction
1513
__HASH_SEQUENCE = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|||||"
1614
__RESPONSE_SEQUENCE = "salt|status||||||udf5|udf4|udf3|udf2|udf1|email|firstname|productinfo|amount|txnid"
1715
__API_HASH_SEQUENCE = "key|command|var1"
16+
1817
def __init__(self, merchant_key, merchant_salt, mode='Test'):
1918

2019
self.key = merchant_key
@@ -40,9 +39,10 @@ def generate_hash(self, *args, **kwargs):
4039
hash_string += ''
4140
hash_string += '|'
4241
hash_string += self.salt
43-
hash_value = hashlib.sha512(hash_string.encode('utf-8')).hexdigest().lower()
42+
hash_value = hashlib.sha512(
43+
hash_string.encode('utf-8')).hexdigest().lower()
4444
logging.info("Hash generation has completed")
45-
return hash_value
45+
return hash_value
4646

4747
def make_html(self, data):
4848
"""
@@ -52,7 +52,7 @@ def make_html(self, data):
5252
request_payload = ['key', 'txnid', 'productinfo',
5353
'amount', 'email', 'firstname', 'lastname', 'surl',
5454
'surl', 'furl', 'phone', 'hash', 'udf1', 'udf2', 'udf3',
55-
'udf4','udf5'
55+
'udf4', 'udf5'
5656
]
5757
for input_val in request_payload:
5858
if data.get(input_val):
@@ -110,7 +110,8 @@ def __generate_response_hash(self, *args, **kwargs):
110110
hash_string += f'{self.key}'
111111
if add_charge:
112112
hash_string = f'{add_charge}|{hash_string}'
113-
generated_hash = hashlib.sha512(hash_string.encode('utf-8')).hexdigest().lower()
113+
generated_hash = hashlib.sha512(
114+
hash_string.encode('utf-8')).hexdigest().lower()
114115
return hash_string, generated_hash
115116

116117
def __error_codes(self, reqstd_code):
@@ -126,7 +127,8 @@ def check_transaction(self, *args, **kwargs):
126127
Verify Transaction from Payu.
127128
Check the payment gateway response.
128129
"""
129-
hash_string, hash_value = self.__generate_response_hash(*args, **kwargs)
130+
hash_string, hash_value = self.__generate_response_hash(
131+
*args, **kwargs)
130132
response_hash = kwargs.get('hash')
131133
hash_response = {
132134
"hash_string": hash_string,
@@ -161,7 +163,8 @@ def __api_hash(self, *args, **kwargs):
161163
for hash_str in hash_seq_list:
162164
hash_string += f"{str(kwargs.get(hash_str, ''))}|"
163165
hash_string += f'{self.salt}'
164-
generated_hash = hashlib.sha512(hash_string.encode('utf-8')).hexdigest().lower()
166+
generated_hash = hashlib.sha512(
167+
hash_string.encode('utf-8')).hexdigest().lower()
165168
return hash_string, generated_hash
166169

167170
def __make_request(self, method="POST", **kwargs):
@@ -176,7 +179,8 @@ def __make_request(self, method="POST", **kwargs):
176179
}
177180
payload = self.__payload_encode(**kwargs)
178181
url = PAYU_CONFIGS[f'api_{self.mode}']
179-
response = requests.request(method, url, data=payload, headers=headers)
182+
response = requests.request(
183+
method, url, data=payload, headers=headers)
180184
return response.json()
181185
except requests.exceptions.HTTPError as http_error:
182186
raise Exception(f"Http Error: {str(http_error)}")
@@ -197,7 +201,8 @@ def verify_payment(self, *args, **kwargs):
197201
reconcile with PayU’s database once you receive the response.
198202
"""
199203
if len(kwargs.get('transaction_id')) == 0:
200-
raise KeyError(" Requested data doesn't contains required field: transaction_id")
204+
raise KeyError(
205+
" Requested data doesn't contains required field: transaction_id")
201206
kwargs['command'] = "verify_payment"
202207
kwargs['var1'] = "|".join(kwargs.pop('transaction_id'))
203208
response = self.__make_request(**kwargs)
@@ -212,7 +217,8 @@ def check_payment(self, *args, **kwargs):
212217
whereas the input parameter in verify_payment API is the TxnID (Transaction ID generated at your end).
213218
"""
214219
if not kwargs.get('payment_id'):
215-
raise KeyError(f" Requested data doesn't contains required field: payment_id")
220+
raise KeyError(
221+
f" Requested data doesn't contains required field: payment_id")
216222
kwargs['command'] = "check_payment"
217223
kwargs['var1'] = kwargs.pop('payment_id')
218224
response = self.__make_request(**kwargs)
@@ -223,13 +229,13 @@ def get_wsonline_response(self, *args, **kwargs):
223229
This API is used to get the transaction response sent on surl/furl.
224230
"""
225231
if not kwargs.get('transaction_id'):
226-
raise KeyError(" Requested data doesn't contains required field: transaction_id")
232+
raise KeyError(
233+
" Requested data doesn't contains required field: transaction_id")
227234
kwargs['command'] = "get_ws_response"
228235
kwargs['var1'] = kwargs.pop('transaction_id')
229236
response = self.__make_request(**kwargs)
230237
return response
231238

232-
233239
def get_transaction_details(self, *args, **kwargs):
234240
"""
235241
This API is used to extract the transaction details between two given time periods.
@@ -243,15 +249,15 @@ def get_transaction_details(self, *args, **kwargs):
243249

244250
for key in ['date_from', 'date_to']:
245251
if not kwargs.get(key):
246-
raise KeyError(f"To get transaction details required parameter is missing {key}")
252+
raise KeyError(
253+
f"To get transaction details required parameter is missing {key}")
247254

248255
kwargs['command'] = "get_Transaction_Details"
249256
kwargs['var1'] = kwargs.pop('date_from')
250257
kwargs['var2'] = kwargs.pop('date_to')
251258
response = self.__make_request(**kwargs)
252259
return response
253260

254-
255261
def get_transaction_info(self, *args, **kwargs):
256262
"""
257263
This API works exactly the same way as get_Transaction_Details API.
@@ -265,16 +271,15 @@ def get_transaction_info(self, *args, **kwargs):
265271
"""
266272
for key in ['date_time_from', 'date_time_to']:
267273
if not kwargs.get(key):
268-
raise KeyError(f"To get transaction details required parameter is missing {key}")
274+
raise KeyError(
275+
f"To get transaction details required parameter is missing {key}")
269276

270277
kwargs['command'] = "get_transaction_info"
271278
kwargs['var1'] = kwargs.pop('date_time_from')
272279
kwargs['var2'] = kwargs.pop('date_time_to')
273280
response = self.__make_request(**kwargs)
274281
return response
275282

276-
277-
278283
def get_tdr(self, *args, **kwargs):
279284
"""
280285
This API is used to get the TDR value of a transaction with PayU. It is a simple API
@@ -283,7 +288,8 @@ def get_tdr(self, *args, **kwargs):
283288
to the output.
284289
"""
285290
if len(kwargs.get('payment_id')) == 0:
286-
raise KeyError(" Requested data doesn't contains required field: payment_id")
291+
raise KeyError(
292+
" Requested data doesn't contains required field: payment_id")
287293
kwargs['command'] = "get_TDR"
288294
kwargs['var1'] = kwargs.get('payment_id')
289295
response = self.__make_request(**kwargs)
@@ -313,7 +319,7 @@ def refund(self, *args, **kwargs):
313319
"beneficiary_ifsc":""
314320
}
315321
"""
316-
for col in ['payment_id', 'refund_id', 'amount']:
322+
for col in ['payment_id', 'refund_id', 'amount']:
317323
if not kwargs.get(col):
318324
raise KeyError(f"{col} mandatory missing in request payload ")
319325

@@ -341,6 +347,3 @@ def refund_status(self, *args, **kwargs):
341347
kwargs['command'] = "check_action_status"
342348
response = self.__make_request(**kwargs)
343349
return response
344-
345-
346-

0 commit comments

Comments
 (0)