2

我有一个 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
4

2 回答 2

2

我发现在 pp-adaptive gem 中,它需要以下语法:

:fees_payer       => "PRIMARYRECEIVER",

现在它运行良好。

于 2014-05-17T07:12:51.223 回答
1

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

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)

例如:

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 }
    ]
  )
于 2014-05-14T20:15:24.300 回答