diff --git a/lib/stripe_mock/api/refund.ex b/lib/stripe_mock/api/refund.ex index 9dd8801..f645644 100644 --- a/lib/stripe_mock/api/refund.ex +++ b/lib/stripe_mock/api/refund.ex @@ -7,6 +7,7 @@ defmodule StripeMock.API.Refund do @foreign_key_type :binary_id schema "refunds" do field :amount, :integer + field :created, :integer field :metadata, StripeMock.Metadata, default: %{} field :reason, :string diff --git a/lib/stripe_mock/pagination.ex b/lib/stripe_mock/pagination.ex index 5dd98d1..ad8d6e9 100644 --- a/lib/stripe_mock/pagination.ex +++ b/lib/stripe_mock/pagination.ex @@ -12,14 +12,14 @@ defmodule StripeMock.Pagination do object: "list", url: "/v1/customers", has_more: page.has_more, - data: render_many(page.data, view, template) + data: render_many(page.data, view, template, conn: conn) } end end end @spec paginate(list(), map()) :: Page.t() - def paginate(objects, params) do + def paginate(objects, params \\ %{}) do limit = get_limit(params) objects = diff --git a/lib/stripe_mock_web.ex b/lib/stripe_mock_web.ex index c1ffa35..5e90271 100644 --- a/lib/stripe_mock_web.ex +++ b/lib/stripe_mock_web.ex @@ -23,7 +23,7 @@ defmodule StripeMockWeb do import Plug.Conn import StripeMockWeb.Gettext - import StripeMock.Pagination, only: [paginate: 2] + import StripeMock.Pagination, only: [paginate: 1, paginate: 2] alias StripeMockWeb.Router.Helpers, as: Routes alias StripeMockWeb.Plug, as: SMPlug end diff --git a/lib/stripe_mock_web/views/customer_view.ex b/lib/stripe_mock_web/views/customer_view.ex index 1e5b841..a155246 100644 --- a/lib/stripe_mock_web/views/customer_view.ex +++ b/lib/stripe_mock_web/views/customer_view.ex @@ -1,16 +1,21 @@ defmodule StripeMockWeb.CustomerView do use StripeMockWeb, :view - alias StripeMockWeb.CustomerView + alias StripeMock.{API, Pagination} + alias StripeMockWeb.{CustomerView, CardView} def render("index.json", %{conn: conn, page: page}) do render_page(conn, page, CustomerView, "customer.json") end - def render("show.json", %{customer: customer}) do - render_one(customer, CustomerView, "customer.json") + def render("show.json", %{conn: conn, customer: customer}) do + render_one(customer, CustomerView, "customer.json", conn: conn) end - def render("customer.json", %{customer: customer}) do - customer |> as_map() + def render("customer.json", %{conn: conn, customer: customer}) do + sources = API.list_cards(customer) |> Pagination.paginate() + + customer + |> as_map() + |> Map.put(:sources, render_page(conn, sources, CardView, "card.json")) end end diff --git a/lib/stripe_mock_web/views/refund_view.ex b/lib/stripe_mock_web/views/refund_view.ex index 9391827..0540f29 100644 --- a/lib/stripe_mock_web/views/refund_view.ex +++ b/lib/stripe_mock_web/views/refund_view.ex @@ -11,12 +11,8 @@ defmodule StripeMockWeb.RefundView do end def render("refund.json", %{refund: refund}) do - %{ - id: refund.id, - charge: refund.charge_id, - amount: refund.amount, - metadata: refund.metadata, - reason: refund.reason - } + refund + |> Map.take(~w(id created amount metadata reason)a) + |> Map.put(:charge, refund.charge_id) end end diff --git a/test/stripe_mock_web/controllers/refund_controller_test.exs b/test/stripe_mock_web/controllers/refund_controller_test.exs index 52c975b..835844a 100644 --- a/test/stripe_mock_web/controllers/refund_controller_test.exs +++ b/test/stripe_mock_web/controllers/refund_controller_test.exs @@ -25,6 +25,7 @@ defmodule StripeMockWeb.RefundControllerTest do "id" => "re_" <> _, "amount" => 5000, "charge" => "ch_" <> _, + "created" => _, "metadata" => %{} } = json_response(conn, 200) end