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

Fix most dialyzer errors #325

Merged
merged 1 commit into from
Nov 25, 2017
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
7 changes: 7 additions & 0 deletions lib/stripe.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ defmodule Stripe do
use Application

@type id :: String.t()
@type date_query :: %{
gt: timestamp,
gte: timestamp,
lt: timestamp,
lte: timestamp
}
@type options :: Keyword.t()
@type timestamp :: pos_integer

@doc """
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ defmodule Stripe.API do
error =
case Poison.decode(body) do
{:ok, %{"error_description" => _} = api_error} ->
Error.from_oauth_error(status, api_error, request_id)
Error.from_stripe_error(status, api_error, request_id)

{:ok, %{"error" => api_error}} ->
Error.from_stripe_error(status, api_error, request_id)
Expand Down
12 changes: 6 additions & 6 deletions lib/stripe/connect/account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ defmodule Stripe.Account do
external_accounts: Stripe.List.of(Stripe.BankAccount.t() | Stripe.Card.t()),
keys: keys | nil,
legal_entity: legal_entity,
metadata: Stripe.Types.metdata(),
metadata: Stripe.Types.metadata(),
payout_schedule: Stripe.Types.transfer_schedule(),
payout_statement_descriptor: String.t() | nil,
payouts_enabled: boolean,
Expand Down Expand Up @@ -191,7 +191,7 @@ defmodule Stripe.Account do
| String.t()
| nil,
legal_entity: legal_entity,
metadata: Stripe.Types.metdata() | nil,
metadata: Stripe.Types.metadata() | nil,
payout_schedule: Stripe.Types.transfer_schedule() | nil,
payout_statement_descriptor: String.t() | nil,
product_description: String.t() | nil,
Expand All @@ -200,7 +200,7 @@ defmodule Stripe.Account do
support_phone: String.t() | nil,
support_url: String.t() | nil,
tos_acceptance: tos_acceptance | nil
}
} | %{}

@doc """
Create an account.
Expand Down Expand Up @@ -259,7 +259,7 @@ defmodule Stripe.Account do
| String.t()
| nil,
legal_entity: legal_entity,
metadata: Stripe.Types.metdata() | nil,
metadata: Stripe.Types.metadata() | nil,
payout_schedule: Stripe.Types.transfer_schedule() | nil,
payout_statement_descriptor: String.t() | nil,
product_description: String.t() | nil,
Expand All @@ -268,7 +268,7 @@ defmodule Stripe.Account do
support_phone: String.t() | nil,
support_url: String.t() | nil,
tos_acceptance: tos_acceptance | nil
}
} | %{}

@doc """
Update an account.
Expand Down Expand Up @@ -326,7 +326,7 @@ defmodule Stripe.Account do
ending_before: t | Stripe.id(),
limit: 1..100,
starting_after: t | Stripe.id()
}
} | %{}
def list(params \\ %{}, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint)
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/connect/application_fee.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Stripe.ApplicationFee do
account: Stripe.id() | Stripe.Account.t(),
amount: integer,
amount_refunded: integer,
application: Stripe.id() | Stripe.Application.t(),
application: Stripe.id(),
balance_transaction: Stripe.id() | Stripe.BalanceTransaction.t(),
charge: Stripe.id() | Stripe.Charge.t(),
created: Stripe.timestamp(),
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/connect/transfer_reversal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Stripe.TransferReversal do
currency: String.t(),
description: boolean,
metadata: Stripe.Types.metadata(),
transfer: String.id() | Stripe.Transfer.t()
transfer: Stripe.id() | Stripe.Transfer.t()
}

defstruct [
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/core_resources/balance_transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ defmodule Stripe.BalanceTransaction do
source: Stripe.id() | Stripe.Source.t() | nil,
starting_after: Stripe.id() | Stripe.BalanceTransaction.t() | nil,
type: String.t() | nil
}
} | %{}
def all(params \\ %{}, opts \\ []) do
new_request(opts)
|> put_endpoint(@endpoint)
Expand Down
24 changes: 16 additions & 8 deletions lib/stripe/core_resources/charge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ defmodule Stripe.Charge do
network_status: String.t() | nil,
reason: String.t() | nil,
risk_level: String.t(),
rule: Stripe.id() | Stripe.Rule.t(),
rule: Stripe.id() | charge_outcome_rule,
seller_message: String.t() | nil,
type: String.t()
}

@type charge_outcome_rule :: %{
action: String.t(),
id: String.t(),
predicate: String.t()
}

@type card_info :: %{
exp_month: number,
exp_year: number,
Expand All @@ -51,7 +57,7 @@ defmodule Stripe.Charge do
object: String.t(),
amount: non_neg_integer,
amount_refunded: non_neg_integer,
application: Stripe.id() | Stripe.Application.t() | nil,
application: Stripe.id() | nil,
application_fee: Stripe.id() | Stripe.ApplicationFee.t() | nil,
balance_transaction: Stripe.id() | Stripe.BalanceTransaction.t() | nil,
captured: boolean,
Expand Down Expand Up @@ -147,7 +153,7 @@ defmodule Stripe.Charge do
},
receipt_email: String.t(),
statement_descriptor: String.t()
}
} | %{}
def capture(id, params, opts) do
new_request(opts)
|> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}/capture")
Expand All @@ -167,10 +173,12 @@ defmodule Stripe.Charge do
capture(id, %{}, opts)
end

@spec capture(Stripe.id() | t, map) :: {:ok, t} | {:error, Stripe.Error.t()}
def capture(id, params) when is_map(params) do
capture(id, params, [])
end

@spec capture(Stripe.id() | t) :: {:ok, t} | {:error, Stripe.Error.t()}
def capture(id) do
Stripe.Util.log_deprecation("Please use `capture/3` instead.")
capture(id, %{}, [])
Expand Down Expand Up @@ -200,11 +208,11 @@ defmodule Stripe.Charge do
on_behalf_of: Stripe.id() | Stripe.Account.t(),
metadata: map,
receipt_email: String.t(),
shipping: Stripe.Customer.shipping(),
shipping: Stripe.Types.shipping(),
customer: Stripe.id() | Stripe.Customer.t(),
source: Stripe.id() | Stripe.Card.t() | card_info,
statement_descriptor: String.t()
}
} | %{}
def create(params, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint)
Expand Down Expand Up @@ -252,9 +260,9 @@ defmodule Stripe.Charge do
fraud_details: user_fraud_report,
metadata: Stripe.Types.metadata(),
receipt_email: String.t(),
shipping: Stripe.Customer.shipping(),
shipping: Stripe.Types.shipping(),
transfer_group: String.t()
}
} | %{}
def update(id, params, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}")
Expand Down Expand Up @@ -282,7 +290,7 @@ defmodule Stripe.Charge do
},
starting_after: t | Stripe.id(),
transfer_group: String.t()
}
} | %{}
def list(params \\ %{}, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint)
Expand Down
6 changes: 3 additions & 3 deletions lib/stripe/core_resources/customer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ defmodule Stripe.Customer do
metadata: Stripe.Types.metadata(),
shipping: Stripe.Types.shipping() | nil,
source: Stripe.Source.t() | nil
}
} | %{}
def create(params, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint)
Expand Down Expand Up @@ -105,7 +105,7 @@ defmodule Stripe.Customer do
metadata: Stripe.Types.metadata(),
shipping: Stripe.Types.shipping() | nil,
source: Stripe.Source.t() | nil
}
} | %{}
def update(id, params, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}")
Expand Down Expand Up @@ -133,7 +133,7 @@ defmodule Stripe.Customer do
ending_before: t | Stripe.id() | nil,
limit: 1..100 | nil,
starting_after: t | Stripe.id() | nil
}
} | %{}
def list(params \\ %{}, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint)
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/core_resources/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule Stripe.Event do
| Stripe.Charge.t()
| Stripe.Coupon.t()
| Stripe.Customer.t()
| Stripe.File.t()
| Stripe.FileUpload.t()
| Stripe.Invoice.t()
| Stripe.Invoiceitem.t()
| Stripe.Order.t()
Expand Down
6 changes: 3 additions & 3 deletions lib/stripe/core_resources/payout.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ defmodule Stripe.Payout do
metadata: map,
source_type: String.t(),
statement_descriptor: String.t()
}
} | %{}
def create(params, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint)
Expand Down Expand Up @@ -115,7 +115,7 @@ defmodule Stripe.Payout do
optional(String.t()) => String.t(),
optional(atom) => String.t()
}
}
} | %{}
def update(id, params, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}")
Expand All @@ -141,7 +141,7 @@ defmodule Stripe.Payout do
limit: 1..100,
starting_after: t | Stripe.id(),
status: String.t()
}
} | %{}
def list(params \\ %{}, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint)
Expand Down
6 changes: 3 additions & 3 deletions lib/stripe/core_resources/refund.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ defmodule Stripe.Refund do
reason: String.t(),
refund_application_fee: boolean,
reverse_transfer: boolean
}
} | %{}
def create(params, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint)
Expand Down Expand Up @@ -110,7 +110,7 @@ defmodule Stripe.Refund do
@spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
when params: %{
metadata: Stripe.Types.metadata()
}
} | %{}
def update(id, params, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}")
Expand All @@ -135,7 +135,7 @@ defmodule Stripe.Refund do
ending_before: Stripe.id() | t,
limit: 1..100,
starting_after: Stripe.id() | t
}
} | %{}
def list(params \\ %{}, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint)
Expand Down
14 changes: 7 additions & 7 deletions lib/stripe/core_resources/token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ defmodule Stripe.Token do
id: Stripe.id(),
object: String.t(),
account_holder_name: String.t() | nil,
account_holder_type: Stripe.BankAccount.account_holder_type() | nil,
account_holder_type: String.t() | nil,
bank_name: String.t() | nil,
country: String.t(),
currency: String.t(),
fingerprint: String.t() | nil,
last4: String.t(),
routing_number: String.t() | nil,
status: Stripe.BankAccount.status()
status: String.t()
}

@type token_card :: %{
Expand All @@ -35,24 +35,24 @@ defmodule Stripe.Token do
address_city: String.t() | nil,
address_country: String.t() | nil,
address_line1: String.t() | nil,
address_line1_check: Stripe.Card.check_result() | nil,
address_line1_check: String.t() | nil,
address_line2: String.t() | nil,
address_state: String.t() | nil,
address_zip: String.t() | nil,
address_zip_check: Stripe.Card.check_result() | nil,
address_zip_check: String.t() | nil,
brand: String.t(),
country: String.t() | nil,
currency: String.t(),
cvc_check: Stripe.Card.check_result() | nil,
cvc_check: String.t() | nil,
dynamic_last4: String.t() | nil,
exp_month: integer,
exp_year: integer,
fingerprint: String.t() | nil,
funding: Stripe.Card.funding(),
funding: String.t(),
last4: String.t(),
metadata: Stripe.Types.metadata(),
name: String.t() | nil,
tokenization_method: Stripe.Card.tokenization_method() | nil
tokenization_method: String.t() | nil
}

@type t :: %__MODULE__{
Expand Down
10 changes: 5 additions & 5 deletions lib/stripe/payment_methods/source.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ defmodule Stripe.Source do
}

@type card :: %{
address_line1_check: Stripe.Card.check_result() | nil,
address_zip_check: Stripe.Card.check_result() | nil,
address_line1_check: String.t() | nil,
address_zip_check: String.t() | nil,
brand: String.t() | nil,
country: String.t() | nil,
cvc_check: Stripe.Card.check_result() | nil,
cvc_check: String.t() | nil,
dynamic_last4: String.t() | nil,
exp_month: integer | nil,
exp_year: integer | nil,
fingerprint: String.t(),
funding: Stripe.Card.funding() | nil,
funding: String.t() | nil,
last4: String.t() | nil,
skip_validation: boolean,
three_d_secure: String.t(),
tokenization_method: Stripe.Card.tokenization_method() | nil
tokenization_method: String.t() | nil
}

@type code_verification_flow :: %{
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/relay/order.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ defmodule Stripe.Order do
paid: Stripe.timestamp(),
returned: Stripe.timestamp()
},
updated: Stripe.timstamp(),
updated: Stripe.timestamp(),
upstream_id: String.t()
}

Expand Down
20 changes: 10 additions & 10 deletions lib/stripe/request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ defmodule Stripe.Request do
At a minimum, a request must have the endpoint and method specified to be
valid.
"""
alias Stripe.{API, Request, Converter}

@opaque t :: %__MODULE__{
opts: Keyword.t(),
endpoint: String.t() | (map -> String.t()),
method: Stripe.API.method(),
params: %{optional(atom) => any},
cast_to_id: MapSet.t(atom)
}
alias Stripe.{API, Converter, Request}

@type t :: %__MODULE__{
cast_to_id: MapSet.t(),
endpoint: String.t() | nil,
method: Stripe.API.method() | nil,
opts: Keyword.t() | nil,
params: map
}

@type error_code ::
:endpoint_fun_invalid_result
Expand Down Expand Up @@ -52,7 +52,7 @@ defmodule Stripe.Request do
before the request is made so the actual parameters can be specified after
the endpoint.
"""
@spec put_endpoint(t, String.t() | (map -> String.t())) :: t
@spec put_endpoint(t, String.t()) :: t
def put_endpoint(%Request{} = request, endpoint) do
%{request | endpoint: endpoint}
end
Expand Down
Loading