Class: Wbase::UpdateSubscription
- Inherits:
-
Object
- Object
- Wbase::UpdateSubscription
- Defined in:
- app/services/wbase/update_subscription.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#subscription ⇒ Object
readonly
Returns the value of attribute subscription.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(user, params) ⇒ UpdateSubscription
constructor
A new instance of UpdateSubscription.
- #stripe_customer ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(user, params) ⇒ UpdateSubscription
Returns a new instance of UpdateSubscription.
5 6 7 8 9 |
# File 'app/services/wbase/update_subscription.rb', line 5 def initialize(user, params) @params = params @user = user @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
3 4 5 |
# File 'app/services/wbase/update_subscription.rb', line 3 def errors @errors end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'app/services/wbase/update_subscription.rb', line 3 def params @params end |
#subscription ⇒ Object (readonly)
Returns the value of attribute subscription.
3 4 5 |
# File 'app/services/wbase/update_subscription.rb', line 3 def subscription @subscription end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'app/services/wbase/update_subscription.rb', line 3 def user @user end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/services/wbase/update_subscription.rb', line 19 def call Rails.logger.info("Updating Stripe Customer for #{ user.email }") card = stripe_customer.sources.create(card: params[:credit_card_token]) card.save stripe_customer.default_source = card.id stripe_customer.save subscription.update!(params) Rails.logger.info stripe_customer rescue Stripe::CardError => e # Since it's a decline, Stripe::CardError will be caught body = e.json_body err = body[:error] @errors << body[:error] puts "Status is: #{e.http_status}" puts "Type is: #{err[:type]}" puts "Code is: #{err[:code]}" # param is '' in this case puts "Param is: #{err[:param]}" puts "Message is: #{err[:message]}" rescue Stripe::InvalidRequestError => e Rails.logger.error "Stripe error while updating card: #{ e. }" @errors << e. end |
#stripe_customer ⇒ Object
15 16 17 |
# File 'app/services/wbase/update_subscription.rb', line 15 def stripe_customer @stripe_customer ||= subscription.stripe_customer end |
#valid? ⇒ Boolean
43 44 45 |
# File 'app/services/wbase/update_subscription.rb', line 43 def valid? errors.empty? end |