forked from rajarampadmanathan/Checkout-Python-SDK-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_order.py
More file actions
executable file
·58 lines (55 loc) · 2.26 KB
/
patch_order.py
File metadata and controls
executable file
·58 lines (55 loc) · 2.26 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from paypalcheckoutsdk.orders import OrdersPatchRequest, OrdersGetRequest
from sample import PayPalClient
from sample.AuthorizeIntentExamples import CreateOrder
import json
class PatchOrder(PayPalClient):
@staticmethod
def build_request_body():
"""Method to created body for patch order -> list of patches"""
return \
[
{
"op": "replace",
"path": "/intent",
"value": "CAPTURE"
},
{
"op": "replace",
"path": "/purchase_units/@reference_id=='PUHF'/amount",
"value": {
"currency_code": "USD",
"value": "200.00",
"breakdown": {
"item_total": {
"currency_code": "USD",
"value": "180.00"
},
"tax_total": {
"currency_code": "USD",
"value": "20.00"
}
}
}
}
]
def patch_order(self, order_id):
"""Method to patch order"""
request = OrdersPatchRequest(order_id)
request.request_body(self.build_request_body())
self.client.execute(request)
response = self.client.execute(OrdersGetRequest(order.id))
print 'Order ID: ', response.result.id
print 'Intent: ', response.result.intent
print 'Links:'
for link in response.result.links:
print('\t{}: {}\tCall Type: {}'.format(link.rel, link.href, link.method))
print 'Gross Amount: {} {}'.format(response.result.purchase_units[0].amount.currency_code,
response.result.purchase_units[0].amount.value)
json_data = self.object_to_json(response.result)
print "json_data: ", json.dumps(json_data,indent=4)
if __name__ == "__main__":
print 'Before PATCH:'
createResponse = CreateOrder().create_order(True)
order = createResponse.result
print '\nAfter PATCH (Changed Intent and Amount):'
PatchOrder().patch_order(order.id)