2019-09-13 22:56:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-07-06 16:19:45 -04:00
|
|
|
module DiscourseSubscriptions
|
|
|
|
class PaymentSerializer < ApplicationSerializer
|
|
|
|
attributes :payment_intent_id,
|
|
|
|
:receipt_email,
|
|
|
|
:url,
|
|
|
|
:created_at_age,
|
|
|
|
:amount,
|
|
|
|
:amount_currency,
|
|
|
|
:username,
|
|
|
|
:user_id
|
2019-09-14 00:20:16 -04:00
|
|
|
|
2020-07-06 16:19:45 -04:00
|
|
|
def created_at_age
|
|
|
|
Time.now - object.created_at
|
|
|
|
end
|
2019-09-14 01:55:25 -04:00
|
|
|
|
2020-07-06 16:19:45 -04:00
|
|
|
def amount_currency
|
|
|
|
ActiveSupport::NumberHelper.number_to_currency(
|
|
|
|
object.amount / 100,
|
|
|
|
precision: 2,
|
|
|
|
unit: currency_unit
|
|
|
|
)
|
|
|
|
end
|
2019-09-14 01:55:25 -04:00
|
|
|
|
2020-07-06 16:19:45 -04:00
|
|
|
def username
|
|
|
|
user&.username
|
|
|
|
end
|
2019-09-14 02:34:51 -04:00
|
|
|
|
2020-07-06 16:19:45 -04:00
|
|
|
private
|
2019-09-14 01:55:25 -04:00
|
|
|
|
2020-07-06 16:19:45 -04:00
|
|
|
def user
|
|
|
|
begin
|
|
|
|
User.find(object.user_id)
|
|
|
|
rescue
|
|
|
|
nil
|
|
|
|
end
|
2020-04-23 06:36:02 -04:00
|
|
|
end
|
2019-09-14 02:34:51 -04:00
|
|
|
|
2020-07-06 16:19:45 -04:00
|
|
|
def currency_unit
|
|
|
|
case object.currency
|
|
|
|
when "eur"
|
|
|
|
"€"
|
|
|
|
when "gbp"
|
|
|
|
"£"
|
|
|
|
when "inr"
|
|
|
|
"₹"
|
|
|
|
when "brl"
|
|
|
|
"R$"
|
2021-04-06 10:59:27 -04:00
|
|
|
when "dkk"
|
|
|
|
"KR"
|
2021-04-13 06:20:00 -04:00
|
|
|
when "sgd"
|
|
|
|
"S$"
|
2020-07-06 16:19:45 -04:00
|
|
|
else
|
|
|
|
"$"
|
|
|
|
end
|
2019-09-14 01:55:25 -04:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 22:56:28 -04:00
|
|
|
end
|