Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- created on 04-Nov-24 && powered by kohpriw/niranam
- ตัวอย่างการเรียกใช้
- token = 'YOUR_ACCESS_TOKEN'
- image_path = 'slip.jpg'
- payload = 'YOUR_PAYLOAD'
- _____________________________
- functions
- get_account_info(token)
- verify_bank_slip_by_payload(token, payload)
- verify_bank_slip_by_image(token, image_path)
- verify_bank_slip_by_base64(token, image_path)
- verify_truewallet_slip_by_image(token, image_path)
- """
- import requests
- import base64
- def get_account_info(token):
- url = 'https://developer.easyslip.com/api/v1/me'
- headers = {
- 'Authorization': f'Bearer {token}'
- }
- try:
- response = requests.get(url, headers=headers)
- response.raise_for_status()
- data = response.json()
- if response.status_code == 200:
- print("Account Info:")
- print(f"Application: {data['data']['application']}")
- print(f"Used Quota: {data['data']['usedQuota']}")
- print(f"Max Quota: {data['data']['maxQuota']}")
- print(f"Remaining Quota: {data['data']['remainingQuota']}")
- print(f"Expired At: {data['data']['expiredAt']}")
- print(f"Current Credit: {data['data']['currentCredit']}")
- else:
- print(f"Unexpected status code: {response.status_code}")
- except requests.exceptions.HTTPError as http_err:
- if response.status_code == 401:
- print("Error: Unauthorized (401) - Please check your access token.")
- elif response.status_code == 403:
- print("Error: Access Denied (403) - You do not have permission to access this resource.")
- elif response.status_code == 500:
- print("Error: Server Error (500) - Please try again later.")
- else:
- print(f"HTTP error occurred: {http_err}")
- except Exception as err:
- print(f"An error occurred: {err}")
- def verify_bank_slip_by_payload(token, payload):
- url = f'https://developer.easyslip.com/api/v1/verify?payload={payload}'
- headers = {
- 'Authorization': f'Bearer {token}'
- }
- try:
- response = requests.get(url, headers=headers)
- response.raise_for_status()
- data = response.json()
- if response.status_code == 200:
- print("Slip Verification Successful:")
- print(f"Transaction Reference: {data['data']['transRef']}")
- print(f"Date: {data['data']['date']}")
- print(f"Country Code: {data['data']['countryCode']}")
- print(f"Amount: {data['data']['amount']['amount']}")
- print(f"Sender Bank: {data['data']['sender']['bank']['name']}")
- print(f"Receiver Bank: {data['data']['receiver']['bank']['name']}")
- else:
- print(f"Unexpected status code: {response.status_code}")
- except requests.exceptions.HTTPError as http_err:
- if response.status_code == 400:
- print("Error: Invalid Payload (400) - Please check the payload.")
- elif response.status_code == 401:
- print("Error: Unauthorized (401) - Please check your access token.")
- elif response.status_code == 403:
- error_message = data.get('message', 'Access Denied (403)')
- print(f"Error: {error_message}")
- elif response.status_code == 404:
- print("Error: Slip Not Found (404) - The specified slip was not found.")
- elif response.status_code == 500:
- error_message = data.get('message', 'Server Error (500)')
- print(f"Error: {error_message}")
- else:
- print(f"HTTP error occurred: {http_err}")
- except Exception as err:
- print(f"An error occurred: {err}")
- def verify_bank_slip_by_image(token, image_path):
- url = 'https://developer.easyslip.com/api/v1/verify'
- headers = {
- 'Authorization': f'Bearer {token}'
- }
- files = {
- 'file': open(image_path, 'rb')
- }
- try:
- response = requests.post(url, headers=headers, files=files)
- response.raise_for_status()
- data = response.json()
- if response.status_code == 200:
- print("Slip Verification Successful:")
- print(f"Transaction Reference: {data['data']['transRef']}")
- print(f"Date: {data['data']['date']}")
- print(f"Country Code: {data['data']['countryCode']}")
- print(f"Amount: {data['data']['amount']['amount']}")
- print(f"Sender Bank: {data['data']['sender']['bank']['name']}")
- print(f"Receiver Bank: {data['data']['receiver']['bank']['name']}")
- else:
- print(f"Unexpected status code: {response.status_code}")
- except requests.exceptions.HTTPError as http_err:
- if response.status_code == 400:
- error_message = data.get('message', 'Invalid Request (400)')
- print(f"Error: {error_message}")
- elif response.status_code == 401:
- print("Error: Unauthorized (401) - Please check your access token.")
- elif response.status_code == 403:
- error_message = data.get('message', 'Access Denied (403)')
- print(f"Error: {error_message}")
- elif response.status_code == 404:
- error_message = data.get('message', 'Slip Not Found (404)')
- print(f"Error: {error_message}")
- elif response.status_code == 500:
- error_message = data.get('message', 'Server Error (500)')
- print(f"Error: {error_message}")
- else:
- print(f"HTTP error occurred: {http_err}")
- except Exception as err:
- print(f"An error occurred: {err}")
- finally:
- files['file'].close()
- def verify_bank_slip_by_base64(token, image_path):
- url = 'https://developer.easyslip.com/api/v1/verify'
- headers = {
- 'Content-Type': 'application/json',
- 'Authorization': f'Bearer {token}'
- }
- try:
- with open(image_path, 'rb') as image_file:
- base64_image = base64.b64encode(image_file.read()).decode('utf-8')
- payload = {
- "image": base64_image
- }
- response = requests.post(url, headers=headers, json=payload)
- response.raise_for_status()
- data = response.json()
- if response.status_code == 200:
- print("Slip Verification Successful:")
- print(f"Transaction Reference: {data['data']['transRef']}")
- print(f"Date: {data['data']['date']}")
- print(f"Country Code: {data['data']['countryCode']}")
- print(f"Amount: {data['data']['amount']['amount']}")
- print(f"Sender Bank: {data['data']['sender']['bank']['name']}")
- print(f"Receiver Bank: {data['data']['receiver']['bank']['name']}")
- else:
- print(f"Unexpected status code: {response.status_code}")
- except requests.exceptions.HTTPError as http_err:
- if response.status_code == 400:
- error_message = data.get('message', 'Invalid Request (400)')
- print(f"Error: {error_message}")
- elif response.status_code == 401:
- print("Error: Unauthorized (401) - Please check your access token.")
- elif response.status_code == 403:
- error_message = data.get('message', 'Access Denied (403)')
- print(f"Error: {error_message}")
- elif response.status_code == 404:
- error_message = data.get('message', 'Slip Not Found (404)')
- print(f"Error: {error_message}")
- elif response.status_code == 500:
- error_message = data.get('message', 'Server Error (500)')
- print(f"Error: {error_message}")
- else:
- print(f"HTTP error occurred: {http_err}")
- except Exception as err:
- print(f"An error occurred: {err}")
- def verify_truewallet_slip_by_image(token, image_path):
- url = 'https://developer.easyslip.com/api/v1/verify/truewallet'
- headers = {
- 'Authorization': f'Bearer {token}'
- }
- files = {
- 'file': open(image_path, 'rb')
- }
- try:
- response = requests.post(url, headers=headers, files=files)
- response.raise_for_status()
- data = response.json()
- if response.status_code == 200:
- print("Truemoney Wallet Slip Verification Successful:")
- print(f"Transaction ID: {data['data']['transactionId']}")
- print(f"Date: {data['data']['date']}")
- print(f"Amount: {data['data']['amount']}")
- print(f"Sender Name: {data['data']['sender']['name']}")
- print(f"Receiver Name: {data['data']['receiver']['name']}")
- print(f"Receiver Phone: {data['data']['receiver']['phone']}")
- else:
- print(f"Unexpected status code: {response.status_code}")
- except requests.exceptions.HTTPError as http_err:
- if response.status_code == 400:
- error_message = data.get('message', 'Invalid Request (400)')
- print(f"Error: {error_message}")
- elif response.status_code == 401:
- print("Error: Unauthorized (401) - Please check youraccess token.")
- elif response.status_code == 403:
- error_message = data.get('message', 'Access Denied (403)')
- print(f"Error: {error_message}")
- elif response.status_code == 404:
- error_message = data.get('message', 'Slip Not Found (404)')
- print(f"Error: {error_message}")
- elif response.status_code == 500:
- error_message = data.get('message', 'Server Error (500)')
- print(f"Error: {error_message}")
- else:
- print(f"HTTP error occurred: {http_err}")
- except Exception as err:
- print(f"An error occurred: {err}")
- finally:
- files['file'].close()
Add Comment
Please, Sign In to add comment