2011-07-29 69 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