lib/pay/braintree/subscription.rb in pay-2.7.2 vs lib/pay/braintree/subscription.rb in pay-3.0.0

- old
+ new

@@ -2,15 +2,15 @@ module Braintree class Subscription attr_reader :pay_subscription delegate :active?, + :customer, :canceled?, :ends_at, :name, :on_trial?, - :owner, :processor_id, :processor_plan, :processor_subscription, :prorate, :prorate?, @@ -43,17 +43,17 @@ raise Pay::Braintree::Error, e end def cancel_now! gateway.subscription.cancel(processor_subscription.id) - pay_subscription.update(status: :canceled, ends_at: Time.zone.now) + pay_subscription.update(status: :canceled, ends_at: Time.current) rescue ::Braintree::BraintreeError => e raise Pay::Braintree::Error, e end def on_grace_period? - canceled? && Time.zone.now < ends_at + canceled? && Time.current < ends_at end def paused? false end @@ -68,11 +68,11 @@ end if canceled? && on_trial? duration = trial_ends_at.to_date - Date.today - owner.subscribe( + customer.subscribe( name: name, plan: processor_plan, trial_period: true, trial_duration: duration.to_i, trial_duration_unit: :day @@ -98,11 +98,11 @@ resume return end unless active? - owner.subscribe(name: name, plan: plan, trial_period: false) + customer.subscribe(name: name, plan: plan, trial_period: false) return end braintree_plan = find_braintree_plan(plan) @@ -120,16 +120,11 @@ number_of_billing_cycles: nil, options: { prorate_charges: prorate? } }) - - if result.success? - pay_subscription.update(status: :active, processor_plan: braintree_plan.id, ends_at: nil) - else - raise Error, "Braintree failed to swap plans: #{result.message}" - end + raise Error, "Braintree failed to swap plans: #{result.message}" unless result.success? rescue ::Braintree::BraintreeError => e raise Pay::Braintree::Error, e end private @@ -205,10 +200,10 @@ } end cancel_now! - owner.subscribe(**options.merge(name: name, plan: plan.id)) + customer.subscribe(**options.merge(name: name, plan: plan.id)) end end end end