ruby-on-railsspreesubscriptionschargify

Chargify Subscription Parameters


I am currently working on an existing Ruby on Rails App that is built on Spree and Chargify for subscriptions and Payments. The person who worked on the application before did not mentioned any comments and also most of things are not the true representation of RESTful Rails Application.

Anyhow I have 2 things which I want to clarify. First of all can somebody explain me what this piece of code is doing :

couponJSON = `curl -u #{Chargify.api_key}:x https://#{Chargify.subdomain}.chargify.com/product_families/#{subscription_product_family_id}/coupons/find.json?code=#{params[:payment_form][:coupon_code]}`

coupon_amount_in_cents = ActiveSupport::JSON.decode(couponJSON)['coupon']['amount_in_cents']

Second thing I have to make a GET request to :

https://[@subdomain].chargify.com/subscriptions/[@subscription.id].json

The json response returned is going to be this :

> {"subscription":{
>         "id":[@subscription.id],
>         "state":"active",
>         "balance_in_cents":0,
>         "current_period_started_at":`auto
> generated`,
>         "current_period_ends_at":`auto generated`,
>         "activated_at":`auto generated`,
>         "trial_ended_at":`auto generated`,
>         "trial_started_at":`auto generated`,
>         "expires_at":`auto generated`,
>         "created_at":`auto generated`,
>         "updated_at":`auto generated`,
>         "cancellation_message":null,
>         "customer":{
>           "id":`auto generated`,
>           "first_name":`your value`,
>           "last_name":`your value`,
>           "email":`your value`,
>           "organization":`your value`,
>           "reference":`your value`,
>           "updated_at":`auto generated`,
>           "created_at":`auto generated`
>         },
>         "product":{
>           "id":`auto generated`,
>           "name":`your value`,
>           "handle":`your value`,
>           "price_in_cents":`your value`,
>           "accounting_code":`your value`,
>           "interval":`your value`,
>           "interval_unit":`your value`,
>           "product_family":{
>             "id":`auto generated`,
>             "name":`your value`,
>             "handle":`your value`,
>             "accounting_code":`your value`
>           }
>         },
>         "credit_card":{
>           "first_name":`your value`,
>           "last_name":`your value`,
>           "masked_card_number":`your value`,
>           "card_type":`auto generated`,
>           "expiration_month":`your value`,
>           "expiration_year":`your value`
>         }
>       }}

My question would be what is going to be the least time consuming way of making the get request to the above URL ? Second thing I have to grab couple of parameters received and show on the page titled "information.html.erb". I assume the best way would be doing something like this :

balance = params[_json][:balance_in_cents].

I am not sure if I am doing it right or not. Any suggestions would be appreciated.

Thanks


Solution

  • HTTParty and Multi Json solved both of these problems for me.