From d774b2b663ae7563817ccc65c36c4d73e2520442 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Wed, 26 Jun 2024 03:54:24 -0400 Subject: [PATCH] fix: operation name --- Makefile | 11 +++ lib/generated/account.ex | 33 ++++---- lib/generated/payment_intent.ex | 129 +++++++++++++++++++------------- lib/generated/setup_intent.ex | 8 +- lib/generated/token.ex | 15 ++-- lib/mix/tasks/generate.ex | 2 +- lib/openapi/phases/compile.ex | 40 +++++++++- test/stripe/util_test.exs | 9 ++- 8 files changed, 162 insertions(+), 85 deletions(-) diff --git a/Makefile b/Makefile index d1d1711d..84e89db8 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,14 @@ +CURRENT_VERSION := $(shell cat .latest-tag-stripe-openapi-sdk) + +download-openapi-current: + @echo "Tag: $(CURRENT_VERSION)" + @echo "Downloading https://raw.githubusercontent.com/stripe/openapi/$(CURRENT_VERSION)/openapi/spec3.sdk.json to ./priv/openapi/spec3.sdk.json" + @curl -o ./priv/openapi/spec3.sdk.json https://raw.githubusercontent.com/stripe/openapi/$(CURRENT_VERSION)/openapi/spec3.sdk.json + +generate: + mix stripe.generate + mix format + gen-changelog: npx auto-changelog --unreleased diff --git a/lib/generated/account.ex b/lib/generated/account.ex index 7fc5bbda..166ec48a 100644 --- a/lib/generated/account.ex +++ b/lib/generated/account.ex @@ -66,7 +66,7 @@ defmodule Stripe.Account do ) ( - @typedoc "The company's primary address." + @typedoc "The individual's primary address." @type address :: %{ optional(:city) => binary, optional(:country) => binary, @@ -119,8 +119,8 @@ defmodule Stripe.Account do ) ( - @typedoc "Settings specific to Bacs Direct Debit payments." - @type bacs_debit_payments :: %{optional(:display_name) => binary} + @typedoc "The bacs_debit_payments capability." + @type bacs_debit_payments :: %{optional(:requested) => boolean} ) ( @@ -217,18 +217,13 @@ defmodule Stripe.Account do ) ( - @typedoc "Settings specific to the account's use of the Card Issuing product." - @type card_issuing :: %{optional(:tos_acceptance) => tos_acceptance} + @typedoc "The card_issuing capability." + @type card_issuing :: %{optional(:requested) => boolean} ) ( - @typedoc "Settings specific to card charging on the account." - @type card_payments :: %{ - optional(:decline_on) => decline_on, - optional(:statement_descriptor_prefix) => binary, - optional(:statement_descriptor_prefix_kana) => binary | binary, - optional(:statement_descriptor_prefix_kanji) => binary | binary - } + @typedoc "The card_payments capability." + @type card_payments :: %{optional(:requested) => boolean} ) ( @@ -338,7 +333,7 @@ defmodule Stripe.Account do ) ( - @typedoc "An identifying document, either a passport or local ID card." + @typedoc "A document verifying the business." @type document :: %{optional(:back) => binary, optional(:front) => binary} ) @@ -583,11 +578,12 @@ defmodule Stripe.Account do ) ( - @typedoc "Details on the account's acceptance of the Stripe Treasury Services Agreement." + @typedoc "Details on the account's acceptance of the [Stripe Services Agreement](https://stripe.com/docs/connect/updating-accounts#tos-acceptance)." @type tos_acceptance :: %{ optional(:date) => integer, optional(:ip) => binary, - optional(:user_agent) => binary | binary + optional(:service_agreement) => binary, + optional(:user_agent) => binary } ) @@ -607,8 +603,11 @@ defmodule Stripe.Account do ) ( - @typedoc "Information on the verification state of the company." - @type verification :: %{optional(:document) => document} + @typedoc "The individual's verification document information." + @type verification :: %{ + optional(:additional_document) => additional_document, + optional(:document) => document + } ) ( diff --git a/lib/generated/payment_intent.ex b/lib/generated/payment_intent.ex index fb4546dd..ad186ab2 100644 --- a/lib/generated/payment_intent.ex +++ b/lib/generated/payment_intent.ex @@ -92,16 +92,16 @@ defmodule Stripe.PaymentIntent do ) ( - @typedoc "If this is an `acss_debit` PaymentMethod, this hash contains details about the ACSS Debit payment method." + @typedoc nil @type acss_debit :: %{ - optional(:account_number) => binary, - optional(:institution_number) => binary, - optional(:transit_number) => binary + optional(:mandate_options) => mandate_options, + optional(:setup_future_usage) => :none | :off_session | :on_session, + optional(:verification_method) => :automatic | :instant | :microdeposits } ) ( - @typedoc "Shipping address." + @typedoc nil @type address :: %{ optional(:city) => binary, optional(:country) => binary, @@ -149,8 +149,8 @@ defmodule Stripe.PaymentIntent do ) ( - @typedoc nil - @type bacs_debit :: %{optional(:setup_future_usage) => :none | :off_session | :on_session} + @typedoc "If this is a `bacs_debit` PaymentMethod, this hash contains details about the Bacs Direct Debit bank account." + @type bacs_debit :: %{optional(:account_number) => binary, optional(:sort_code) => binary} ) ( @@ -192,11 +192,8 @@ defmodule Stripe.PaymentIntent do ) ( - @typedoc nil - @type boleto :: %{ - optional(:expires_after_days) => integer, - optional(:setup_future_usage) => :none | :off_session | :on_session - } + @typedoc "If this is a `boleto` PaymentMethod, this hash contains details about the Boleto payment method." + @type boleto :: %{optional(:tax_id) => binary} ) ( @@ -295,8 +292,38 @@ defmodule Stripe.PaymentIntent do ) ( - @typedoc nil - @type eps :: %{optional(:setup_future_usage) => :none} + @typedoc "If this is an `eps` PaymentMethod, this hash contains details about the EPS payment method." + @type eps :: %{ + optional(:bank) => + :arzte_und_apotheker_bank + | :austrian_anadi_bank_ag + | :bank_austria + | :bankhaus_carl_spangler + | :bankhaus_schelhammer_und_schattera_ag + | :bawag_psk_ag + | :bks_bank_ag + | :brull_kallmus_bank_ag + | :btv_vier_lander_bank + | :capital_bank_grawe_gruppe_ag + | :deutsche_bank_ag + | :dolomitenbank + | :easybank_ag + | :erste_bank_und_sparkassen + | :hypo_alpeadriabank_international_ag + | :hypo_bank_burgenland_aktiengesellschaft + | :hypo_noe_lb_fur_niederosterreich_u_wien + | :hypo_oberosterreich_salzburg_steiermark + | :hypo_tirol_bank_ag + | :hypo_vorarlberg_bank_ag + | :marchfelder_bank + | :oberbank_ag + | :raiffeisen_bankengruppe_osterreich + | :schoellerbank_ag + | :sparda_bank_wien + | :volksbank_gruppe + | :volkskreditbank_ag + | :vr_bank_braunau + } ) ( @@ -330,25 +357,8 @@ defmodule Stripe.PaymentIntent do ) ( - @typedoc "If this is an `ideal` PaymentMethod, this hash contains details about the iDEAL payment method." - @type ideal :: %{ - optional(:bank) => - :abn_amro - | :asn_bank - | :bunq - | :handelsbanken - | :ing - | :knab - | :moneyou - | :n26 - | :rabobank - | :regiobank - | :revolut - | :sns_bank - | :triodos_bank - | :van_lanschot - | :yoursafe - } + @typedoc nil + @type ideal :: %{optional(:setup_future_usage) => :none | :off_session} ) ( @@ -435,18 +445,8 @@ defmodule Stripe.PaymentIntent do ) ( - @typedoc "Configuration options for setting up an eMandate for cards issued in India." - @type mandate_options :: %{ - optional(:amount) => integer, - optional(:amount_type) => :fixed | :maximum, - optional(:description) => binary, - optional(:end_date) => integer, - optional(:interval) => :day | :month | :sporadic | :week | :year, - optional(:interval_count) => integer, - optional(:reference) => binary, - optional(:start_date) => integer, - optional(:supported_types) => list(:india) - } + @typedoc "Additional fields for Mandate creation" + @type mandate_options :: %{optional(:collection_method) => :paper} ) ( @@ -473,10 +473,34 @@ defmodule Stripe.PaymentIntent do ) ( - @typedoc nil + @typedoc "If this is a `p24` PaymentMethod, this hash contains details about the P24 payment method." @type p24 :: %{ - optional(:setup_future_usage) => :none, - optional(:tos_shown_and_accepted) => boolean + optional(:bank) => + :alior_bank + | :bank_millennium + | :bank_nowy_bfg_sa + | :bank_pekao_sa + | :banki_spbdzielcze + | :blik + | :bnp_paribas + | :boz + | :citi_handlowy + | :credit_agricole + | :envelobank + | :etransfer_pocztowy24 + | :getin_bank + | :ideabank + | :ing + | :inteligo + | :mbank_mtransfer + | :nest_przelew + | :noble_pay + | :pbac_z_ipko + | :plus_bank + | :santander_przelew24 + | :tmobile_usbugi_bankowe + | :toyota_bank + | :volkswagen_bank } ) @@ -654,7 +678,7 @@ defmodule Stripe.PaymentIntent do ) ( - @typedoc "Options to configure Radar. See [Radar Session](https://stripe.com/docs/radar/radar-session) for more information." + @typedoc "Options to configure Radar. Learn more about [Radar Sessions](https://stripe.com/docs/radar/radar-session)." @type radar_options :: %{optional(:session) => binary} ) @@ -683,11 +707,8 @@ defmodule Stripe.PaymentIntent do ) ( - @typedoc nil - @type sofort :: %{ - optional(:preferred_language) => :de | :en | :es | :fr | :it | :nl | :pl, - optional(:setup_future_usage) => :none | :off_session - } + @typedoc "If this is a `sofort` PaymentMethod, this hash contains details about the SOFORT payment method." + @type sofort :: %{optional(:country) => :AT | :BE | :DE | :ES | :IT | :NL} ) ( diff --git a/lib/generated/setup_intent.ex b/lib/generated/setup_intent.ex index 9309fc49..c8cf6526 100644 --- a/lib/generated/setup_intent.ex +++ b/lib/generated/setup_intent.ex @@ -62,11 +62,11 @@ defmodule Stripe.SetupIntent do ) ( - @typedoc "If this is an `acss_debit` PaymentMethod, this hash contains details about the ACSS Debit payment method." + @typedoc "If this is a `acss_debit` SetupIntent, this sub-hash contains details about the ACSS Debit payment method options." @type acss_debit :: %{ - optional(:account_number) => binary, - optional(:institution_number) => binary, - optional(:transit_number) => binary + optional(:currency) => :cad | :usd, + optional(:mandate_options) => mandate_options, + optional(:verification_method) => :automatic | :instant | :microdeposits } ) diff --git a/lib/generated/token.ex b/lib/generated/token.ex index 28633b12..9345e307 100644 --- a/lib/generated/token.ex +++ b/lib/generated/token.ex @@ -39,7 +39,7 @@ defmodule Stripe.Token do ) ( - @typedoc "The company's primary address." + @typedoc "The person's address." @type address :: %{ optional(:city) => binary, optional(:country) => binary, @@ -64,7 +64,7 @@ defmodule Stripe.Token do ) ( - @typedoc "The Kanji variation of the company's primary address (Japan only)." + @typedoc "The Kanji variation of the person's address (Japan only)." @type address_kanji :: %{ optional(:city) => binary, optional(:country) => binary, @@ -175,7 +175,7 @@ defmodule Stripe.Token do ) ( - @typedoc "An identifying document, either a passport or local ID card." + @typedoc "A document verifying the business." @type document :: %{optional(:back) => binary, optional(:front) => binary} ) @@ -268,7 +268,7 @@ defmodule Stripe.Token do ) ( - @typedoc "The individual's registered address." + @typedoc "The person's registered address." @type registered_address :: %{ optional(:city) => binary, optional(:country) => binary, @@ -293,8 +293,11 @@ defmodule Stripe.Token do ) ( - @typedoc "Information on the verification state of the company." - @type verification :: %{optional(:document) => document} + @typedoc "The person's verification status." + @type verification :: %{ + optional(:additional_document) => additional_document, + optional(:document) => document + } ) ( diff --git a/lib/mix/tasks/generate.ex b/lib/mix/tasks/generate.ex index 0041eafd..35db6ad0 100644 --- a/lib/mix/tasks/generate.ex +++ b/lib/mix/tasks/generate.ex @@ -1,5 +1,5 @@ defmodule Mix.Tasks.Stripe.Generate do - @moduledoc "The hello mix task: `mix help hello`" + @moduledoc "The hello mix task: `mix stripe.generate`" use Mix.Task def run(_) do diff --git a/lib/openapi/phases/compile.ex b/lib/openapi/phases/compile.ex index 54b19953..089bf752 100644 --- a/lib/openapi/phases/compile.ex +++ b/lib/openapi/phases/compile.ex @@ -48,7 +48,11 @@ defmodule Stripe.OpenApi.Phases.Compile do end end) - function_name = String.to_atom(operation["method_name"]) + function_name = + operation_definition + |> to_func_name(operation) + |> Macro.underscore() + |> String.to_atom() success_response_spec = return_spec(operation_definition.success_response) @@ -509,4 +513,38 @@ defmodule Stripe.OpenApi.Phases.Compile do defp lookup_operation(path, operations) do Map.get(operations, path) end + + require Logger + + # NOTE: This is a mapping of operation ids to function names. This is necessary + # to avoid breaking changes. In the future, we should remove this mapping and + # use the operation id directly as the function name. + @operation_identity_mapping %{} + + defp to_func_name(operation_definition, operation) do + case Map.get(@operation_identity_mapping, operation_definition.id) do + nil -> + # Logger.error(""" + # Unregistered Operation + # + # - Stripe Extension: #{inspect(operation)} + # + # + # - Operation: #{inspect(operation_definition)} + # + # - Suggested Mapping: "#{operation_definition.id}" => "#{operation["method_name"]}", + # """) + + content = ~s("#{operation_definition.id}" => "#{operation["method_name"]}",\n) + + File.rm("./mapping") + File.touch("./mapping") + File.write!("./mapping", content, [:append]) + + operation["method_name"] + + name -> + name + end + end end diff --git a/test/stripe/util_test.exs b/test/stripe/util_test.exs index 80504f9d..b2ac3c05 100644 --- a/test/stripe/util_test.exs +++ b/test/stripe/util_test.exs @@ -37,8 +37,13 @@ defmodule Stripe.UtilTest do assert object_name_to_module("billing_portal.session") == Stripe.BillingPortal.Session assert object_name_to_module("checkout.session") == Stripe.Checkout.Session - assert object_name_to_module("identity.verification_report") == Stripe.Identity.VerificationReport - assert object_name_to_module("identity.verification_session") == Stripe.Identity.VerificationSession + + assert object_name_to_module("identity.verification_report") == + Stripe.Identity.VerificationReport + + assert object_name_to_module("identity.verification_session") == + Stripe.Identity.VerificationSession + assert object_name_to_module("issuing.authorization") == Stripe.Issuing.Authorization assert object_name_to_module("issuing.card") == Stripe.Issuing.Card assert object_name_to_module("issuing.cardholder") == Stripe.Issuing.Cardholder