我的应用程序有一些基本的电子商务活动。我尝试使用测试authorize.net帐户,它工作正常。我输入了生产模式的API,当我尝试购买任何东西时,我不断被重定向到失败屏幕。我没有收到任何错误,heroku上的日志中没有任何错误,我甚至不知道从哪里开始调试。我成功连接到Authorize.net,交易在开发模式下成功 - 我基于Ryan Bate的RailsCast第145集(http://railscasts.com/episodes/145-integrating-active-merchant),但这里是我的代码的一些亮点(因为我正在测试我,尽管我订购了,我还是强迫它做1美分交易)
in enviroments / production.rb
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :production
::GATEWAY = ActiveMerchant::Billing::AuthorizeNetGateway.new(
:login => "scrubbed",
:password => "scrubbed",
:test => false
)
end
orders_controller.rb
def create
@order = Order.new(params[:order])
@order.cart = current_cart
if @order.save
if @order.purchase
@order.state = 'paid'
@order.save
render :action => "success"
end
else
render :action => "failure"
end
else
redirect_to home_page_path, notice: "The order failed to save"
end
end
def purchase
response = GATEWAY.purchase(1, credit_card, purchase_options)
transactions.create!(:action => "purchase", :amount => price_in_cents, :response => response)
#cart.update_attribute(:purchased_at, Time.now) if response.success?
response.success?
end
order.rb
def purchase
response = GATEWAY.purchase(1, credit_card, purchase_options)
transactions.create!(:action => "purchase", :amount => price_in_cents, :response => response)
#cart.update_attribute(:purchased_at, Time.now) if response.success?
response.success?
end
private
def purchase_options
{
:ip => ip_address,
:billing_address => {
:first_name => first_name,
:last_name => last_name,
:address1 => address_line_1,
:address2 => address_line_2,
:city => city,
:state => billing_state,
:country => "US",
:zip => zip_code,
:phone => phone_number,
:company => company
},
:shipping_address => {
:first_name => sfirst_name,
:last_name => slast_name,
:address1 => saddress_line_1,
:address2 => saddress_line_2,
:city => scity,
:state => sbilling_state,
:country => "US",
:zip => szip_code,
:phone => sphone_number,
:company => scompany
}
}
end
def validate_card
unless credit_card.valid?
credit_card.errors.full_messages.each do |message|
errors.add :base, message
end
end
end
def credit_card
@credit_card ||= ActiveMerchant::Billing::CreditCard.new(
:brand => card_type,
:number => card_number,
:verification_value => card_verification,
:month => card_expires_on.month,
:year => card_expires_on.year,
:first_name => first_name,
:last_name => last_name
)
end
答案 0 :(得分:1)
我没有亲自处理authorize.net,但我使用了类似的Web服务,这也需要PCI合规性。就我而言,这意味着我需要一个有效的SSL证书才能在生产中使用交易。事实上,如果我没记错的话,交易是以非常类似的方式失败的,并且原因并不明显。
看起来authorize.net需要某种类型的安全性,具体取决于您使用的API。 http://developer.authorize.net/integration/
答案 1 :(得分:1)
我需要问一下 - 您是否已经完成了所有工作,以便在Authorize.net和您的银行设置您的商家帐户以进行生产使用,并且您已经与他们协调,以便在开始时将资金过帐到您的银行帐户钱开始进来?
如果是这样,请查看他们的开发者文档页面,了解测试和生产交易之间的区别
http://developer.authorize.net/guides/AIM/5_TestTrans.html
在网关端正确配置所有内容时,在测试模式下工作的事务应该在生产模式下工作。我会联系authorize.net,可能会有技术或管理细节需要最终确定,以便您的帐户处理实时交易。