【问题标题】:Setting up PayPal adaptive payment flow设置 PayPal 自适应支付流程
【发布时间】:2016-02-10 04:01:01
【问题描述】:

我正在与 paypal api 搏斗,并且所有关于它的文章都给出了我不是唯一的 :-)。但是,我找不到我的问题的答案。

我正在尝试在 Ruby 中设置链式支付,如下所示:

amount = (self.price * 0.95).round(2) #amount to payout to seller
fee = (self.price * 0.05).round(2) #5% fee for my platform
api = PayPal::SDK::AdaptivePayments.new
pay = api.build_pay({
    :actionType => "PAY",
    :cancelUrl => "https://my-url/paypal_cancel?purchase_guid=" + self.guid,
    :currencyCode => self.currency,
    :feesPayer => "EACHRECEIVER",
    :ipnNotificationUrl => "http://my-url/paypal_ipn_notify?purchase_guid=" + self.guid,
    :receiverList => {
        :receiver => [{
            :amount => amount,
            :email => 'primary@someurl.com', #this must be the party that receives the full amount initially
            :primary => true
        }],
        :receiver => [{
            :amount => fee,
            :email => 'secondary@someurl.com' #this will be the account of my platform that is a secondary receiver and receives the fee
        }]},
    :returnUrl => "https://some-url/paypal_success?purchase_guid=" + self.guid + "&verification_key=" + paypal_verification_key })
pay_response = api.pay(pay)

此操作完成且没有错误,但仅提示付款人支付在辅助收款人处指定的金额/费用。在主要收款人处指定的金额会被忽略,并且在付款过程中找不到。

这一切可能是由于缺乏知识但整个api非常不透明。

有什么想法吗? :-) 谢谢!

----- 编辑 ------

这是 receiversList 对象的 hash/yaml:

--- !ruby/object:PayPal::SDK::AdaptivePayments::DataTypes::ReceiverList
receiver: !ruby/array:PayPal::SDK::Core::API::DataTypes::ArrayWithBlock
internal:
- !ruby/object:PayPal::SDK::AdaptivePayments::DataTypes::Receiver
amount: 7.15
email: !ruby/string:PayPal::SDK::Core::API::DataTypes::SimpleTypes::String ch-facilitator@fluxmatix.com
ivars:
:@block: !ruby/object:Proc {}
"https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=AP-8VD6912739718553G"

我看到那里只有一个接收器,所以我猜你是对的,问题出在某个地方。知道我的代码的哪一部分搞砸了吗?

----- 编辑 2 -----

好的,我像这样清除哈希问题:

:receiverList => {
    :receiver => [{
        :amount => amount,
        :email => 'ch-seller@domain.com,
        :primary => true
        },
        {
        :amount => fee,
        :email => 'ch-facilitator@fluxmatix.com'
     }],
}

这会导致以下结果:

--- !ruby/object:PayPal::SDK::AdaptivePayments::DataTypes::ReceiverList
receiver: !ruby/array:PayPal::SDK::Core::API::DataTypes::ArrayWithBlock
internal:
- !ruby/object:PayPal::SDK::AdaptivePayments::DataTypes::Receiver
amount: 135.78
email: !ruby/string:PayPal::SDK::Core::API::DataTypes::SimpleTypes::String ch-seller@paypal.com
primary: true
- !ruby/object:PayPal::SDK::AdaptivePayments::DataTypes::Receiver
amount: 7.15
email:    !ruby/string:PayPal::SDK::Core::API::DataTypes::SimpleTypes::String ch-facilitator@fluxmatix.com
ivars:
:@block: !ruby/object:Proc {}

但是,现在我收到以下错误:

undefined method `to_model' for true:TrueClass

打电话时

redirect_to api.payment_url(pay_response)

看起来 api.payment_url 方法没有返回字符串?有什么新鲜想法吗?

【问题讨论】:

  • 我认为您应该尝试更清楚地解释您的问题。
  • 您可以尝试将receiverList 中的哈希值粘贴到rails 控制台中,看看结果如何?我认为您的问题出在那儿 ;-)
  • 谢谢。我已经添加了哈希。看起来有些不对劲:-)
  • 我认为你错过了我的观点。在receiverList 中,您定义了相同的键 TWICE,因此只有最后一个键最终会出现在结果哈希中。这就是你收到错误的原因。文档可能允许您在其中传递一个哈希区域,尝试这样做。
  • 您可以在问题中添加pay.inspectpay_response.inspect 吗?

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


【解决方案1】:

:receiverList 哈希中有两个名为 :receiver 的元素。每个唯一名称的哈希只能有一个元素,因此后者的定义会覆盖前者,因此第一个接收者会丢失。

相反,将两个接收器添加到:receiver 内的一个数组中,这样您将拥有:receiverList => {:receiver => [{...}, {...}]}

【讨论】:

  • 您能引用正确的 PayPal 文档来确认吗?我很难找到一个。
  • 我已经用新的事态更新了原来的问题。
  • @MichalSzyndel 是的,developer.paypal.com/docs/classic/api/adaptive-payments/… 的文档没有此类详细信息。我说的是经验 - 这就是我们的生产代码的工作方式。
猜你喜欢
  • 2016-08-27
  • 2018-07-28
  • 2015-07-19
  • 2014-02-09
  • 2021-08-04
  • 2014-10-13
  • 2013-11-10
  • 2013-11-07
  • 2015-01-20
相关资源
最近更新 更多