I have a ruby on rails app; where I wish to have one user be able to pay another user, less 10% 'commission' to the app; My client wants the fees to come out of the 10% the app keeps, for two reasons 1) not nickel/diming their customer 2) after a certain amount of transactions (per month), the percentage apparently gets lower
So, for example, if User 1 pays User 2 $100, I want it to show up as:
User 1 sends $100 to app -> App receives $97.09 ($100 less the fees) -> App sends 90.00 (90%) to User 2 -> User 2 receives the full $90 (no fees on his side)
However, despite setting the app as the primary receiver, it posted the fees on the secondary receiver, making User 2 pay the fees. I also attempted to set User 2 as the primary, and only send 10% forward to the app afterwards, but then it moved the fees to the primary receiver. The only thing I changed in the code was the percentage being charged, and the primary/secondary emails. My code looks like this:
<!-- app/lib/pay_pal_api.rb -->
require "pp-adaptive"
class PayPalAPI
def self.payment_url(submission)
amount = submission.amount_in_cents.to_f / 100.0
recipient_cut = amount * 0.9
recipient_email = submission.submitter.paypal_email
client.execute(:Pay,
:action_type => "PAY",
:currency_code => "USD",
:cancel_url => "http://localhost:3000/my-studio",
:return_url => "http://localhost:3000/submissions/#{submission.id}",
:receivers => [
{ :email => recipient_email, :amount => recipient_cut, :primary => false },
{ :email => "[email protected]", :amount => amount, :primary => true }
]
) do |response|
if response.success?
puts "Pay key: #{response.pay_key}"
# send the user to PayPal to make the payment
# e.g. https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=abc
return client.payment_url(response)
else
puts "#{response.ack_code}: #{response.error_message}"
end
end
return nil
end
Use the
feesPayer
field and set it to eitherPRIMARYRECEIVER
orSECONDARYONLY
depending on who is receiving the payment first. The ruby SDK version of this isfees_payer
-- from the API Reference:EG: