forked from rajarampadmanathan/Checkout-Python-SDK-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefund_order.py
More file actions
40 lines (36 loc) · 1.65 KB
/
refund_order.py
File metadata and controls
40 lines (36 loc) · 1.65 KB
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
from sample import PayPalClient
from paypalcheckoutsdk.payments import CapturesRefundRequest
import json
class RefundOrder(PayPalClient):
"""Request body for building refund request. This can be updated with values in case of partial refund. """
@staticmethod
def build_request_body():
"""Method to build empty body"""
return \
{
"amount": {
"value": "20.00",
"currency_code": "USD"
}
}
"""Below function can be used to refund an capture. Valid capture id should be passed as an argument."""
def refund_order(self, capture_id, debug=False):
"""Method to refund order using capture_id"""
request = CapturesRefundRequest(capture_id)
request.prefer("return=representation")
request.request_body(self.build_request_body())
response = self.client.execute(request)
if debug:
print 'Status Code:', response.status_code
print 'Status:', response.result.status
print 'Order ID:', response.result.id
print 'Links:'
for link in response.result.links:
print('\t{}: {}\tCall Type: {}'.format(link.rel, link.href, link.method))
json_data = self.object_to_json(response.result)
print "json_data: ", json.dumps(json_data,indent=4)
return response
"""This is the driver function which invokes the refund capture function. Capture Id value should be replaced with the valid capture id. """
if __name__ == "__main__":
capture_id = '<<REPLACE-WITH-VALID-CAPTURE-ID>>'
RefundOrder().refund_order(capture_id, debug=True)