-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathpatch_order.rb
53 lines (50 loc) · 1.79 KB
/
patch_order.rb
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
require_relative './paypal_client'
require_relative './capture_intent_examples/create_order'
require_relative './get_order'
include PayPalCheckoutSdk::Orders
module Samples
class PatchOrder
# Below function can be used to patch and order.
# Patch is supported on only specific set of fields.
# Please refer API docs for more info.
def patch_order(order_id)
body = [{
op:'replace',
path:"/purchase_units/@reference_id=='PUHF'/description",
value:'Sporting goods description'
},
{
op: 'replace',
path: "/purchase_units/@reference_id=='PUHF'/custom_id",
value: 'CUST-ID-HighFashions'
}
]
request = OrdersPatchRequest::new(order_id)
request.request_body(body)
response = PayPalClient::client::execute(request)
return response
end
end
end
# Driver function which does below steps.
# 1. Create an Order
# 2. Patch fields in the newly created order.
# 3. Print the updated fields by calling the get order.
if __FILE__ == $0
begin
order= Samples::CaptureIntentExamples::CreateOrder::new::create_order.result
patch_response = Samples::PatchOrder::new::patch_order(order.id)
puts "patch_response status code ::: #{patch_response.status_code}"
if patch_response.status_code == 204
order = Samples::GetOrder::new::get_order(order.id)
puts "Updated Description: #{order.result.purchase_units[0].description}"
puts "Updated Custom Id: #{order.result.purchase_units[0].custom_id}"
puts PayPalClient::openstruct_to_hash(order.result).to_json
end
rescue BraintreeHttp::HttpError => ioe
# Exception occured while processing the refund.
puts " Status Code: #{ioe.status_code}"
puts " Debug Id: #{ioe.result.debug_id}"
puts " Response: #{ioe.result}"
end
end