Skip to content

Commit

Permalink
added: transaction validation
Browse files Browse the repository at this point in the history
  • Loading branch information
shahedex committed Apr 21, 2020
1 parent ab17c7e commit 299cb2d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
venv
__pycache__
.vscode
.vscode
build
dist
sslcommerz_python.egg-info/
38 changes: 37 additions & 1 deletion sslcommerz_python/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sslcommerz_python._constants as const


class SSLCSession:
class SSLCommerz:
sslc_is_sandbox : bool
sslc_store_id : str
sslc_store_pass : str
Expand All @@ -28,6 +28,11 @@ def set_sslcommerz_mode(sslc_is_sandbox: bool) -> str:
return 'sandbox'
else:
return 'securepay'


class SSLCSession(SSLCommerz):
def __init__(self, sslc_is_sandbox=True, sslc_store_id='', sslc_store_pass='') -> None:
super().__init__(sslc_is_sandbox, sslc_store_id, sslc_store_pass)

def set_urls(self, success_url: str, fail_url: str, cancel_url: str, ipn_url: str='') -> None:
self.integration_data['success_url'] = success_url
Expand Down Expand Up @@ -85,3 +90,34 @@ def init_payment(self):
response_data['status'] = response_json['status']
response_data['failedreason'] = response_json['failedreason']
return response_data


class Validation(SSLCommerz):
def __init__(self, sslc_is_sandbox=True, sslc_store_id='', sslc_store_pass='') -> None:
super().__init__(sslc_is_sandbox, sslc_store_id, sslc_store_pass)

def validate_transaction(self, validation_id):
query_params : Dict[str, str] = {}
response_data : Dict[str, str] = {}
query_params['val_id'] = validation_id
query_params['store_id'] = self.sslc_store_id
query_params['store_passwd'] = self.sslc_store_pass
query_params['format'] = 'json'

validation_response = requests.get(
self.sslc_validation_api,
params=query_params
)

if validation_response.status_code == 200:
validation_json = validation_response.json()
if validation_json['status'] == 'VALIDATED':
response_data['status'] = 'VALIDATED'
response_data['data'] = validation_json
else:
response_data['status'] = validation_json['status']
response_data['data'] = validation_json
else:
response_data['status'] = 'FAILED'
response_data['data'] = 'Validation failed due to status code ' + str(validation_response.status_code)
return response_data

0 comments on commit 299cb2d

Please sign in to comment.