Skip to content

Commit f2ad6ba

Browse files
committed
added the transaction methods
1 parent 64a0a9b commit f2ad6ba

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

thepeer/main.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,48 @@ def authorize_direct_charge(self, auth_charge_reference, event):
186186
except Exception as e:
187187
raise SwitchErrorStates(e).switch()
188188

189+
def get_transaction_detail(self, transaction_id):
190+
"""Get the details about a transaction
191+
Args:
192+
transaction_id (string): the unique identifier of the transaction
193+
194+
Returns:
195+
dict:containing the transaction object. more about a transaction object here
196+
https://docs.thepeer.co/transaction/transaction-object#anatomy-of-a-transaction-object
197+
"""
198+
try:
199+
response = httpx.get(
200+
f"{self.url}/transactions/{transaction_id}", headers=dict(self.headers)
201+
)
202+
return response.json()
203+
except Exception as e:
204+
raise SwitchErrorStates(e).switch()
205+
206+
def refund_transaction(self, transaction_id, reason):
207+
208+
"""This method allows a business to refund a transaction back to the user
209+
who made the transaction for obvious reasons.
210+
211+
Args:
212+
transaction_id (string): the unique identifier of the transaction
213+
reason (string): a string explaining the reason for the refund
214+
215+
Returns:
216+
dict:
217+
containing the transaction object. more about a transaction object can be found here
218+
https://docs.thepeer.co/transaction/transaction-object#anatomy-of-a-transaction-object
219+
"""
220+
try:
221+
data = json.dumps({"reason": reason})
222+
response = httpx.post(
223+
f"{self.url}/transactions/{transaction_id}/refund",
224+
data=data,
225+
headers=dict(self.headers),
226+
)
227+
return response.json()
228+
except Exception as e:
229+
raise SwitchErrorStates(e).switch()
230+
189231

190232
# test function
191233
thepeer = ThePeerInit(config("PEER_SECRET_KEY"))
@@ -195,5 +237,5 @@ def authorize_direct_charge(self, auth_charge_reference, event):
195237
)
196238
charge = thepeer.authorize_direct_charge("3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd", "failed")
197239
view = thepeer.view_user("3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd")
198-
# print(view)
199-
# print(get)
240+
print(view)
241+
print(get)

0 commit comments

Comments
 (0)