我正在努力使用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方法没有返回字符串?有什么新鲜的想法吗?
答案 0 :(得分:2)
:receiver
哈希中有两个名为:receiverList
的元素。哈希只能为每个唯一名称使用一个元素,因此后一个定义会覆盖前者,因此第一个接收者将丢失。
相反,将两个接收器添加到:receiver
内的一个数组中,这样您就会:receiverList => {:receiver => [{...}, {...}]}
。