Skip to content

Commit

Permalink
Add created to Refund
Browse files Browse the repository at this point in the history
  • Loading branch information
nkezhaya committed Jun 4, 2019
1 parent 922a844 commit 1a0d311
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions lib/stripe_mock/api/refund.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/stripe_mock/pagination.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe_mock_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions lib/stripe_mock_web/views/customer_view.ex
Original file line number Diff line number Diff line change
@@ -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
10 changes: 3 additions & 7 deletions lib/stripe_mock_web/views/refund_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule StripeMockWeb.RefundControllerTest do
"id" => "re_" <> _,
"amount" => 5000,
"charge" => "ch_" <> _,
"created" => _,
"metadata" => %{}
} = json_response(conn, 200)
end
Expand Down

0 comments on commit 1a0d311

Please sign in to comment.