fail to create Chargify::Product #37

Closed
dieuit07 opened this Issue Mar 22, 2012 · 10 comments

Projects

None yet

3 participants

Hi everyone, I test create it in console :
Chargify::Product.create("expiration_interval_unit"=>"never", "handle"=>"buzzflock-subscription","interval"=>1, "interval_unit"=>"month", "name"=>"Buzzflock Subscription111111", "price_in_cents"=>0, "request_credit_card"=>true, "require_credit_card"=>true, "return_params"=>"product_id={product_id}&customer_reference={customer_reference}&subscription_id={subscription_id}", "return_url"=>"http://buzzflock.heroku.com/customers/register", "trial_interval"=>1, "trial_interval_unit"=>"month", "trial_price_in_cents"=>0, "update_return_url"=>"http://buzzflock.heroku.com/customers/register_update", "product_family"=> Chargify::ProductFamily.last)
I have this:

    from /home/wf04/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.0.7/lib/active_resource/connection.rb:133:in`handle_response'
    from /home/wf04/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.0.7/lib/active_resource/connection.rb:114:in `request'
    from /home/wf04/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.0.7/lib/active_resource/connection.rb:97:in`block in post'
    from /home/wf04/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.0.7/lib/active_resource/connection.rb:217:in `with_auth'
    from /home/wf04/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.0.7/lib/active_resource/connection.rb:97:in`post'
    from /home/wf04/.rvm/gems/ruby-1.9.2-p290/gems/chargify_api_ares-0.5.1/lib/chargify_api_ares/resources/product.rb:19:in `create'
    from /home/wf04/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.0.7/lib/active_resource/base.rb:1117:in`save'
    from /home/wf04/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.0.7/lib/active_resource/validations.rb:87:in `save_with_validation'
    from /home/wf04/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.0.7/lib/active_resource/observing.rb:11:in`save_with_notifications'
    from (irb):113
    from /home/wf04/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
    from /home/wf04/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in`start'
    from /home/wf04/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:6:in`require'
    from script/rails:6:in `<main>'

instruct me how to create a Chargify::Product , I need it to build test data for Chargify::Subcription

And when I try to create Chargify::Subcription with existing data

 => #<Chargify::Customer:0x0000000814db80 @attributes={"address"=>nil, "address_2"=>nil, "city"=>nil, "country"=>nil, "created_at"=>2011-10-10 07:18:19 UTC, "email"=>"nyros.divya@gmail.com", "first_name"=>"divya", "id"=>968556, "last_name"=>"nyros", "organization"=>nil, "phone"=>nil, "reference"=>"61", "state"=>nil, "updated_at"=>2011-10-10 07:18:19 UTC, "zip"=>nil}, @prefix_options={}> ```

```Chargify::Product.last
 => #<Chargify::Product:0x00000007f1cb90 @attributes={"accounting_code"=>"123", "archived_at"=>nil, "created_at"=>2011-09-13 09:22:02 UTC, "description"=>"buzznewproduct", "expiration_interval"=>nil, "expiration_interval_unit"=>"never", "handle"=>"buzznewproduct", "id"=>50985, "initial_charge_in_cents"=>nil, "interval"=>10, "interval_unit"=>"month", "name"=>"buzznewproduct", "price_in_cents"=>10000, "request_credit_card"=>true, "require_credit_card"=>true, "return_params"=>"product_id={product_id}&customer_reference={customer_reference}&subscription_id={subscription_id}", "return_url"=>nil, "trial_interval"=>2, "trial_interval_unit"=>"month", "trial_price_in_cents"=>1000, "update_return_url"=>nil, "updated_at"=>2011-09-15 12:44:06 UTC, "product_family"=>#<Chargify::ProductFamily:0x00000007f143a0 @attributes={"accounting_code"=>nil, "description"=>nil, "handle"=>"subscriptions", "id"=>13067, "name"=>"Subscriptions"}, @prefix_options={}>}, @prefix_options={}>```

CREATE SUBCRIPTION:
```Chargify::Subscription.create(
      "balance_in_cents"=>0, "cancel_at_end_of_period"=>false, "canceled_at"=>nil, "cancellation_message"=>nil, "expires_at"=>nil,  "state"=>"active", "previous_state"=>"active", "signup_payment_id"=>10918487, "signup_revenue"=>"0.00", "delayed_cancel_at"=>nil, "coupon_code"=>nil,
      :credit_card => {
        :first_name => "Michael",
        :last_name => "Klett",
        :expiration_month => 1,
        :expiration_year => 2010,
        :full_number => "1234-1234-1234-1234"
      },
      :customer => Chargify::Customer.last,
      :product => Chargify::Product.last
    )```

AND ERROR IS:
```=> #<Chargify::Subscription:0x00000007ce6100 @attributes={"balance_in_cents"=>0, "cancel_at_end_of_period"=>false, "canceled_at"=>nil, "cancellation_message"=>nil, "expires_at"=>nil, "state"=>"active", "previous_state"=>"active", "signup_revenue"=>"0.00", "delayed_cancel_at"=>nil, "coupon_code"=>nil}, @prefix_options={}, @remote_errors=#<ActiveResource::ResourceInvalid: Failed.  Response code = 422.  Response message = Unprocessable Entity.>, @validation_context=nil, @errors={:base=>["Product must be specified and be a valid product provided by the seller.", "A Customer must be specified for the subscription to be valid."]}> ```

HOW TO FIX IT? 

I config like spec in gem, when I call :
@chargify_customer = Factory(:chargify_customer) # I change name factory :customer => :chargify_customer
And error is:
Failure/Error: @chargify_customer = Factory(:chargify_customer)#Chargify::Customer.last ActiveResource::UnauthorizedAccess: Failed. Response code = 401. Response message = Unauthorized.

Contributor

@dieuit07, you need to do this:

    hash = {...}
    family = ::Chargify::ProductFamily.find_by_handle('your_product_family_handle_here')
    result = ::Chargify::Product.create(hash.merge('product_family_id' => family.id))

Currently you do not have the product family id and this is needed to construct the URL for the product creation.

HTH

@hedgehog ,Can you write it clearly, I can't understand :D
I know it must create customer first , then productfamily , and the last is product.
But I try to create customer it error Unauthorized In my third comment
Now I try to create with mock_model like this:
@chargify_customer = mock_model(Chargify::Customer,:id => 1,:first_name => 'aaa',:last_name => 'bbb',:email => 'charifycus@gmail.com',:organization=>'abc')
error :)
Failure/Error: @chargify_customer = mock_model(Chargify::Customer,:id => 1,:first_name => 'aaa',:last_name => 'bbb',:email => 'charifycus@gmail.com',:organization=>'abc') Mocha::ExpectationError: unexpected invocation: #<Mock:Chargify::Customer_1>.__mock_proxy() unsatisfied expectations: - expected exactly once, not yet invoked: #<Mock:Chargify::Customer_1>.organization(any_parameters) - expected exactly once, not yet invoked: #<Mock:Chargify::Customer_1>.email(any_parameters) - expected exactly once, not yet invoked: #<Mock:Chargify::Customer_1>.last_name(any_parameters) - expected exactly once, not yet invoked: #<Mock:Chargify::Customer_1>.first_name(any_parameters) - expected exactly once, not yet invoked: #<Mock:Chargify::Customer_1>.id(any_parameters) - expected exactly once, not yet invoked: #<Mock:Chargify::Customer_1>.blank?(any_parameters) - expected exactly once, not yet invoked: #<Mock:Chargify::Customer_1>.valid?(any_parameters) - expected exactly once, not yet invoked: #<Mock:Chargify::Customer_1>.marked_for_destruction?(any_parameters) - expected exactly once, not yet invoked: #<Mock:Chargify::Customer_1>.destroyed?(any_parameters) - expected exactly once, not yet invoked: #<Mock:Chargify::Customer_1>.persisted?(any_parameters)

Contributor

No need to create customers first. Just create:

  1. Product family
  2. Product (see code snippet)

For more detailed examples study the contents of the spec and examples folders.

I think you can close this issue since there is no bug as-far-asI-can-tell, it seems more like you are getting familiar with the API - I know the feeling, we have all been there. Correct?
Hope that helps.

dieuit07 commented Apr 3, 2012

Oh, error is I not replace my key api for it ('test') :D

@dieuit07 dieuit07 closed this Apr 3, 2012

@hedgehog can you link to the examples in spec and examples that show this functionality? I can't seem to track it down and the error message isn't helping me find what I'm missing.

@hedgehog there are no product creation examples in the spec. It just appears to test the find-by handle example. The examples section is also is devoid of a clear product creation example.

I also looked at https://github.com/chargify/chargify_api_ares/blob/master/lib/chargify_api_ares/resources/product.rb in hopes of finding some rdoc or something, no luck.

Any clear Docs anywhere?

Guess I should include @chargify on this thread as well...

Contributor

@jtmkrueger, soory I've moved from using this gem and am writing my own ruby layer - it is simpler (in my mind). I am working flat chat so not much chance or re-factoring it for an OS release any time soon - will try to change that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment