【发布时间】: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.inspect和pay_response.inspect吗?
标签: ruby-on-rails ruby paypal paypal-adaptive-payments