client = $dwolla.auths.client
mass_payment = @client.post "mass-payments", request_body, headers
mass_payment_url = mass_payment.response_headers[:location] # value "https://api-sandbox.dwolla.com/mass-payments/27f1c972-66e8-4511-8731-adff010939c3"
mass_payment_items = client.get "#{mass_payment_url}/items"
transfer_urls = [];
mass_payment_items._embedded.items.each do |item|
transfer_urls << item._links["transfer"]["href"]
end
I need the value of the array of transfer_urls. I did this job after requesting for a mass_payment. I need all the transfers details to save in my database. but problem is sometimes the transfer details is missing in the response. then this line item._links["transfer"]["href"] throws error. and background retries to fetch the data. then it got the correct response. but what is the reason? I am giving the response of a failed case.
Transfer key missing response for a item:
{"_links"=>{"self"=>{"href"=>"https://api-sandbox.dwolla.com/mass-payment-items/9a337477-47ce-4a56-a1dd-337b30e68641", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"mass-payment-item"}, "mass-payment"=>{"href"=>"https://api-sandbox.dwolla.com/mass-payments/27f1c972-66e8-4511-8731-adff010939c3", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"mass-payment"}, "destination"=>{"href"=>"https://api-sandbox.dwolla.com/customers/874948fb-aa92-4891-bbbc-ec7c32663277", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"customer"}}, "id"=>"9a337477-47ce-4a56-a1dd-337b30e68641", "status"=>"pending", "amount"=>{"value"=>"0.25", "currency"=>"USD"}, "metadata"=>{"investment_id"=>"278", "unsecure_repayment_id"=>"99"}, "clearing"=>{"destination"=>"next-available"}, "created"=>2021-12-15 16:05:46 UTC}
Transfer key present in the response:
{"_links"=>{"self"=>{"href"=>"https://api-sandbox.dwolla.com/mass-payment-items/e3f2852c-c340-4016-ae39-9ab24adf299e", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"mass-payment-item"}, "mass-payment"=>{"href"=>"https://api-sandbox.dwolla.com/mass-payments/27f1c972-66e8-4511-8731-adff010939c3", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"mass-payment"}, "destination"=>{"href"=>"https://api-sandbox.dwolla.com/customers/874948fb-aa92-4891-bbbc-ec7c32663277", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"customer"}, "transfer"=>{"href"=>"https://api-sandbox.dwolla.com/transfers/0aabb2d9-c05d-ec11-813b-9b226fbd821b", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"transfer"}}, "id"=>"e3f2852c-c340-4016-ae39-9ab24adf299e", "status"=>"success", "amount"=>{"value"=>"0.25", "currency"=>"USD"}, "metadata"=>{"investment_id"=>"278", "unsecure_repayment_id"=>"98"}, "clearing"=>{"destination"=>"next-available"}, "created"=>2021-12-15 16:05:46 UTC}