Skip to content

Commit

Permalink
Cast cardholder to id
Browse files Browse the repository at this point in the history
- fixes beam-community#519: Creating a card with cardholder as a cardholder struct throws
  • Loading branch information
Jason Cartwright authored and Jason Cartwright committed Jul 30, 2019
1 parent a65097d commit 2b3fe7a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
10 changes: 6 additions & 4 deletions lib/stripe/issuing/card.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Stripe.Issuing.Card do
object: String.t(),
authorization_controls: Stripe.Issuing.Types.authorization_controls(),
brand: String.t(),
cardholder: Stripe.Issuing.Cardholder.t(),
cardholder: Stripe.id() | Stripe.Issuing.Cardholder.t(),
created: Stripe.timestamp(),
currency: String.t(),
exp_month: pos_integer,
Expand Down Expand Up @@ -69,7 +69,7 @@ defmodule Stripe.Issuing.Card do
:type => :physical | :virtual,
optional(:authorization_controls) =>
Stripe.Issuing.Types.authorization_controls(),
optional(:cardholder) => Stripe.Issuing.Cardholder.t(),
optional(:cardholder) => Stripe.id() | Stripe.Issuing.Cardholder.t(),
optional(:metadata) => Stripe.Types.metadata(),
optional(:replacement_for) => t | Stripe.id(),
optional(:replacement_reason) => String.t(),
Expand All @@ -82,6 +82,7 @@ defmodule Stripe.Issuing.Card do
|> put_endpoint(@plural_endpoint)
|> put_params(params)
|> put_method(:post)
|> cast_to_id([:cardholder])
|> make_request()
end

Expand All @@ -104,7 +105,7 @@ defmodule Stripe.Issuing.Card do
%{
optional(:authorization_controls) =>
Stripe.Issuing.Types.authorization_controls(),
optional(:cardholder) => Stripe.Issuing.Cardholder.t(),
optional(:cardholder) => Stripe.id() | Stripe.Issuing.Cardholder.t(),
optional(:metadata) => Stripe.Types.metadata(),
optional(:replacement_for) => t | Stripe.id(),
optional(:replacement_reason) => String.t(),
Expand All @@ -117,6 +118,7 @@ defmodule Stripe.Issuing.Card do
|> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}")
|> put_method(:post)
|> put_params(params)
|> cast_to_id([:cardholder])
|> make_request()
end

Expand All @@ -126,7 +128,7 @@ defmodule Stripe.Issuing.Card do
@spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()}
when params:
%{
optional(:cardholder) => Stripe.Issuing.Cardholder.t() | Stripe.id(),
optional(:cardholder) => Stripe.id() | Stripe.Issuing.Cardholder.t(),
optional(:created) => String.t() | Stripe.date_query(),
optional(:ending_before) => t | Stripe.id(),
optional(:exp_month) => String.t(),
Expand Down
46 changes: 39 additions & 7 deletions test/stripe/issuing/card_test.exs
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
defmodule Stripe.Issuing.CardTest do
use Stripe.StripeCase, async: true

test "is creatable" do
params = %{
currency: "usd",
type: :virtual
}
describe "create/2" do
test "is creatable" do
params = %{
currency: "usd",
type: :virtual
}

assert {:ok, %Stripe.Issuing.Card{}} = Stripe.Issuing.Card.create(params)
assert {:ok, %Stripe.Issuing.Card{}} = Stripe.Issuing.Card.create(params)

assert_stripe_requested(:post, "/v1/issuing/cards")
assert_stripe_requested(:post, "/v1/issuing/cards")
end

test "is creatable with cardholder id" do
params = %{
currency: "usd",
type: :virtual,
cardholder: "ich_123"
}

assert {:ok, %Stripe.Issuing.Card{}} = Stripe.Issuing.Card.create(params)

assert_stripe_requested(:post, "/v1/issuing/cards")
end

test "is create with cardholder struct" do
cardholder = %Stripe.Issuing.Cardholder{
id: "ich_123",
object: "issuing.cardholder",
type: "individual"
}

params = %{
currency: "usd",
type: :virtual,
cardholder: cardholder
}

assert {:ok, %Stripe.Issuing.Card{}} = Stripe.Issuing.Card.create(params)

assert_stripe_requested(:post, "/v1/issuing/cards")
end
end

test "is retrievable" do
Expand Down

0 comments on commit 2b3fe7a

Please sign in to comment.