Skip to content

Commit

Permalink
adds Stripe.Refund module
Browse files Browse the repository at this point in the history
  • Loading branch information
poops committed May 26, 2017
1 parent 1e9b87d commit 608c5b3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions lib/stripe/refund.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
defmodule Stripe.Refund do
@moduledoc """
Work with Stripe refund objects.
You can:
- Create a refund
- Retrieve a refund
- Update a refund
Stripe API reference: https://stripe.com/docs/api#refunds
"""

@type t :: %__MODULE__{}

defstruct [
:id, :object, :amount, :balance_transaction, :charge, :created, :currency,
:metadata, :reason, :receipt_number, :status
]

@plural_endpoint "refunds"

@schema %{
charge: [:create],
amount: [:create],
metadata: [:create, :update],
reason: [:create],
refund_application_fee: [:create],
reverse_transfer: [:create],
}

@nullable_keys [
:metadata
]

@doc """
Create a refund.
"""
@spec create(map, Keyword.t) :: {:ok, t} | {:error, Stripe.api_error_struct}
def create(changes, opts \\ []) do
Stripe.Request.create(@plural_endpoint, changes, @schema, opts)
end

@doc """
Retrieve a refund
"""
@spec retrieve(binary, Keyword.t) :: {:ok, t} | {:error, Stripe.api_error_struct}
def retrieve(id, opts \\ []) do
endpoint = @plural_endpoint <> "/" <> id
Stripe.Request.retrieve(endpoint, opts)
end

@doc """
Update a refund
"""
@spec update(binary, map, Keyword.t) :: {:ok, t} | {:error, Stripe.api_error_struct}
def update(id, changes, opts \\ []) do
endpoint = @plural_endpoint <> "/" <> id
Stripe.Request.update(endpoint, changes, @schema, @nullable_keys, opts)
end
end

1 change: 1 addition & 0 deletions test/stripe/util_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule Stripe.UtilTest do
assert object_name_to_module("invoice") == Stripe.Invoice
assert object_name_to_module("list") == Stripe.List
assert object_name_to_module("plan") == Stripe.Plan
assert object_name_to_module("refund") == Stripe.Refund
assert object_name_to_module("subscription") == Stripe.Subscription
assert object_name_to_module("token") == Stripe.Token
end
Expand Down

0 comments on commit 608c5b3

Please sign in to comment.