2021-04-07 21:43:58 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
|
|
|
|
2021-06-07 20:02:02 +00:00
|
|
|
# rubocop:disable Metrics/BlockLength, Metrics/AbcSize
|
2021-04-07 21:43:58 +00:00
|
|
|
class OfflineTransactionCharge < ApplicationRecord
|
|
|
|
include Model::SubtransactionPaymentable
|
|
|
|
belongs_to :payment
|
|
|
|
|
|
|
|
delegate :gross_amount, :net_amount, :fee_total, to: :payment
|
|
|
|
|
|
|
|
delegate :currency, to: :nonprofit
|
|
|
|
|
|
|
|
concerning :JBuilder do
|
|
|
|
included do
|
|
|
|
setup_houid :offtrxchrg
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_builder(*expand)
|
|
|
|
init_builder(*expand) do |json|
|
|
|
|
json.object 'offline_transaction_charge'
|
|
|
|
json.gross_amount do
|
|
|
|
json.cents gross_amount
|
|
|
|
json.currency currency
|
|
|
|
end
|
|
|
|
|
|
|
|
json.net_amount do
|
|
|
|
json.cents net_amount
|
|
|
|
json.currency currency
|
|
|
|
end
|
|
|
|
|
|
|
|
json.fee_total do
|
|
|
|
json.cents fee_total
|
|
|
|
json.currency currency
|
|
|
|
end
|
|
|
|
|
|
|
|
json.created payment.date.to_i
|
|
|
|
|
|
|
|
json.type 'payment'
|
|
|
|
|
|
|
|
json.add_builder_expansion :nonprofit, :supporter, :subtransaction
|
|
|
|
|
|
|
|
json.add_builder_expansion :trx, json_attribute: :transaction
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_id
|
|
|
|
::Jbuilder.new do |json|
|
|
|
|
json.(self, :id)
|
|
|
|
json.object 'offline_transaction_charge'
|
|
|
|
json.type 'payment'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def publish_created
|
|
|
|
Houdini.event_publisher.announce(
|
|
|
|
:offline_transaction_charge_created,
|
|
|
|
to_event('offline_transaction_charge.created',
|
|
|
|
:nonprofit,
|
|
|
|
:trx,
|
|
|
|
:supporter,
|
|
|
|
:subtransaction).attributes!
|
|
|
|
)
|
|
|
|
Houdini.event_publisher.announce(
|
|
|
|
:payment_created,
|
|
|
|
to_event(
|
|
|
|
'payment.created',
|
|
|
|
:nonprofit,
|
|
|
|
:trx,
|
|
|
|
:supporter,
|
|
|
|
:subtransaction
|
|
|
|
).attributes!
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# rubocop:enable all
|