FIX: Properly namespace payment serializer (#15)
This commit is contained in:
parent
fb4f50478d
commit
3e6d8734de
|
@ -1,53 +1,55 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class PaymentSerializer < ApplicationSerializer
|
||||
attributes :payment_intent_id,
|
||||
:receipt_email,
|
||||
:url,
|
||||
:created_at_age,
|
||||
:amount,
|
||||
:amount_currency,
|
||||
:username,
|
||||
:user_id
|
||||
module DiscourseSubscriptions
|
||||
class PaymentSerializer < ApplicationSerializer
|
||||
attributes :payment_intent_id,
|
||||
:receipt_email,
|
||||
:url,
|
||||
:created_at_age,
|
||||
:amount,
|
||||
:amount_currency,
|
||||
:username,
|
||||
:user_id
|
||||
|
||||
def created_at_age
|
||||
Time.now - object.created_at
|
||||
end
|
||||
|
||||
def amount_currency
|
||||
ActiveSupport::NumberHelper.number_to_currency(
|
||||
object.amount / 100,
|
||||
precision: 2,
|
||||
unit: currency_unit
|
||||
)
|
||||
end
|
||||
|
||||
def username
|
||||
user&.username
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user
|
||||
begin
|
||||
User.find(object.user_id)
|
||||
rescue
|
||||
nil
|
||||
def created_at_age
|
||||
Time.now - object.created_at
|
||||
end
|
||||
end
|
||||
|
||||
def currency_unit
|
||||
case object.currency
|
||||
when "eur"
|
||||
"€"
|
||||
when "gbp"
|
||||
"£"
|
||||
when "inr"
|
||||
"₹"
|
||||
when "brl"
|
||||
"R$"
|
||||
else
|
||||
"$"
|
||||
def amount_currency
|
||||
ActiveSupport::NumberHelper.number_to_currency(
|
||||
object.amount / 100,
|
||||
precision: 2,
|
||||
unit: currency_unit
|
||||
)
|
||||
end
|
||||
|
||||
def username
|
||||
user&.username
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user
|
||||
begin
|
||||
User.find(object.user_id)
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def currency_unit
|
||||
case object.currency
|
||||
when "eur"
|
||||
"€"
|
||||
when "gbp"
|
||||
"£"
|
||||
when "inr"
|
||||
"₹"
|
||||
when "brl"
|
||||
"R$"
|
||||
else
|
||||
"$"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue