-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcancel_payout_item.rb
38 lines (33 loc) · 1.45 KB
/
cancel_payout_item.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
require_relative 'paypal_client'
require_relative 'create_payouts'
require_relative 'get_payouts'
include PaypalPayoutsSdk::Payouts
module Samples
class CancelPayoutItem
# Cancels an UNCLAIMED payout item
# An item can be cancelled only when the item status is UNCLAIMED and the batch status is SUCCESS
# Upon cancelling the item status becomes RETURNED and the funds returned back to the sender
def cancel_payout_item(item_id, debug = false)
request = PayoutsItemCancelRequest.new(item_id)
begin
response = PayPalClient::client.execute(request)
puts "Status Code: #{response.status_code}"
puts "Status: #{response.result.status}"
puts "Payout Item Id: #{response.result.payout_item_id}"
puts "Payout Item Status: #{response.result.transaction_status}"
puts "Links: "
for link in response.result.links
# this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
end
puts PayPalClient::openstruct_to_hash(response.result).to_json
return response
rescue PayPalHttp::HttpError => ioe
# Exception occured while processing the payouts.
puts " Status Code: #{ioe.status_code}"
puts " Debug Id: #{ioe.result.debug_id}"
puts " Response: #{ioe.result}"
end
end
end
end