开发者

How do I process responses from using the official Chargify gem in Rails 3.

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜