forked from rajkumarpalani/Payouts-Ruby-SDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_all.rb
63 lines (59 loc) · 2.54 KB
/
run_all.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
54
55
56
57
58
59
60
61
62
63
require_relative 'create_payouts'
require_relative 'get_payouts'
require_relative 'get_payout_item'
require_relative 'cancel_payout_item'
include PayPalHttp
# Create Payouts Batch
puts "Creating Payouts Batch"
create_resp = Samples::CreatePayouts::new().create_payouts(true)
if create_resp.status_code == 201
# Retrieve Payout batch details
batch_id = create_resp.result.batch_header.payout_batch_id
puts "Retrieving Payouts batch details with id: #{batch_id}"
get_resp = Samples::GetPayouts::new().get_payouts(batch_id, true)
if get_resp.status_code == 200
# Retrieve Payout Item details
item_id = get_resp.result.items[0].payout_item_id
puts "Retrieving Payouts item detail with id: #{item_id}"
get_item_resp = Samples::GetPayoutItem::new().get_payout_item(item_id, true)
if get_item_resp.status_code == 200
# Wait till batch status becomes SUCCESS to cancel an UNCLAIMED payout item - this is just for demonstration purpose
# Defer using this while integration
# Note: Use Webhooks to get LIVE status updates for Payouts Batch and Item
puts "Check if all Payouts items are processed"
var = 0
until var == 5
sleep 2
get_resp = Samples::GetPayouts::new().get_payouts(batch_id, true)
if get_resp.result.batch_header.batch_status == 'SUCCESS'
# Cancel UNCLAIMED Payout item
puts "Cancelling unclaimed Payouts item with id: #{item_id}"
cancel_resp = Samples::CancelPayoutItem.new().cancel_payout_item(item_id, true)
if cancel_resp.status_code == 200
puts "Successfully cancelled unclaimed Payouts item with id: #{item_id}"
# Run cancel failure scenario
puts "Simulate failure on cancelling an already cancelled Payout item with id: #{item_id}"
Samples::CancelPayoutItem.new().cancel_payout_item(item_id, true)
else
puts "Failed to cancel unclaimed Payouts item with id: #{item_id}"
end
break
end
var = var + 1
end
else
puts "Failed to retrieve Payouts item detail with id: #{item_id}"
end
else
puts "Failed to retrieve Payouts batch detail with id: #{batch_id}"
end
else
puts "Failed to crate Payouts batch"
end
# Execute all failure cases
puts "Create a payout with validation failure"
Samples::CreatePayouts::new().create_payouts_failure(true)
puts "Retrieving an invalid payout"
Samples::GetPayouts::new().get_payouts("DUMMY", true)
puts "Retrieving an invalid payout item"
Samples::GetPayoutItem::new().get_payout_item("DUMMY", true)