From 6992d6620286c007de87a4044535d93e8a08ea36 Mon Sep 17 00:00:00 2001 From: stveep Date: Fri, 1 Jan 2016 09:37:21 -0500 Subject: [PATCH] Add payments data, reformat dates --- app/serializers/api/order_serializer.rb | 6 ++++-- app/serializers/api/payment_serializer.rb | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 app/serializers/api/payment_serializer.rb diff --git a/app/serializers/api/order_serializer.rb b/app/serializers/api/order_serializer.rb index fb1c3f28d3..8c8260a901 100644 --- a/app/serializers/api/order_serializer.rb +++ b/app/serializers/api/order_serializer.rb @@ -1,8 +1,10 @@ class Api::OrderSerializer < ActiveModel::Serializer - attributes :id, :completed_at, :total, :state, :shipment_state, :payment_state, :outstanding_balance, :total_money, :balance_money + attributes :id, :completed_at, :total, :state, :shipment_state, :payment_state, :outstanding_balance, :total_money, :balance_money, :payments + + has_many :payments, serializer: Api::PaymentSerializer def completed_at - object.completed_at.blank? ? "" : object.completed_at.strftime("%F %T") + object.completed_at.blank? ? "" : object.completed_at.to_formatted_s(:long_ordinal) end def total_money diff --git a/app/serializers/api/payment_serializer.rb b/app/serializers/api/payment_serializer.rb new file mode 100644 index 0000000000..029143403f --- /dev/null +++ b/app/serializers/api/payment_serializer.rb @@ -0,0 +1,14 @@ +class Api::PaymentSerializer < ActiveModel::Serializer + attributes :identifier, :amount, :updated_at, :payment_method + def payment_method + object.payment_method.name + end + + def amount + object.amount.to_money.to_s + end + + def updated_at + object.updated_at.to_formatted_s(:long_ordinal) + end +end