gpt4 book ai didi

ruby-on-rails - 设置 PayPal 自适应支付流程

转载 作者:太空宇宙 更新时间:2023-11-03 16:17:04 26 4
gpt4 key购买 nike

我正在与 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 对象的哈希/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 散列中有两个名为 :receiver 的元素。散列对于每个唯一名称只能有一个元素,因此后一个定义覆盖前一个,因此第一个接收者丢失。

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

关于ruby-on-rails - 设置 PayPal 自适应支付流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33610285/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com