【问题标题】:Add multiplie receivers to Paypal Mass Pay using Rails and 'paypal-sdk-merchant' gem使用 Rails 和“paypal-sdk-merchant”gem 将多个接收者添加到 Paypal Mass Pay
【发布时间】:2014-06-30 12:24:14
【问题描述】:

我正在创建一个必须使用 Paypal MassPayment API 的 Rails 应用程序(在我们的例子中,自适应支付不是一个选项)。

我正在使用“paypal-sdk-merchant”https://github.com/paypal/merchant-sdk-ruby

按照中建议的示例 https://paypal-sdk-samples.herokuapp.com/merchant/mass_pay 我可以使用一个接收器创建“大规模支付”:

@api = PayPal::SDK::Merchant::API.new

# Build request object
@mass_pay = @api.build_mass_pay({
  :ReceiverType => "EmailAddress",
  :MassPayItem => [{
    :ReceiverEmail => "enduser_biz@gmail.com",
    :Amount => {
      :currencyID => "EUR",
      :value => "3.00" } }] })

# Make API call & get response
@mass_pay_response = @api.mass_pay(@mass_pay)

# Access Response
if @mass_pay_response.success?
else
  @mass_pay_response.Errors
end

问题是:如何构建一个有多个接收者的大规模支付对象?

按照文档,我尝试了以下代码并进行了多种变体,但 Paypal 似乎只考虑了最后一项:

        @api = PayPal::SDK::Merchant::API.new

# Build request object
        @mass_pay = @api.build_mass_pay({


        :ReceiverType0 => "EmailAddress",
        :MassPayItem0 => [{
        :ReceiverEmail => "enduser_biz@gmail.com",
        :Amount => {
        :currencyID => "EUR",
        :value => "3.00" } }],

        :ReceiverType1 => "EmailAddress",
        :MassPayItem1 => [{
        :ReceiverEmail => "enduser_biz1@gmail.com",
        :Amount => {
        :currencyID => "EUR",
        :value => "5.00" } }]
  }

)

(...)

另外,我有一堆邮件和值,所以我需要把它们全部都批量支付,怎么办?

理想情况下,我想要一些东西:

@mass_pay = build_mass_pay_with_array_of_email_and_values([ARRAY_OF_EMAILS_AND_VALUES_HERE])

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 paypal masspay


    【解决方案1】:
    require 'paypal-sdk-merchant'
    
    @api = PayPal::SDK::Merchant::API.new
    
    #make an array of members
    member_list = []
    member_list << {
      :ReceiverEmail => 'someone@example.com',
      :Amount => {
        :currencyID => "USD",
        :value => 1.6
      }
    }
    member_list << {
      :ReceiverEmail => 'someone2@example.com',
      :Amount => {
        :currencyID => "USD",
        :value => 1.6
      }
    }
    
    # Build request object
    @mass_pay = @api.build_mass_pay(member_list)
    
    # Make API call & get response
    @mass_pay_response = @api.mass_pay(@mass_pay)
    
    # Access Response
    if @mass_pay_response.success?
    else
      @mass_pay_response.Errors
    end
    

    【讨论】:

    • 解决了上一个解决方案的问题,但感谢您在此答案中详细说明:)
    【解决方案2】:

    语法有点像 JSON。 [] 是一个数组,您可以向该 MassPayItem 数组添加更多成员:

        :MassPayItem => [{
            :ReceiverEmail => "enduser_biz@gmail.com",
            :Amount => {
                :currencyID => "EUR",
                :value => "3.00"
            }
        },
        {
            :ReceiverEmail => "enduser_biz2@gmail.com",
            :Amount => {
                :currencyID => "EUR",
                :value => "1.00" 
            }
        }]
    

    结束:

    require 'paypal-sdk-merchant'
    
    @api = PayPal::SDK::Merchant::API.new
    
    # Build request object
    @mass_pay = @api.build_mass_pay({
        :ReceiverType => "EmailAddress",
        :MassPayItem => [{
            :ReceiverEmail => "enduser_biz@gmail.com",
            :Amount => {
                :currencyID => "EUR",
                :value => "3.00"
            }
        },
        {
            :ReceiverEmail => "enduser_biz2@gmail.com",
            :Amount => {
                :currencyID => "EUR",
                :value => "1.00" 
            }
        }]
    })
    
    # Make API call & get response
    @mass_pay_response = @api.mass_pay(@mass_pay)
    
    # Access Response
    if @mass_pay_response.success?
    else
      @mass_pay_response.Errors
    end
    

    【讨论】:

      猜你喜欢
      • 2014-04-26
      • 2013-11-04
      • 2012-12-20
      • 2013-06-18
      • 2013-09-11
      • 2023-04-02
      • 2014-06-20
      • 2015-05-27
      • 2016-08-11
      相关资源
      最近更新 更多