首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >路由错误Adaptive Payments Rails

路由错误Adaptive Payments Rails
EN

Stack Overflow用户
提问于 2015-01-20 03:14:11
回答 1查看 75关注 0票数 0

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

以下是我的项目模型中的内容:

代码语言:javascript
复制
   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

在项目控制器中:

代码语言:javascript
复制
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中:

代码语言:javascript
复制
<%= link_to "Buy Now with PayPal", @gateway, class: "btn btn-primary col-md-8", id: "paypal-buy-btn"%>

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

有人能帮我解开这个难题吗?谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2015-01-30 03:01:33

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

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

代码语言:javascript
复制
resources :items do
  post :gateway, on: :member
end

现在您已经定义了gateway_item_path(item),所以您将改为链接到它:

代码语言:javascript
复制
<%= link_to "Buy Now with PayPal", gateway_item_path(@item), method: :post, ... %>

现在,每当您单击该链接时,您的gateway方法都会被击中。在网关方法中,您需要找到Item,如图所示:

代码语言:javascript
复制
@item = Item.find(params[:id])

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

item_url(@item)

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

让我知道它进行得怎么样!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28031925

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档