Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for voiding invoices #444

Merged
merged 5 commits into from
Jan 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ otp_release:
sudo: false
env:
global:
- STRIPE_MOCK_VERSION=0.38.0
- STRIPE_MOCK_VERSION=0.40.0
- MIX_ENV=test STRIPE_SECRET_KEY=non_empty_secret_key_string
cache:
directories:
Expand Down
12 changes: 12 additions & 0 deletions lib/stripe/subscriptions/invoice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Stripe.Invoice do
- Create an invoice
- Retrieve an invoice
- Update an invoice
- Void an invoice

Does not take options yet.

Expand Down Expand Up @@ -237,4 +238,15 @@ defmodule Stripe.Invoice do
|> cast_to_id([:source])
|> make_request()
end

@doc """
Void an invoice
"""
@spec void(Stripe.id() | t, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
def void(id, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}/void")
|> put_method(:post)
|> make_request()
end
end
3 changes: 1 addition & 2 deletions test/stripe/payment_methods/source_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ defmodule Stripe.SourceTest do

describe "detach/2" do
test "detaches a source from a customer" do
assert {:ok, %{deleted: true, id: "src_123"}} =
Stripe.Source.detach("src_123", %{customer: "cus_123"})
assert {:ok, %{id: "src_123"}} = Stripe.Source.detach("src_123", %{customer: "cus_123"})
Copy link
Author

@ktravers ktravers Dec 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as of stripe-mock v0.39.0, this endpoint now returns a Stripe.Account object without a deleted attribute to match against.

i raised a ticket on stripe-mock, since based on Stripe API docs, it seems like this should respond with a Stripe.Source object instead... but regardless, the response will no longer contain a deleted attribute either way.

@snewcomer given that these changes are related to updating the stripe-mock version, not voiding an invoice, it seems cleaner to pull the version updates and this test change into a separate PR. let me know what you prefer.


assert_stripe_requested(:delete, "/v1/customers/cus_123/sources/src_123")
end
Expand Down
8 changes: 8 additions & 0 deletions test/stripe/subscriptions/invoice_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,12 @@ defmodule Stripe.InvoiceTest do
assert %Stripe.Invoice{} = hd(invoices)
end
end

describe "void/2" do
test "voids an invoice" do
{:ok, invoice} = Stripe.Invoice.retrieve("in_123")
assert {:ok, %Stripe.Invoice{} = _voided_invoice} = Stripe.Invoice.void(invoice)
assert_stripe_requested(:post, "/v1/invoices/#{invoice.id}/void")
end
end
end