0

I'm currently developing a Rails application to accept recurring billing using Chargify. I've installed their gem and managed to connect to Chargify with the gem. However, some subscriptions go through and some do not.

My question is how do I handle or even process the response once the gem communicates with the server?

I don't see anything in the development logs that gives me any indication of a successful data transfer or a failed one. The gem documentation also does not mention anything regarding this.

Thanks for looking.

UPDATE

The code I'm playing around with is in my checkout controller:

def checkout @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

end

The customer create is going through, but the Subscription does not. I'm just looking for a callback from the server so I can act based off whether it succeeded and find out why the subscription isn't going through.

jklina
  • 3,407
  • 27
  • 42
  • It looks like the code checks the response code for a few requests and if it gets an unexpected response it raises an UnexpectedResponseError. Can you give us some example code? – Devin M Jul 29 '11 at 19:42
  • Put my controller code up. Thanks for the response. – jklina Jul 29 '11 at 19:53

1 Answers1

2

Since this whole gem uses ActiveResource cant you just call something like:

# 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

and see if the record has been created correctly?

EDIT: Your code should work but I see that the call to save is commented out. When you call save it creates or updates the record and testing this should allow you to determine if your record was created or not.

Devin M
  • 9,636
  • 2
  • 33
  • 46
  • I'm sorry for not specifying, but the official Chargify API is here: http://rubydoc.info/gems/chargify_api_ares/0.3.9/frames – jklina Jul 29 '11 at 22:20
  • Try using the code above. Also im not sure why your save call is commented out or where you define @subscription. – Devin M Jul 29 '11 at 23:24
  • Yep, I was on the right track, but what I was missing was getting the error messages which I eventually found I could get by calling: `messages = '' subscription.errors.full_messages.each {|error| messages += error + "
    "} logger.info messages`
    – jklina Aug 02 '11 at 15:54