ruby-on-rails - Ruby 的 Paypal 自适应支付

标签 ruby-on-rails ruby paypal paypal-adaptive-payments

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

@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"
   }
)

最佳答案

我推荐使用这个 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!

问候!

关于ruby-on-rails - Ruby 的 Paypal 自适应支付,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14451587/

相关文章:

ruby-on-rails - ActionCable 在 rspec 系统规范期间引发异常

Ruby 需要另一个文件夹上的模块/类

ruby-on-rails - 在 ActiveRecord 中执行后回滚

paypal - 使用自适应支付的点对点支付

c# - PayPal API 混淆 - ExpressCheckout 使用哪一个

ruby-on-rails - tmux:我的其他终端还在运行吗?

javascript - 在 JavaScript 函数中传递可选参数

ruby-on-rails - Ruby on Rails:适用于所有 Controller 的Global Helper方法

ruby - ruby中两个网络掩码的总和

php - 将 Paypal IPN 变量打印到屏幕