【问题标题】:Routing Error Adaptive Payments Rails路由错误自适应支付 Rails
【发布时间】:2015-01-19 19:14:10
【问题描述】:

我已尽我所能,需要帮助(请!)。我正在尝试为我的点对点市场中的项目设置付款。我想我已经正确设置了所有内容,但是当我按下我创建的支付按钮时,它不会重定向到 PayPal,而是似乎只是刷新了项目页面。我认为这是一个路由错误,但并不完全是肯定的。

这是我的项目模型中的内容:

   class Item < ActiveRecord::Base
      belongs_to :user 
      belongs_to :category 
      default_scope -> { order('created_at DESC') }

      def recipients
       [
         { email: '<biz email address>', amount: '1.00', primary: false },
         { email: 'item.user.booth.paypal_email', amount: '5.00', primary: true }
       ]
      end
    end

在 Items 控制器中:

class ItemsController < ApplicationController
      include ActiveMerchant::Billing::Integrations
        before_action :logged_in_user, only: [:edit, :update, :new, :destroy]
      before_action :correct_user, only: [:edit, :update, :destroy]

        def show
            @item = Item.find(params[:id])
        end


      def gateway
        @gateway ||= ActiveMerchant::Billing::PaypalAdaptivePayment.new \
        login: '<login email>',
        password: '<password>',
        signature: '<signature>',
        appid: 'APP-80W284485P519543T'

        response = gateway.setup_purchase \
        return_url: root_url,
        cancel_url: item_path,
        #ipn_notification_url: <notification URL>,
        receiver_list: recipients

        redirect_to gateway.redirect_url_for(response['payKey'])
      end
end 

按钮的链接在views/items/show中:

<%= link_to "Buy Now with PayPal", @gateway, class: "btn btn-primary col-md-8", id: "paypal-buy-btn"%>

我还想知道错误是否可能是因为我没有在 show 操作中定义 @gateway,但是当我尝试这样做时,我也会收到错误。

谁能帮我解决这个难题?谢谢你的帮助。

【问题讨论】:

  • 我们的 Ruby 人员已经检查了您的代码。他不喜欢它,或者没有看到全貌。因此,这只是一个评论。从长远来看,我建议使用工作 git,例如github.com/jpablobr/active_paypal_adaptive_payment 似乎很有希望,并且有一些关于链式支付的更详细的文档(到 x.com 的链接有点过时了)
  • 这正是我使用的 git 并且文档也不完整,尤其不适合初学者。
  • response['payKey'] 返回什么? gateway.redirect_url_for(response['payKey']) 返回什么?另外,我认为收件人的金额需要是浮点数,而不是字符串,但我不能 100% 确定(ActiveMerchant 可能同时接受这两者?)。

标签: ruby-on-rails ruby-on-rails-4 paypal routing


【解决方案1】:

除了我的评论之外,这里还有一些事情,如果它实际上没有帮助,我将编辑此答案或稍后将其删除。只需要回答而不是在小评论框中输入。

首先,您的视图会刷新,因为@gatewaynil,所以您链接到nil,它什么都不做。您需要为您的 gateway 方法定义一个路由,如下所示:

resources :items do
  post :gateway, on: :member
end

现在您将定义 gateway_item_path(item),因此您将链接到它:

<%= link_to "Buy Now with PayPal", gateway_item_path(@item), method: :post, ... %>

现在,只要您点击链接,您的 gateway 方法就会被命中。在您的网关方法中,您需要找到Item,如图所示:

@item = Item.find(params[:id])

当您设置网关时,您需要将项目传递给取消 url,以便它返回到该特定项目,因此将其更改为:

item_url(@item)

并将您的收件人更改为@item.recipients,因为您已经在模型上定义了该方法。

告诉我进展如何!

【讨论】:

    猜你喜欢
    • 2016-04-02
    • 2013-08-25
    • 2016-03-14
    • 2013-09-10
    • 2015-02-20
    • 2012-07-04
    • 1970-01-01
    • 2011-06-16
    相关资源
    最近更新 更多