-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatus.py
30 lines (26 loc) · 1.06 KB
/
status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import json
import http.client
class Verify():
def __init__(self, reference, secret_key):
self.reference = reference
self.secret_key = secret_key
def status(self):
url = f"/transaction/verify/{self.reference}"
headers = {
"Authorization": "Bearer " + self.secret_key
}
response = self._http_request("GET", url, headers)
response_text = response.read().decode("utf-8")
print(response_text)
if response.status == 200:
data = json.loads(response_text)
gateway_response = data.get('data', {}).get('gateway_response')
if gateway_response == "Successful":
return "successful"
elif gateway_response == "The transaction was not completed":
return "pending"
return "failed"
def _http_request(self, method, url, headers, body=None):
connection = http.client.HTTPSConnection("api.paystack.co")
connection.request(method, url, body, headers)
return connection.getresponse()