我目前正在开发一个Rails应用程序,使用Chargify接受循环计费。我已经安装了他们的宝石,并设法与宝石连接到充电。然而,有些订阅会通过,有些则不会。
我的问题是,一旦gem与服务器通信,我如何处理甚至处理响应?
我在开发日志中没有看到任何数据传输成功或失败的指示。gem文档也没有提到任何与此相关的内容。
感谢您的关注。
我正在玩的代码是在我的结帐控制器:
def结帐@customer = customer .new(params[:customer])
Chargify::Customer.create(
:first_name => "Charlie",
:last_name => "Bull",
:email => "charlie@example.com",
:organization => "Chargify"
)
Chargify::Subscription.create(
:product_handle => 'recurring',
:customer_attriburtes => {
:first_name => @customer.shipping_first_name,
:last_name => @customer.shipping_last_name,
:email => @customer.email
},
:payment_profile_attributes => {
:first_name => @customer.shipping_first_name,
:last_name => @customer.shipping_last_name,
:full_number => "1",
:expiration_month => 1,
:expiration_year => 2012,
:billing_address => @customer.shipping_street_address,
:billing_city => @customer.shipping_city,
:billing_state => @customer.shipping_state,
:billing_zip => @customer.shipping_zip_code,
:billing_country => @customer.shipping_country
}
)
#if @subscription.save
# logger.info "saved description"
# redirect_to process_path
#else
# redirect_to :back, :alert =>"There was an error."
#end
结束客户创建正在执行,但订阅没有执行。我只是在寻找一个来自服务器的回调,这样我就可以根据它是否成功采取行动,并找出订阅没有通过的原因。
既然这整个gem使用了ActiveResource,你就不能调用像这样的东西:
# Create a subscription from a customer reference
subscription = Chargify::Subscription.create(
:customer_reference => 'moklett',
:product_handle => 'chargify-api-ares-test',
:credit_card_attributes => {
:first_name => "Michael",
:last_name => "Klett",
:expiration_month => 1,
:expiration_year => 2020,
:full_number => "1"
}
)
if subscription.save
puts "Created Subscription!"
else
puts "Subscription Failed!"
end
并查看记录是否已正确创建?
编辑:你的代码应该工作,但我看到保存的调用被注释掉了。当您调用save
时,它创建或更新记录,测试这应该允许您确定您的记录是否已创建。