From 67e89ecd06a7391c48dad234d63a0059aa47dc64 Mon Sep 17 00:00:00 2001 From: Aleksandr Lossenko Date: Tue, 6 Aug 2024 10:50:03 +0200 Subject: [PATCH 1/4] chore: fix Elixir 1.17 warnings --- lib/stripe/converter.ex | 2 +- test/support/stripe_mock_test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stripe/converter.ex b/lib/stripe/converter.ex index e106ce33f..33f2dcacd 100644 --- a/lib/stripe/converter.ex +++ b/lib/stripe/converter.ex @@ -136,7 +136,7 @@ defmodule Stripe.Converter do @spec convert_stripe_object(%{String.t() => any}) :: struct defp convert_stripe_object(%{"object" => object_name} = value) do module = Stripe.Util.object_name_to_module(object_name) - struct_keys = Map.keys(module.__struct__) |> List.delete(:__struct__) + struct_keys = Map.keys(module.__struct__()) |> List.delete(:__struct__) check_for_extra_keys(struct_keys, value) processed_map = diff --git a/test/support/stripe_mock_test.exs b/test/support/stripe_mock_test.exs index 0ead7b172..4076f3122 100644 --- a/test/support/stripe_mock_test.exs +++ b/test/support/stripe_mock_test.exs @@ -10,7 +10,7 @@ defmodule Stripe.StripeMockTest do defp assert_port_open(port) do delay() - assert {:ok, socket} = :gen_tcp.connect('localhost', port, []) + assert {:ok, socket} = :gen_tcp.connect(~c'localhost', port, []) :gen_tcp.close(socket) end From 926a6226b7c5f3bf12f91b641110371d1021d78a Mon Sep 17 00:00:00 2001 From: Aleksandr Lossenko Date: Wed, 28 Aug 2024 17:44:06 +0200 Subject: [PATCH 2/4] try to fix CI --- .github/workflows/ci.yml | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78259b72b..bbbd52b60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,8 +5,8 @@ on: types: [opened, reopened, synchronize] push: branches: - - 'master' - - 'remote' + - "master" + - "remote" jobs: test: @@ -18,39 +18,39 @@ jobs: runs-on: ubuntu-latest name: Test (OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}) strategy: - matrix: - elixir: ['1.12'] - # All of the above can use this version. For details see: https://hexdocs.pm/elixir/compatibility-and-deprecations.html#compatibility-between-elixir-and-erlang-otp - otp: [24] + matrix: + elixir: ["1.12"] + # All of the above can use this version. For details see: https://hexdocs.pm/elixir/compatibility-and-deprecations.html#compatibility-between-elixir-and-erlang-otp + otp: [24] services: - stripe-mock: - image: stripe/stripe-mock:v0.125.0 - ports: - - 12111:12111 - - 12112:12112 + stripe-mock: + image: stripe/stripe-mock:v0.125.0 + ports: + - 12111:12111 + - 12112:12112 steps: - - name: Clone code - uses: actions/checkout@v2 - - name: Setup Elixir and Erlang - uses: erlef/setup-beam@v1 - with: + - name: Clone code + uses: actions/checkout@v2 + - name: Setup Elixir and Erlang + uses: erlef/setup-beam@v1 + with: otp-version: ${{ matrix.otp }} elixir-version: ${{ matrix.elixir }} - - name: Mix Dependencies - run: mix deps.get - - name: Test - run: mix test + - name: Mix Dependencies + run: mix deps.get + - name: Test + run: mix test lint: runs-on: ubuntu-latest name: Linting strategy: matrix: - elixir: ['1.12', '1.11', '1.10'] + elixir: ["1.17", "1.16"] # All of the above can use this version. For details see: https://hexdocs.pm/elixir/compatibility-and-deprecations.html#compatibility-between-elixir-and-erlang-otp - otp: [24, 23, 22] + otp: [26, 25] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: erlef/setup-beam@v1 with: otp-version: ${{matrix.otp}} @@ -62,7 +62,7 @@ jobs: path: ~/.mix key: cache-${{ runner.os }}-${{ env.cache-name }}-${{ matrix.otp }}-${{ matrix.elixir }} restore-keys: | - cache-${{ runner.os }}-${{ env.cache-name }}- + cache-${{ runner.os }}-${{ env.cache-name }}- - uses: actions/cache@v1 env: cache-name: build @@ -70,7 +70,7 @@ jobs: path: _build key: cache-${{ runner.os }}-${{ env.cache-name }}-${{ matrix.otp }}-${{ matrix.elixir }} restore-keys: | - cache-${{ runner.os }}-${{ env.cache-name }}- + cache-${{ runner.os }}-${{ env.cache-name }}- - run: mix deps.get - run: mix compile --warnings-as-errors - run: mix dialyzer --halt-exit-status From d316520b7fea2bec691c53892f0747523ae34324 Mon Sep 17 00:00:00 2001 From: Aleksandr Lossenko Date: Wed, 28 Aug 2024 17:46:05 +0200 Subject: [PATCH 3/4] missed a version --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bbbd52b60..b7efe196f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,9 +19,9 @@ jobs: name: Test (OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}) strategy: matrix: - elixir: ["1.12"] + elixir: ["1.17"] # All of the above can use this version. For details see: https://hexdocs.pm/elixir/compatibility-and-deprecations.html#compatibility-between-elixir-and-erlang-otp - otp: [24] + otp: [26] services: stripe-mock: image: stripe/stripe-mock:v0.125.0 From d04af2890cae0bb9364de583ad856287f5afb370 Mon Sep 17 00:00:00 2001 From: Aleksandr Lossenko Date: Wed, 28 Aug 2024 18:22:46 +0200 Subject: [PATCH 4/4] try to fix more warnings --- .gitignore | 4 ++++ .tool-versions | 4 ++-- lib/stripe/api.ex | 16 ++++++++++------ lib/stripe/core_resources/charge.ex | 2 +- lib/stripe/core_resources/customer.ex | 3 ++- lib/stripe/core_resources/event.ex | 4 ---- lib/stripe/core_resources/payment_intent.ex | 3 ++- lib/stripe/error.ex | 4 +--- lib/stripe/payment_methods/card.ex | 2 +- lib/stripe/relay/order_item.ex | 2 +- lib/stripe/subscriptions/credit_note.ex | 2 +- .../subscriptions/credit_note_line_item.ex | 2 +- lib/stripe/subscriptions/invoice.ex | 5 ++++- 13 files changed, 30 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 03f88067f..bc2127264 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,10 @@ # The directory Mix downloads your dependencies sources to. /deps/ +# Dialyzer PLT files +/priv/plts/*.plt +/priv/plts/*.plt.hash + # Where third-party dependencies like ExDoc output generated docs. /doc/ diff --git a/.tool-versions b/.tool-versions index 16f4970ac..9bd8fc1ca 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 26.1.2 -elixir 1.16.0-otp-26 +erlang 26.2.5.1 +elixir 1.17.2-otp-26 diff --git a/lib/stripe/api.ex b/lib/stripe/api.ex index 0ee346a6c..42555a82e 100644 --- a/lib/stripe/api.ex +++ b/lib/stripe/api.ex @@ -382,9 +382,10 @@ defmodule Stripe.API do defp do_perform_request_and_retry(method, url, headers, body, opts, {:attempts, attempts}) do {idempotency_key, attempt} = log_request(method, url, headers, attempts) - response = track_request_time(method, url, idempotency_key, attempt, - fn -> http_module().request(method, url, headers, body, opts) end - ) + response = + track_request_time(method, url, idempotency_key, attempt, fn -> + http_module().request(method, url, headers, body, opts) + end) do_perform_request_and_retry( method, @@ -404,7 +405,8 @@ defmodule Stripe.API do attempt: attempt } - :telemetry.span([:stripity_stripe, :request], + :telemetry.span( + [:stripity_stripe, :request], start_metadata, fn -> result = request_fn.() @@ -424,9 +426,11 @@ defmodule Stripe.API do # attempts are 0-index based attempt = "attempt=#{attempts + 1}" - Logger.info("[stripity_stripe] Performing #{http_method_url} #{attempt}#{idempotency_key_msg}") + Logger.info( + "[stripity_stripe] Performing #{http_method_url} #{attempt}#{idempotency_key_msg}" + ) - {idempotency_key, attempts+1} + {idempotency_key, attempts + 1} end defp get_idempotency_key_from_headers(method, _headers) when method in [:get, :headers], do: nil diff --git a/lib/stripe/core_resources/charge.ex b/lib/stripe/core_resources/charge.ex index 4fe0883fd..51b342700 100644 --- a/lib/stripe/core_resources/charge.ex +++ b/lib/stripe/core_resources/charge.ex @@ -89,7 +89,7 @@ defmodule Stripe.Charge do livemode: boolean, metadata: Stripe.Types.metadata(), on_behalf_of: Stripe.id() | Stripe.Account.t() | nil, - order: Stripe.id() | Stripe.Order.t() | nil, + order: Stripe.id() | nil, outcome: charge_outcome | nil, paid: boolean, payment_intent: Stripe.id() | Stripe.PaymentIntent.t() | nil, diff --git a/lib/stripe/core_resources/customer.ex b/lib/stripe/core_resources/customer.ex index 2c09a768a..9d090d45a 100644 --- a/lib/stripe/core_resources/customer.ex +++ b/lib/stripe/core_resources/customer.ex @@ -211,7 +211,8 @@ defmodule Stripe.Customer do {:ok, cash_Balance} = Stripe.Customer.update_cash_balance("cus_123") """ - @spec update_cash_balance(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + @spec update_cash_balance(Stripe.id() | t, params, Stripe.options()) :: + {:ok, t} | {:error, Stripe.Error.t()} when params: %{ optional(:settings) => Stripe.Types.metadata() diff --git a/lib/stripe/core_resources/event.ex b/lib/stripe/core_resources/event.ex index a27c58197..9933d5210 100644 --- a/lib/stripe/core_resources/event.ex +++ b/lib/stripe/core_resources/event.ex @@ -27,16 +27,12 @@ defmodule Stripe.Event do | Stripe.FileUpload.t() | Stripe.Invoice.t() | Stripe.Invoiceitem.t() - | Stripe.Order.t() - | Stripe.OrderReturn.t() | Stripe.Payout.t() | Stripe.Plan.t() | Stripe.Relay.Product.t() | Stripe.Price.t() | Stripe.Product.t() - | Stripe.Recipient.t() | Stripe.Review.t() - | Stripe.Sku.t() | Stripe.Source.t() | Stripe.Transfer.t() | map diff --git a/lib/stripe/core_resources/payment_intent.ex b/lib/stripe/core_resources/payment_intent.ex index 3e0fc248d..40b477c29 100644 --- a/lib/stripe/core_resources/payment_intent.ex +++ b/lib/stripe/core_resources/payment_intent.ex @@ -318,7 +318,8 @@ defmodule Stripe.PaymentIntent do See the [Stripe docs](https://stripe.com/docs/api/payment_intents/apply_customer_balance). """ - @spec apply_customer_balance(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} + @spec apply_customer_balance(Stripe.id() | t, params, Stripe.options()) :: + {:ok, t} | {:error, Stripe.Error.t()} when params: %{ optional(:amount) => non_neg_integer, optional(:currency) => String.t() diff --git a/lib/stripe/error.ex b/lib/stripe/error.ex index c63331b97..9fc6c1a3b 100644 --- a/lib/stripe/error.ex +++ b/lib/stripe/error.ex @@ -123,9 +123,7 @@ defmodule Stripe.Error do source: :network, code: :network_error, message: - "An error occurred while making the network request. The HTTP client returned the following reason: #{ - inspect(reason) - }", + "An error occurred while making the network request. The HTTP client returned the following reason: #{inspect(reason)}", extra: %{ hackney_reason: reason } diff --git a/lib/stripe/payment_methods/card.ex b/lib/stripe/payment_methods/card.ex index 94be37c06..b8b8294f2 100644 --- a/lib/stripe/payment_methods/card.ex +++ b/lib/stripe/payment_methods/card.ex @@ -49,7 +49,7 @@ defmodule Stripe.Card do last4: String.t(), metadata: Stripe.Types.metadata(), name: String.t() | nil, - recipient: Stripe.id() | Stripe.Recipient.t() | nil, + recipient: Stripe.id() | nil, tokenization_method: String.t() | nil } diff --git a/lib/stripe/relay/order_item.ex b/lib/stripe/relay/order_item.ex index 13961f6b4..31ceafd94 100644 --- a/lib/stripe/relay/order_item.ex +++ b/lib/stripe/relay/order_item.ex @@ -12,7 +12,7 @@ defmodule Stripe.OrderItem do amount: pos_integer, currency: String.t(), description: String.t(), - parent: nil | Stripe.id() | Stripe.Sku.t(), + parent: nil | Stripe.id(), quantity: nil | pos_integer, type: String.t() } diff --git a/lib/stripe/subscriptions/credit_note.ex b/lib/stripe/subscriptions/credit_note.ex index b37098136..f7a89a8e8 100644 --- a/lib/stripe/subscriptions/credit_note.ex +++ b/lib/stripe/subscriptions/credit_note.ex @@ -25,7 +25,7 @@ defmodule Stripe.CreditNote do @type discount :: %{ amount: integer, - discount: String.t(), + discount: String.t() } @type t :: %__MODULE__{ diff --git a/lib/stripe/subscriptions/credit_note_line_item.ex b/lib/stripe/subscriptions/credit_note_line_item.ex index 5eb78871a..6fdf3c6fe 100644 --- a/lib/stripe/subscriptions/credit_note_line_item.ex +++ b/lib/stripe/subscriptions/credit_note_line_item.ex @@ -18,7 +18,7 @@ defmodule Stripe.CreditNoteLineItem do @type discount :: %{ amount: integer, - discount: String.t(), + discount: String.t() } @type t :: %__MODULE__{ diff --git a/lib/stripe/subscriptions/invoice.ex b/lib/stripe/subscriptions/invoice.ex index 9ccc941f6..10843a7f6 100644 --- a/lib/stripe/subscriptions/invoice.ex +++ b/lib/stripe/subscriptions/invoice.ex @@ -297,7 +297,10 @@ defmodule Stripe.Invoice do @spec upcoming(map, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()} def upcoming(params, opts \\ []) def upcoming(params = %{customer: _customer}, opts), do: get_upcoming(params, opts) - def upcoming(params = %{customer_details: _customer_details}, opts), do: get_upcoming(params, opts) + + def upcoming(params = %{customer_details: _customer_details}, opts), + do: get_upcoming(params, opts) + def upcoming(params = %{subscription: _subscription}, opts), do: get_upcoming(params, opts) defp get_upcoming(params, opts) do