-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathrefund-payment.py
72 lines (55 loc) · 2.42 KB
/
refund-payment.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from CyberSource import *
from pathlib import Path
import os
import json
from importlib.machinery import SourceFileLoader
config_file = os.path.join(os.getcwd(), "data", "Configuration.py")
configuration = SourceFileLoader("module.name", config_file).load_module()
process_payment_path = os.path.join(os.getcwd(), "samples", "Payments", "Payments", "simple-authorizationinternet.py")
process_payment = SourceFileLoader("module.name", process_payment_path).load_module()
# To delete None values in Input Request Json body
def del_none(d):
for key, value in list(d.items()):
if value is None:
del d[key]
elif isinstance(value, dict):
del_none(value)
return d
def refund_payment():
clientReferenceInformationCode = "TC50171_3"
clientReferenceInformation = Ptsv2paymentsidrefundsClientReferenceInformation(
code = clientReferenceInformationCode
)
orderInformationAmountDetailsTotalAmount = "10"
orderInformationAmountDetailsCurrency = "USD"
orderInformationAmountDetails = Ptsv2paymentsidcapturesOrderInformationAmountDetails(
total_amount = orderInformationAmountDetailsTotalAmount,
currency = orderInformationAmountDetailsCurrency
)
orderInformation = Ptsv2paymentsidrefundsOrderInformation(
amount_details = orderInformationAmountDetails.__dict__
)
requestObj = RefundPaymentRequest(
client_reference_information = clientReferenceInformation.__dict__,
order_information = orderInformation.__dict__
)
requestObj = del_none(requestObj.__dict__)
requestObj = json.dumps(requestObj)
try:
api_payment_response = process_payment.simple_authorizationinternet(True)
id = api_payment_response.id
config_obj = configuration.Configuration()
client_config = config_obj.get_configuration()
api_instance = RefundApi(client_config)
return_data, status, body = api_instance.refund_payment(requestObj, id)
print("\nAPI RESPONSE CODE : ", status)
print("\nAPI RESPONSE BODY : ", body)
write_log_audit(status)
return return_data
except Exception as e:
write_log_audit(e.status if hasattr(e, 'status') else 999)
print("\nException when calling RefundApi->refund_payment: %s\n" % e)
def write_log_audit(status):
print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}")
if __name__ == "__main__":
refund_payment()