From 83175c62f3682b0d5a9bc51db22ccb9e92d7d76b Mon Sep 17 00:00:00 2001 From: Luis Ferreira Date: Wed, 20 Mar 2024 12:13:53 +0000 Subject: [PATCH 1/4] Adds trace id to Stripe.Payout Why: * Trace id a new field coming to Stripe This change addresses the need by: * Adding the optional trace_id field. It is currently not supported in all of the countries, but it'll say it's unsupported in that case. Also fixes some things to make it work with newer versions of Elixir and Erlang --- lib/stripe/core_resources/payout.ex | 6 ++++-- mix.exs | 3 +-- test/stripe/core_resources/payout_test.exs | 10 +++++----- test/support/stripe_mock.ex | 13 +++++++++++-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/stripe/core_resources/payout.ex b/lib/stripe/core_resources/payout.ex index bfc5b34f..603695cc 100644 --- a/lib/stripe/core_resources/payout.ex +++ b/lib/stripe/core_resources/payout.ex @@ -29,7 +29,8 @@ defmodule Stripe.Payout do source_type: String.t(), statement_descriptor: String.t() | nil, status: String.t(), - type: String.t() + type: String.t(), + trace_id: String.t() | nil } defstruct [ @@ -53,7 +54,8 @@ defmodule Stripe.Payout do :source_type, :statement_descriptor, :status, - :type + :type, + :trace_id ] @plural_endpoint "payouts" diff --git a/mix.exs b/mix.exs index 113fb0ed..2052d7c7 100644 --- a/mix.exs +++ b/mix.exs @@ -30,8 +30,7 @@ defmodule Stripe.Mixfile do # Configuration for the OTP application def application do [ - applications: apps(Mix.env()), - extra_applications: [:plug], + extra_applications: [:plug] ++ apps(Mix.env()), env: env(), mod: {Stripe, []} ] diff --git a/test/stripe/core_resources/payout_test.exs b/test/stripe/core_resources/payout_test.exs index a168913f..d5e02b9c 100644 --- a/test/stripe/core_resources/payout_test.exs +++ b/test/stripe/core_resources/payout_test.exs @@ -2,7 +2,7 @@ defmodule Stripe.PayoutTest do use Stripe.StripeCase, async: true describe "create/2" do - test "creates a card for a customer" do + test "creates a payout with the card source_type" do params = %{amount: 100, currency: "USD", source_type: "card"} assert {:ok, %Stripe.Payout{}} = Stripe.Payout.create(params) assert_stripe_requested(:post, "/v1/payouts") @@ -10,21 +10,21 @@ defmodule Stripe.PayoutTest do end describe "retrieve/2" do - test "retrieves a card" do - assert {:ok, %Stripe.Payout{}} = Stripe.Payout.retrieve("py_123") + test "retrieves a payout" do + assert {:ok, %Stripe.Payout{}} = Stripe.Payout.retrieve("py_123") |> dbg() assert_stripe_requested(:get, "/v1/payouts/py_123") end end describe "update/2" do - test "updates a card" do + test "updates a payout" do assert {:ok, %Stripe.Payout{}} = Stripe.Payout.update("py_123", %{metadata: %{foo: "bar"}}) assert_stripe_requested(:post, "/v1/payouts/py_123") end end describe "list/2" do - test "lists all cards" do + test "lists all payouts" do assert {:ok, %Stripe.List{data: payouts}} = Stripe.Payout.list() assert_stripe_requested(:get, "/v1/payouts") assert is_list(payouts) diff --git a/test/support/stripe_mock.ex b/test/support/stripe_mock.ex index 315e7b18..24b4b4f0 100644 --- a/test/support/stripe_mock.ex +++ b/test/support/stripe_mock.ex @@ -53,14 +53,23 @@ defmodule Stripe.StripeMock do @impl true def handle_info( - %{os_pid: os_pid, opts: opts, restarting: {true, from}} = state, - {:DOWN, os_pid, :process, _ex_pid, _reason} + {:DOWN, os_pid, :process, _ex_pid, _reason}, + %{os_pid: os_pid, opts: opts, restarting: {true, from}} = state ) do {:ok, manager_pid, os_pid} = start_stripe_mock(opts) GenServer.reply(from, :ok) {:noreply, %{state | manager_pid: manager_pid, os_pid: os_pid, restarting: false}} end + @impl true + def handle_info( + {:DOWN, os_pid, :process, _ex_pid, _reason}, + %{os_pid: os_pid, opts: opts, restarting: false} = state + ) do + {:ok, manager_pid, os_pid} = start_stripe_mock(opts) + {:noreply, %{state | manager_pid: manager_pid, os_pid: os_pid, restarting: false}} + end + defp start_stripe_mock(opts) do executable = opts[:stripe_mock_path] || System.find_executable("stripe-mock") From 98a02aaeed8f4a7077b22808c01940e2847696a4 Mon Sep 17 00:00:00 2001 From: Luis Ferreira Date: Wed, 20 Mar 2024 13:34:40 +0000 Subject: [PATCH 2/4] Update typespec --- lib/stripe/core_resources/payout.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stripe/core_resources/payout.ex b/lib/stripe/core_resources/payout.ex index 603695cc..001a63c5 100644 --- a/lib/stripe/core_resources/payout.ex +++ b/lib/stripe/core_resources/payout.ex @@ -30,7 +30,7 @@ defmodule Stripe.Payout do statement_descriptor: String.t() | nil, status: String.t(), type: String.t(), - trace_id: String.t() | nil + trace_id: map() | nil } defstruct [ From a963673df7782f5ea03be353a598a4087c111adf Mon Sep 17 00:00:00 2001 From: Luis Ferreira Date: Wed, 20 Mar 2024 13:39:49 +0000 Subject: [PATCH 3/4] Do not change configs in this PR --- mix.exs | 3 ++- test/support/stripe_mock.ex | 13 ++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/mix.exs b/mix.exs index 2052d7c7..113fb0ed 100644 --- a/mix.exs +++ b/mix.exs @@ -30,7 +30,8 @@ defmodule Stripe.Mixfile do # Configuration for the OTP application def application do [ - extra_applications: [:plug] ++ apps(Mix.env()), + applications: apps(Mix.env()), + extra_applications: [:plug], env: env(), mod: {Stripe, []} ] diff --git a/test/support/stripe_mock.ex b/test/support/stripe_mock.ex index 24b4b4f0..315e7b18 100644 --- a/test/support/stripe_mock.ex +++ b/test/support/stripe_mock.ex @@ -53,23 +53,14 @@ defmodule Stripe.StripeMock do @impl true def handle_info( - {:DOWN, os_pid, :process, _ex_pid, _reason}, - %{os_pid: os_pid, opts: opts, restarting: {true, from}} = state + %{os_pid: os_pid, opts: opts, restarting: {true, from}} = state, + {:DOWN, os_pid, :process, _ex_pid, _reason} ) do {:ok, manager_pid, os_pid} = start_stripe_mock(opts) GenServer.reply(from, :ok) {:noreply, %{state | manager_pid: manager_pid, os_pid: os_pid, restarting: false}} end - @impl true - def handle_info( - {:DOWN, os_pid, :process, _ex_pid, _reason}, - %{os_pid: os_pid, opts: opts, restarting: false} = state - ) do - {:ok, manager_pid, os_pid} = start_stripe_mock(opts) - {:noreply, %{state | manager_pid: manager_pid, os_pid: os_pid, restarting: false}} - end - defp start_stripe_mock(opts) do executable = opts[:stripe_mock_path] || System.find_executable("stripe-mock") From f1bc3c70f0a3e9b064aa0f45408a59f673303177 Mon Sep 17 00:00:00 2001 From: Luis Ferreira Date: Wed, 20 Mar 2024 15:17:26 +0000 Subject: [PATCH 4/4] Remove dbg call --- test/stripe/core_resources/payout_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/stripe/core_resources/payout_test.exs b/test/stripe/core_resources/payout_test.exs index d5e02b9c..1ea72f54 100644 --- a/test/stripe/core_resources/payout_test.exs +++ b/test/stripe/core_resources/payout_test.exs @@ -11,7 +11,7 @@ defmodule Stripe.PayoutTest do describe "retrieve/2" do test "retrieves a payout" do - assert {:ok, %Stripe.Payout{}} = Stripe.Payout.retrieve("py_123") |> dbg() + assert {:ok, %Stripe.Payout{}} = Stripe.Payout.retrieve("py_123") assert_stripe_requested(:get, "/v1/payouts/py_123") end end