Ruby 的 Paypal 自适应支付

Posted

技术标签:

【中文标题】Ruby 的 Paypal 自适应支付【英文标题】:Paypal Adaptive Payment for Ruby 【发布时间】:2013-01-05 06:31:42 【问题描述】:

我已经看到了关于如何进行付费电话的两个不同版本,我想知道我做错了什么,因为这两个版本都不起作用。

@result = HTTParty.post('https://svcs.sandbox.paypal.com/AdaptivePayments/Pay',
  :body =>
    :actionType => "PAY",
     :currencyCode => "USD",
     :receiverList => 
       :receiver => [
         :amount => "1.00",
          :email => "rec1_1312486368_biz@gmail.com"]
     ,
     :returnUrl => "www.yahoo.com",
     :cancelUrl => "google.com",
     :requestEnvelope => 
       :errorLanguage => "en_US",
       :detailLevel => "ReturnAll"
     ,
     :headers => 
       "X-PAYPAL-SECURITY-USERID" => "caller_13124862354_api1.gmail.com",
       "X-PAYPAL-SECURITY-PASSWORD" => "1234567890",
       "X-PAYPAL-SECURITY-SIGNATURE" => "AbtI7HV1xB428VygBUcIhARzxch4AL78.T19CTeylixNNxDZUu0iO87e",
       "X-PAYPAL-APPLICATION-ID" => "APP-81W284485P518643T",
       "X-PAYPAL-REQUEST-DATA-FORMAT" => "JSON",
       "X-PAYPAL-RESPONSE-DATA-FORMAT" => "JSON"
     
 )

@result = HTTParty.post('https://svcs.sandbox.paypal.com/AdaptivePayments/Pay',
  :body => 
    :actionType => "PAY",
    :currencyCode => "USD",
    "receiverList.receiver(0).email".to_sym => "rec1_1312486368_biz@gmail.com",
    "receiverList.receiver(0).amount".to_sym => "1.00",
    :returnUrl => "www.yahoo.com",
    :cancelUrl => "gizmodo.com",
    :requestEnvelope => 
      :errorLanguage => "en_US",
      :detailLevel => "ReturnAll"
  ,
  :headers => 
    "X-PAYPAL-SECURITY-USERID" => "caller_13124862354_api1.gmail.com",
    "X-PAYPAL-SECURITY-PASSWORD" => "1234567890",
    "X-PAYPAL-SECURITY-SIGNATURE" => "AbtI7HV1xB428VygBUcIhARzxch5AL65.T18CTeylixNNxDZUu0iO87e",
    "X-PAYPAL-APPLICATION-ID" => "APP-81W284485P518643T",
    "X-PAYPAL-REQUEST-DATA-FORMAT" => "JSON",
    "X-PAYPAL-RESPONSE-DATA-FORMAT" => "JSON"
   
)

【问题讨论】:

【参考方案1】:

我推荐使用这个gem,http://rubygems.org/gems/active_paypal_adaptive_payment,你可以付款,预批付款,取消付款...等

您需要使用下一个代码进行付款。

def checkout #this method is for checking, you must add this code to your method on your controller
  recipients = [:email => 'email1',
                 :amount => some_amount,
                 :primary => true,
                :email => 'email2',
                 :amount => recipient_amount,
                 :primary => false
                 ]
  response = gateway.setup_purchase(
    :return_url => url_for(:action => 'action', :only_path => false),
    :cancel_url => url_for(:action => 'action', :only_path => false),
    :ipn_notification_url => url_for(:action => 'notify_action', :only_path => false),
    :receiver_list => recipients
  )

  # For redirecting the customer to the actual paypal site to finish the payment.
  redirect_to (gateway.redirect_url_for(response["payKey"]))
end

return_urlcancel_url 值必须是您自己网站上的相对 url!

问候!

【讨论】:

【参考方案2】:

PayPal 有官方的 Ruby SDK(paypal-sdk-adaptivepayments)

样品可在http://paypal-sdk-samples.herokuapp.com/adaptive_payments/pay获得

【讨论】:

以上是关于Ruby 的 Paypal 自适应支付的主要内容,如果未能解决你的问题,请参考以下文章

PayPal自适应支付链式支付错误

我如何获得 Paypal 自适应支付支付响应

Paypal自适应支付(并行)550001错误

Paypal 自适应/链式支付工作流程

沙盒中的 PayPal 自适应链式支付

使用 Rails 3 的 PayPal 自适应支付