2011-07-29 34 views
0

我目前正在开发一个Rails应用程序接受使用Chargify定期结算使用官方Chargify宝石响应。我已经安装了their gem并设法连接到Chargify的宝石。但是,有些订阅会通过,有些则不会。如何处理来自Rails的3

我的问题是我该如何处理,甚至处理响应,一旦创业板与服务器进行通信?

我没有看到任何的开发日志,让我一个成功的数据传输或失败的一个迹象。宝石文档也没有提到这方面的任何事情。

感谢您寻找。

UPDATE

我跟在我结账控制器玩弄代码:

高清结账 @customer = Customer.new(PARAMS [:客户])

Chargify::Customer.create(
    :first_name => "Charlie", 
    :last_name => "Bull", 
    :email  => "[email protected]", 
    :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 

结束

客户创建正在经历,但订阅没有。我只是寻找服务器的回调,以便我可以根据它是否成功并找出订阅未通过的原因。

+0

它看起来像代码检查几个请求的响应代码,如果它得到意外的响应,它会引发一个UnexpectedResponseError。你能给我们一些示例代码吗? –

+0

把我的控制器代码。感谢您的回应。 – jklina

回答

2

由于这整个宝石使用的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它创建或更新记录和测试这应该让你决定是否创建或不是你的记录。

+0

我很抱歉没有指定,但官方Chargify API在这里:http://rubydoc.info/gems/chargify_api_ares/0.3.9/frames – jklina

+0

尝试使用上面的代码。也不知道为什么你的保存电话被注释掉或你定义@subscription。 –

+0

是的,我在正确的轨道上,但是我错过了错误消息,我最终发现我可以通过调用:'messages ='' subscription.errors.full_messages.each {| error |消息+ =错误+“
”} logger.info messages' – jklina