【问题标题】:Rails PayPal Chained Payment FeesRails PayPal 连锁支付费用
【发布时间】:2014-07-03 00:29:20
【问题描述】:

我有一个 ruby​​ on rails 应用程序;在我希望一个用户能够向另一个用户支付的情况下,应用程序少 10% 的“佣金”;我的客户希望从应用程序保留的 10% 中提取费用,原因有两个:1)不给客户加分/减少客户 2)在一定数量的交易(每月)之后,该百分比显然会降低

因此,例如,如果用户 1 向用户 2 支付 100 美元,我希望它显示为:

用户 1 向应用发送 100 美元 -> 应用收到 97.09 美元(减去费用 100 美元)-> 应用程序向用户 2 发送 90.00 (90%) -> 用户 2 收到全部 90 美元(他方不收取任何费用)

但是,尽管将应用设置为主要接收方,但它仍将费用发布到次要接收方,使用户 2 支付费用。我还尝试将用户 2 设置为主要接收者,之后仅将 10% 转发到应用程序,但随后它将费用转移到主要接收者。我在代码中唯一更改的是收费百分比,以及主要/次要电子邮件。我的代码如下所示:

<!-- 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 => "TestApp@gmail.com", :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

【问题讨论】:

    标签: ruby-on-rails ruby paypal paypal-adaptive-payments chained-payments


    【解决方案1】:

    使用feesPayer 字段并将其设置为PRIMARYRECEIVERSECONDARYONLY,具体取决于谁先收到付款。这个的 ruby​​ SDK 版本是fees_payer——来自API Reference

    feesPayer   xs:string (Optional) The payer of PayPal fees. Allowable values are: 
            SENDER – Sender pays all fees (for personal, implicit simple/parallel payments; do not use for chained or unilateral payments)
            PRIMARYRECEIVER – Primary receiver pays all fees (chained payments only)
            EACHRECEIVER – Each receiver pays their own fee (default, personal and unilateral payments)
            SECONDARYONLY – Secondary receivers pay all fees (use only for chained payments with one secondary receiver)
    

    EG:

    client.execute(:Pay,
        :action_type     => "PAY",
        :currency_code   => "USD",
        :cancel_url      => "http://localhost:3000/my-studio",
        :return_url      => "http://localhost:3000/submissions/#{submission.id}",
        :fees_payer      => "SECONDARYONLY",
        :receivers       => [
          { :email => recipient_email, :amount => recipient_cut, :primary => false },
          { :email => "TestApp@gmail.com", :amount => amount, :primary => true }
        ]
      )
    

    【讨论】:

    • 感谢您的回复;但我错了,它仍然向二级而不是一级收取费用。我在 :return_url 下面添加了::feesPayer => "PRIMARYRECEIVER",但它仍然无法正常工作。 叹息
    • 你们知道如何延迟连锁付款吗?
    【解决方案2】:

    我发现在 pp-adaptive gem 中,它需要这样的语法:

    :fees_payer       => "PRIMARYRECEIVER",
    

    现在它运行良好。

    【讨论】:

    • 谢谢,我已经相应地更新了我的答案。这在我能找到的任何 SDK 文档中都不清楚。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    • 2012-06-10
    • 2016-10-18
    • 2016-12-22
    • 2021-02-22
    • 2013-03-06
    • 2011-11-18
    相关资源
    最近更新 更多