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
- API_STATUS_MAP =
Maps AbacatePay API checkout-like statuses (Resources::Subscriptions reuses Enums::Checkouts::Statuses) to local Pay::Subscription statuses. PENDING is the default on creation: the first payment hasn’t settled yet, mirroring Stripe’s “incomplete”.
{ "PENDING" => "incomplete", "PAID" => "active", "CANCELLED" => "canceled", "EXPIRED" => "canceled", "REFUNDED" => "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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/pay/abacatepay/subscription.rb', line 24 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
93 94 95 96 97 |
# File 'app/models/pay/abacatepay/subscription.rb', line 93 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
58 59 60 61 62 63 |
# File 'app/models/pay/abacatepay/subscription.rb', line 58 def cancel(**) Rails.logger.warn( "[pay-abacatepay] AbacatePay does not support cancel-at-period-end; cancelling immediately" ) cancel_now!(**) end |
#cancel_now!(**_options) ⇒ Object
65 66 67 68 69 70 |
# File 'app/models/pay/abacatepay/subscription.rb', line 65 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
82 83 84 85 |
# File 'app/models/pay/abacatepay/subscription.rb', line 82 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.
89 90 91 |
# File 'app/models/pay/abacatepay/subscription.rb', line 89 def past_due? false end |
#resume ⇒ Object
72 73 74 75 |
# File 'app/models/pay/abacatepay/subscription.rb', line 72 def resume raise NotImplementedError, "AbacatePay does not support resuming cancelled subscriptions; create a new subscription" end |
#swap(_plan, **_options) ⇒ Object
77 78 79 80 |
# File 'app/models/pay/abacatepay/subscription.rb', line 77 def swap(_plan, **) raise NotImplementedError, "AbacatePay does not support plan swap; cancel the subscription and create a new one" end |