我正在整合 Paypal Express 付款。我正在调整标准结帐,并且正在使用活跃商家 gem。设置应该类似于response=gateway.setup_purchase(price, details)
,其中详细信息是 PayPal 需要的所有参数。快速网关需要 return_url 和 cancel_return_url。
当我尝试通过提交按钮执行付款时,我得到:
Order xx failed with error message undefined method `checkout_thank_you_url' for #<Order:0x1081e1bb8>
在我的订单模型中,我有以下部分:
#app/models/order.rb
def process
process_with_active_merchant
save!
self.status == 'processed'
end
private
def process_with_active_merchant
ActiveMerchant::Billing::Base.mode = :test
gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(
:login => 'sandbox-account',
:password => 'sandbox-password',
:signature => "sandbox-secret"
params = {
:order_id => self.id,
:email => email,
:address => { :address1 => ship_to_address,
:city => ship_to_city,
:country => ship_to_country,
:zip => ship_to_postal_code
} ,
:description => 'Books',
:ip => customer_ip,
:return_url => checkout_thank_you_url(@order), # return here if payment success
:cancel_return_url => checkout_index_url(@order) # return here if payment failed
}
response = gateway.setup_purchase((@order.total * 100).round(2), params)
if response.success?
self.status = 'processed'
else
self.error_message = response.message
self.status = 'failed'
end
end
该方法在结帐控制器中调用
def place_order
@order = Order.new(params[:order])
@order.customer_ip = request.remote_ip
populate_order
...
@order.process
...
end
def thank_you
...
end
我怎样才能让它工作?先感谢您!
更新
我想我必须指定控制器和操作,但是在使用时:
:return_url => url_for(:controller => :checkout, :action => "thank_you")
我得到:
Order 98 failed with error message undefined method `url_for' for #<Order:0x1065471d8>