【发布时间】: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