Class: Pay::Abacatepay::Subscription
- Inherits:
-
Subscription
- Object
- Subscription
- Pay::Abacatepay::Subscription
- Defined in:
- app/models/pay/abacatepay/subscription.rb
Constant Summary collapse
- STATUS_FROM_EVENT =
{ "subscription.completed" => "active", "subscription.renewed" => "active", "subscription.cancelled" => "canceled" }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #api_record ⇒ Object
- #cancel(**options) ⇒ Object
- #cancel_now!(**_options) ⇒ Object
- #change_quantity(_quantity, **_options) ⇒ Object
-
#past_due? ⇒ Boolean
AbacatePay does not emit payment-failure events, so we cannot observe a past_due state.
- #resume ⇒ Object
- #swap(_plan, **_options) ⇒ Object
Class Method Details
.sync(processor_id, event: nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/pay/abacatepay/subscription.rb', line 10 def self.sync(processor_id, event: nil) return if processor_id.blank? subscription = Pay::Abacatepay::Subscription.find_by(processor_id: processor_id) customer = subscription&.customer customer ||= Pay::Customer.find_by(processor: "abacatepay", processor_id: event&.customer_id) if event if customer.nil? Rails.logger.warn("[pay-abacatepay] cannot sync subscription #{processor_id}: Pay::Customer not found") return end subscription ||= Pay::Abacatepay::Subscription.new(customer: customer, processor_id: processor_id) assign_attributes_from(subscription, event) if event subscription.save! subscription end |
Instance Method Details
#api_record ⇒ Object
79 80 81 82 83 |
# File 'app/models/pay/abacatepay/subscription.rb', line 79 def api_record ::AbacatePay.subscriptions.send(:request, "GET", "get", params: {id: processor_id}) rescue ::AbacatePay::Error => e raise Pay::Abacatepay::Error, e. end |
#cancel(**options) ⇒ Object
44 45 46 47 48 49 |
# File 'app/models/pay/abacatepay/subscription.rb', line 44 def cancel(**) Rails.logger.warn( "[pay-abacatepay] AbacatePay does not support cancel-at-period-end; cancelling immediately" ) cancel_now!(**) end |
#cancel_now!(**_options) ⇒ Object
51 52 53 54 55 56 |
# File 'app/models/pay/abacatepay/subscription.rb', line 51 def cancel_now!(**) ::AbacatePay.subscriptions.send(:request, "POST", "cancel", params: {id: processor_id}) update!(status: "canceled", ends_at: Time.current) rescue ::AbacatePay::Error => e raise Pay::Abacatepay::Error, e. end |
#change_quantity(_quantity, **_options) ⇒ Object
68 69 70 71 |
# File 'app/models/pay/abacatepay/subscription.rb', line 68 def change_quantity(_quantity, **) raise NotImplementedError, "AbacatePay does not support quantity changes" end |
#past_due? ⇒ Boolean
AbacatePay does not emit payment-failure events, so we cannot observe a past_due state. Always false.
75 76 77 |
# File 'app/models/pay/abacatepay/subscription.rb', line 75 def past_due? false end |
#resume ⇒ Object
58 59 60 61 |
# File 'app/models/pay/abacatepay/subscription.rb', line 58 def resume raise NotImplementedError, "AbacatePay does not support resuming cancelled subscriptions; create a new subscription" end |
#swap(_plan, **_options) ⇒ Object
63 64 65 66 |
# File 'app/models/pay/abacatepay/subscription.rb', line 63 def swap(_plan, **) raise NotImplementedError, "AbacatePay does not support plan swap; cancel the subscription and create a new one" end |