I’m using Rails 3.1 and the paypal_adaptive ( https://github.com/tc/paypal_adaptive ) gem in order to make an API request to Paypal. Here’s the deal: I have a request which I’m making to Paypal in a controller. I have a collection of Items (which is @items here), and I’m trying to add recipients to that request for each item in that collection. Here’s my code:
pay_request = PaypalAdaptive::Request.new
data = {
"returnUrl" => "http://testserver.com/payments/completed_payment_request",
"requestEnvelope" => {"errorLanguage" => "en_US"},
"currencyCode" => "USD",
"receiverList" => {"receiver"=>[
@items.each do |item|
{"email"=>"#{Recipient.find_by_id(item.recip_id).email}", "amount"=>"#{item.price}"},
end
]},
"cancelUrl"=>"http://testserver.com/payments/canceled_payment_request",
"actionType"=>"PAY",
"ipnNotificationUrl"=>"http://testserver.com/payments/ipn_notification"
}
pay_response = pay_request.pay(data)
if pay_response.success?
redirect_to pay_response.approve_paypal_payment_url
else
puts pay_response.errors.first['message']
redirect_to failed_payment_url
end
…but this isn’t working. How can I properly insert Ruby syntax into this request?
(Sorry for the vagueness in the title. I’m unsure what kind of request I’m making (AJAX maybe?))
Just collect all the items into a variable and set that as the value of the “reciever” key: