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
|
|
|
|
|
2019-09-17 14:48:06 +02:00
|
|
|
validates :payment_method, inclusion: { in: %w[stripe cheque transfer none cash wallet] }
|
2016-03-23 18:39:41 +01:00
|
|
|
|
|
|
|
attr_accessor :invoice_items_ids
|
|
|
|
|
|
|
|
def generate_reference
|
2019-09-19 14:59:22 +02:00
|
|
|
self.reference = InvoiceReferenceService.generate_reference(self, date: created_at, avoir: true)
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def expire_subscription
|
2019-12-02 11:57:25 +01:00
|
|
|
user.subscription.expire(DateTime.current)
|
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',
|
|
|
|
receiver: User.admins,
|
|
|
|
attached_object: self
|
|
|
|
end
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|