module PayPal::Merchant::MassPay

Protected Instance Methods

bulk_transfer(recipients, options = {}) click to toggle source

Send money to multiple PayPal accounts

# File lib/paypal/merchant/mass_pay.rb, line 25
def bulk_transfer(recipients, options = {})
  begin
    mass_pay_item = recipients.map do |recipient|
      recipient.symbolize_keys!
      {ReceiverEmail: recipient[:email],
        Amount: {
          currencyID: options[:currency] || "USD",
          value: Money.new(recipient[:amount]).dollars
        }, Note: options[:note]}
    end
    send_mass_pay(mass_pay_item, options)
  rescue
    nil
  end
end
send_mass_pay(mass_pay_item, options = {}) click to toggle source
# File lib/paypal/merchant/mass_pay.rb, line 42
def send_mass_pay(mass_pay_item, options = {})
  merchant_api = PayPal::Merchant.new
  transfer_request = merchant_api.build_mass_pay({
    ReceiverType: "EmailAddress",
    EmailSubject: options[:subject],
    MassPayItem: [mass_pay_item].flatten
  })
  response = merchant_api.mass_pay(transfer_request)
end
transfer(amount, email, options = {currency: "USD"}) click to toggle source

Send money to another PayPal account

# File lib/paypal/merchant/mass_pay.rb, line 9
def transfer(amount, email, options = {currency: "USD"})
  begin
    mass_pay_item = {
      ReceiverEmail: email,
      Amount: {currencyID: options[:currency],
        value: Money.new(amount).dollars}
    }
    send_mass_pay(mass_pay_item, options)
  rescue
    nil
  end
end