繁体   English   中英

设置贝宝自适应支付流程

[英]Setting up PayPal adaptive payment flow

我正在使用贝宝(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 => [{...}, {...}]}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM