2019-01-09 16:28:23 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Avoir is a special type of Invoice, which it inherits. It is used to
|
|
|
|
# refund an user, based on a previous invoice, or to credit an user's wallet.
|
2016-03-23 18:39:41 +01:00
|
|
|
class Avoir < Invoice
|
|
|
|
belongs_to :invoice
|
|
|
|
|
2019-12-09 11:55:31 +01:00
|
|
|
after_create :notify_admins_refund_created
|
|
|
|
|
2021-06-09 16:42:06 +02:00
|
|
|
# TODO, remove stripe from this list in a future release. For now, we leave it here to allow data migration to v5.0
|
|
|
|
validates :payment_method, inclusion: { in: %w[stripe card cheque transfer none cash wallet] }
|
2016-03-23 18:39:41 +01:00
|
|
|
|
|
|
|
attr_accessor :invoice_items_ids
|
|
|
|
|
2023-09-29 15:26:36 +02:00
|
|
|
delegate :order_number, to: :invoice, allow_nil: true
|
2023-03-16 17:17:00 +01:00
|
|
|
|
2016-03-23 18:39:41 +01:00
|
|
|
def expire_subscription
|
2023-02-17 15:35:06 +01:00
|
|
|
user.subscription.expire
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
2019-12-09 11:55:31 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def notify_admins_refund_created
|
|
|
|
NotificationCenter.call type: 'notify_admin_refund_created',
|
2020-04-29 15:34:30 +02:00
|
|
|
receiver: User.admins_and_managers,
|
2019-12-09 11:55:31 +01:00
|
|
|
attached_object: self
|
|
|
|
end
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|