我一直在集思广益,想出最好的方法来做到这一点,并认为我应该向社区寻求一些想法/清晰度。
基本上从一个单一的支付控制器,我希望能够处理各种支付选项,用户可能会选择。例如,我的控制器被:payment_option => paypal的post请求击中。我想传递处理paypal特定操作的逻辑,然后将url (到paypal)重定向到控制器。
我正在做一个params[:payment_option].constantize来初始化一个Paypal类,但我遇到的问题是无法访问paypal需要的各种数据(即当前用户信息,请求IP地址,cookie数据,url助手等)。
然后我想也许我可以有一个paypal模块,但如何以编程方式包含正确的支付模块?看起来我可能误用了模块的概念,因为我将模块用于特定的逻辑,而不是共享逻辑。
因此,如果用户选择google结帐,则无论支付方式如何,控制器都应该只需要通用指令
使用params:payment_option获取payment_option_url接收payment_option_response
有没有想过做这样的事情的好方法?我过去也遇到过类似的情况,但我从来不确定这是最好的路线。
发布于 2011-06-12 17:38:25
class Payment
def self.handle
raise 'must impliment in subclass'
end
end
class PaypalPayment < Payment
end
class GooglePayment < Payment
end
class PaymentController < ApplicationController
def show_me_the_money
case params[:payment_option]
when 'paypal': url = PaypalPayment.handle params
when 'google': url = GooglePayment.handle params
end
redirect_to url
end
end https://stackoverflow.com/questions/6321166
复制相似问题