diff --git a/lib/algora/admin/admin.ex b/lib/algora/admin/admin.ex index 7d10dd8a0..28601b608 100644 --- a/lib/algora/admin/admin.ex +++ b/lib/algora/admin/admin.ex @@ -78,7 +78,7 @@ defmodule Algora.Admin do with account_id when is_binary(account_id) <- Algora.config([:stripe, :test_account_id]), {:ok, user} <- Repo.fetch_by(User, handle: user_handle), {:ok, acct} <- Payments.create_account(user, "US"), - {:ok, stripe_acct} <- Stripe.Account.retrieve(account_id, []) do + {:ok, stripe_acct} <- Algora.PSP.Account.retrieve(account_id) do Payments.update_account(acct, stripe_acct) end end diff --git a/lib/algora/bounties/bounties.ex b/lib/algora/bounties/bounties.ex index 9cae8f5af..a141d343d 100644 --- a/lib/algora/bounties/bounties.ex +++ b/lib/algora/bounties/bounties.ex @@ -16,6 +16,7 @@ defmodule Algora.Bounties do alias Algora.Organizations.Member alias Algora.Payments alias Algora.Payments.Transaction + alias Algora.PSP alias Algora.Repo alias Algora.Util alias Algora.Workspace @@ -649,7 +650,7 @@ defmodule Algora.Bounties do recipient: User.t() ] ) :: - {:ok, Stripe.Invoice.t()} | {:error, atom()} + {:ok, PSP.invoice()} | {:error, atom()} def create_invoice(%{owner: owner, amount: amount}, opts \\ []) do tx_group_id = Nanoid.generate() @@ -685,7 +686,7 @@ defmodule Algora.Bounties do }), {:ok, customer} <- Payments.fetch_or_create_customer(owner), {:ok, invoice} <- - Algora.Stripe.Invoice.create(%{ + PSP.Invoice.create(%{ auto_advance: false, customer: customer.provider_id }), @@ -693,7 +694,7 @@ defmodule Algora.Bounties do line_items |> Enum.map(&LineItem.to_invoice_item(&1, invoice, customer)) |> Enum.reduce_while({:ok, []}, fn params, {:ok, acc} -> - case Algora.Stripe.Invoiceitem.create(params) do + case PSP.Invoiceitem.create(params) do {:ok, item} -> {:cont, {:ok, [item | acc]}} {:error, error} -> {:halt, {:error, error}} end diff --git a/lib/algora/contracts/contracts.ex b/lib/algora/contracts/contracts.ex index 9074ea5ee..cbf1aa6a2 100644 --- a/lib/algora/contracts/contracts.ex +++ b/lib/algora/contracts/contracts.ex @@ -11,8 +11,8 @@ defmodule Algora.Contracts do alias Algora.Payments alias Algora.Payments.Account alias Algora.Payments.Transaction + alias Algora.PSP.Invoice alias Algora.Repo - alias Algora.Stripe alias Algora.Util require Algora.SQL @@ -395,7 +395,7 @@ defmodule Algora.Contracts do defp maybe_generate_invoice(contract, charge) do invoice_params = %{auto_advance: false, customer: contract.client.customer.provider_id} - with {:ok, invoice} <- Stripe.Invoice.create(invoice_params), + with {:ok, invoice} <- Invoice.create(invoice_params), {:ok, _line_items} <- create_line_items(contract, invoice, charge.line_items) do {:ok, invoice} end @@ -442,7 +442,7 @@ defmodule Algora.Contracts do defp create_line_items(contract, invoice, line_items) do Enum.reduce_while(line_items, {:ok, []}, fn line_item, {:ok, acc} -> - case Stripe.Invoiceitem.create(%{ + case Algora.PSP.Invoiceitem.create(%{ invoice: invoice.id, customer: contract.client.customer.provider_id, amount: MoneyUtils.to_minor_units(line_item.amount), @@ -460,7 +460,7 @@ defmodule Algora.Contracts do defp maybe_pay_invoice(contract, invoice, txs) do pm_id = contract.client.customer.default_payment_method.provider_id - case Stripe.Invoice.pay(invoice.id, %{off_session: true, payment_method: pm_id}) do + case Invoice.pay(invoice.id, %{off_session: true, payment_method: pm_id}) do {:ok, stripe_invoice} -> if stripe_invoice.paid, do: release_funds(contract, stripe_invoice, txs) {:ok, stripe_invoice} @@ -482,7 +482,7 @@ defmodule Algora.Contracts do defp transfer_funds(contract, %Transaction{type: :transfer} = transaction) when transaction.status != :succeeded do with {:ok, account} <- Repo.fetch_by(Account, user_id: transaction.user_id), {:ok, stripe_transfer} <- - Stripe.Transfer.create(%{ + Algora.PSP.Transfer.create(%{ amount: MoneyUtils.to_minor_units(transaction.net_amount), currency: to_string(transaction.net_amount.currency), destination: account.provider_id diff --git a/lib/algora/integrations/stripe/stripe.ex b/lib/algora/integrations/stripe/stripe.ex deleted file mode 100644 index 29d3fe065..000000000 --- a/lib/algora/integrations/stripe/stripe.ex +++ /dev/null @@ -1,47 +0,0 @@ -defmodule Algora.Stripe do - @moduledoc false - - def client(module) do - :algora - |> Application.get_env(:stripe_client, Stripe) - |> Module.concat(module |> Module.split() |> List.last()) - end - - defmodule Invoice do - @moduledoc false - - def create(params), do: Algora.Stripe.client(__MODULE__).create(params) - - def pay(invoice_id, params), do: Algora.Stripe.client(__MODULE__).pay(invoice_id, params) - end - - defmodule Invoiceitem do - @moduledoc false - - def create(params), do: Algora.Stripe.client(__MODULE__).create(params) - end - - defmodule Transfer do - @moduledoc false - - def create(params), do: Algora.Stripe.client(__MODULE__).create(params) - end - - defmodule Session do - @moduledoc false - - def create(params), do: Algora.Stripe.client(__MODULE__).create(params) - end - - defmodule PaymentMethod do - @moduledoc false - - def attach(params), do: Algora.Stripe.client(__MODULE__).attach(params) - end - - defmodule SetupIntent do - @moduledoc false - - def retrieve(id, params), do: Algora.Stripe.client(__MODULE__).retrieve(id, params) - end -end diff --git a/lib/algora/payments/payments.ex b/lib/algora/payments/payments.ex index d30d52768..4fbb71caf 100644 --- a/lib/algora/payments/payments.ex +++ b/lib/algora/payments/payments.ex @@ -11,8 +11,8 @@ defmodule Algora.Payments do alias Algora.Payments.Jobs alias Algora.Payments.PaymentMethod alias Algora.Payments.Transaction + alias Algora.PSP alias Algora.Repo - alias Algora.Stripe.ConnectCountries alias Algora.Util require Logger @@ -28,12 +28,12 @@ defmodule Algora.Payments do end @spec create_stripe_session( - line_items :: [Stripe.Session.line_item_data()], - payment_intent_data :: Stripe.Session.payment_intent_data() + line_items :: [PSP.Session.line_item_data()], + payment_intent_data :: PSP.Session.payment_intent_data() ) :: - {:ok, Stripe.Session.t()} | {:error, Stripe.Error.t()} + {:ok, PSP.session()} | {:error, PSP.error()} def create_stripe_session(line_items, payment_intent_data) do - Algora.Stripe.Session.create(%{ + PSP.Session.create(%{ mode: "payment", billing_address_collection: "required", line_items: line_items, @@ -59,7 +59,7 @@ defmodule Algora.Payments do end def get_provider_fee_from_invoice(%{id: id}) do - case Stripe.Invoice.retrieve(id, expand: ["charge.balance_transaction"]) do + case PSP.Invoice.retrieve(id, expand: ["charge.balance_transaction"]) do {:ok, invoice} -> get_provider_fee_from_balance_transaction(invoice.charge.balance_transaction) @@ -71,7 +71,7 @@ defmodule Algora.Payments do # TODO: This is not used anymore def get_provider_fee_from_payment_intent(pi) do with [ch] <- pi.charges.data, - {:ok, txn} <- Stripe.BalanceTransaction.retrieve(ch.balance_transaction) do + {:ok, txn} <- PSP.BalanceTransaction.retrieve(ch.balance_transaction) do get_provider_fee_from_balance_transaction(txn) else _ -> nil @@ -153,7 +153,7 @@ defmodule Algora.Payments do end @spec fetch_or_create_customer(user :: User.t()) :: - {:ok, Customer.t()} | {:error, Ecto.Changeset.t()} | {:error, Stripe.Error.t()} + {:ok, Customer.t()} | {:error, Ecto.Changeset.t()} | {:error, PSP.error()} def fetch_or_create_customer(user) do case fetch_customer_by(user_id: user.id) do {:ok, customer} -> {:ok, customer} @@ -162,9 +162,9 @@ defmodule Algora.Payments do end @spec create_customer(user :: User.t()) :: - {:ok, Customer.t()} | {:error, Ecto.Changeset.t()} | {:error, Stripe.Error.t()} + {:ok, Customer.t()} | {:error, Ecto.Changeset.t()} | {:error, PSP.error()} def create_customer(user) do - with {:ok, stripe_customer} <- Stripe.Customer.create(%{name: user.name}) do + with {:ok, stripe_customer} <- PSP.Customer.create(%{name: user.name}) do %Customer{} |> Customer.changeset(%{ provider: "stripe", @@ -177,7 +177,7 @@ defmodule Algora.Payments do end end - @spec create_payment_method(customer :: Customer.t(), payment_method :: Stripe.PaymentMethod.t()) :: + @spec create_payment_method(customer :: Customer.t(), payment_method :: PSP.payment_method()) :: {:ok, PaymentMethod.t()} | {:error, Ecto.Changeset.t()} def create_payment_method(customer, payment_method) do %PaymentMethod{} @@ -193,9 +193,9 @@ defmodule Algora.Payments do end @spec create_stripe_setup_session(customer :: Customer.t(), success_url :: String.t(), cancel_url :: String.t()) :: - {:ok, Stripe.Session.t()} | {:error, Stripe.Error.t()} + {:ok, PSP.session()} | {:error, PSP.error()} def create_stripe_setup_session(customer, success_url, cancel_url) do - Stripe.Session.create(%{ + PSP.Session.create(%{ billing_address_collection: "required", mode: "setup", payment_method_types: ["card"], @@ -223,7 +223,7 @@ defmodule Algora.Payments do @spec create_account(user :: User.t(), country :: String.t()) :: {:ok, Account.t()} | {:error, Ecto.Changeset.t()} def create_account(user, country) do - type = ConnectCountries.account_type(country) + type = PSP.ConnectCountries.account_type(country) with {:ok, stripe_account} <- create_stripe_account(%{country: country, type: type}) do attrs = %{ @@ -242,18 +242,18 @@ defmodule Algora.Payments do end @spec create_stripe_account(attrs :: map()) :: - {:ok, Stripe.Account.t()} | {:error, Stripe.Error.t()} + {:ok, PSP.account()} | {:error, PSP.error()} defp create_stripe_account(%{country: country, type: type}) do - case Stripe.Account.create(%{country: country, type: to_string(type)}) do + case PSP.Account.create(%{country: country, type: to_string(type)}) do {:ok, account} -> {:ok, account} - {:error, _reason} -> Stripe.Account.create(%{type: to_string(type)}) + {:error, _reason} -> PSP.Account.create(%{type: to_string(type)}) end end @spec create_account_link(account :: Account.t(), base_url :: String.t()) :: - {:ok, Stripe.AccountLink.t()} | {:error, Stripe.Error.t()} + {:ok, PSP.account_link()} | {:error, PSP.error()} def create_account_link(account, base_url) do - Stripe.AccountLink.create(%{ + PSP.AccountLink.create(%{ account: account.provider_id, refresh_url: "#{base_url}/callbacks/stripe/refresh", return_url: "#{base_url}/callbacks/stripe/return", @@ -262,12 +262,12 @@ defmodule Algora.Payments do end @spec create_login_link(account :: Account.t()) :: - {:ok, Stripe.LoginLink.t()} | {:error, Stripe.Error.t()} + {:ok, PSP.login_link()} | {:error, PSP.error()} def create_login_link(account) do - Stripe.LoginLink.create(account.provider_id, %{}) + PSP.LoginLink.create(account.provider_id) end - @spec update_account(account :: Account.t(), stripe_account :: Stripe.Account.t()) :: + @spec update_account(account :: Account.t(), stripe_account :: PSP.account()) :: {:ok, Account.t()} | {:error, Ecto.Changeset.t()} def update_account(account, stripe_account) do account @@ -288,10 +288,10 @@ defmodule Algora.Payments do end @spec refresh_stripe_account(user :: User.t()) :: - {:ok, Account.t()} | {:error, Ecto.Changeset.t()} | {:error, :not_found} | {:error, Stripe.Error.t()} + {:ok, Account.t()} | {:error, Ecto.Changeset.t()} | {:error, :not_found} | {:error, PSP.error()} def refresh_stripe_account(user) do with {:ok, account} <- fetch_account(user), - {:ok, stripe_account} <- Stripe.Account.retrieve(account.provider_id, []), + {:ok, stripe_account} <- PSP.Account.retrieve(account.provider_id), {:ok, updated_account} <- update_account(account, stripe_account) do user = Accounts.get_user(account.user_id) @@ -303,25 +303,25 @@ defmodule Algora.Payments do end end - @spec get_service_agreement(account :: Stripe.Account.t()) :: String.t() + @spec get_service_agreement(account :: PSP.account()) :: String.t() defp get_service_agreement(%{tos_acceptance: %{service_agreement: agreement}} = _account) when not is_nil(agreement) do agreement end - @spec get_service_agreement(account :: Stripe.Account.t()) :: String.t() + @spec get_service_agreement(account :: PSP.account()) :: String.t() defp get_service_agreement(%{capabilities: capabilities}) do if is_nil(capabilities[:card_payments]), do: "recipient", else: "full" end @spec delete_account(account :: Account.t()) :: {:ok, Account.t()} | {:error, Ecto.Changeset.t()} def delete_account(account) do - with {:ok, _stripe_account} <- Stripe.Account.delete(account.provider_id) do + with {:ok, _stripe_account} <- PSP.Account.delete(account.provider_id) do Repo.delete(account) end end @spec execute_pending_transfer(credit_id :: String.t()) :: - {:ok, Stripe.Transfer.t()} | {:error, :not_found} | {:error, :duplicate_transfer_attempt} + {:ok, PSP.transfer()} | {:error, :not_found} | {:error, :duplicate_transfer_attempt} def execute_pending_transfer(credit_id) do with {:ok, credit} <- Repo.fetch_by(Transaction, id: credit_id, type: :credit, status: :succeeded) do transfers = @@ -391,7 +391,7 @@ defmodule Algora.Payments do end end - @spec initialize_and_execute_transfer(credit :: Transaction.t()) :: {:ok, Stripe.Transfer.t()} | {:error, term()} + @spec initialize_and_execute_transfer(credit :: Transaction.t()) :: {:ok, PSP.transfer()} | {:error, term()} defp initialize_and_execute_transfer(%Transaction{} = credit) do case fetch_active_account(credit.user_id) do {:ok, account} -> @@ -452,7 +452,7 @@ defmodule Algora.Payments do |> Map.merge(if charge && charge.provider_id, do: %{source_transaction: charge.provider_id}, else: %{}) # TODO: provide idempotency key - case Algora.Stripe.Transfer.create(transfer_params) do + case PSP.Transfer.create(transfer_params) do {:ok, transfer} -> # it's fine if this fails since we'll receive a webhook transaction diff --git a/lib/algora/payments/schemas/account.ex b/lib/algora/payments/schemas/account.ex index 07805fef5..7f0c8c0e4 100644 --- a/lib/algora/payments/schemas/account.ex +++ b/lib/algora/payments/schemas/account.ex @@ -3,7 +3,6 @@ defmodule Algora.Payments.Account do use Algora.Schema alias Algora.Activities.Activity - alias Algora.Stripe @derive {Inspect, except: [:provider_meta]} typed_schema "accounts" do @@ -60,7 +59,7 @@ defmodule Algora.Payments.Account do :user_id ]) |> validate_inclusion(:type, [:standard, :express]) - |> validate_inclusion(:country, Stripe.ConnectCountries.list_codes()) + |> validate_inclusion(:country, Algora.PSP.ConnectCountries.list_codes()) |> foreign_key_constraint(:user_id) |> generate_id() end diff --git a/lib/algora/integrations/stripe/connect_countries.ex b/lib/algora/psp/connect_countries.ex similarity index 98% rename from lib/algora/integrations/stripe/connect_countries.ex rename to lib/algora/psp/connect_countries.ex index 58c4d9d81..7877f514a 100644 --- a/lib/algora/integrations/stripe/connect_countries.ex +++ b/lib/algora/psp/connect_countries.ex @@ -1,4 +1,4 @@ -defmodule Algora.Stripe.ConnectCountries do +defmodule Algora.PSP.ConnectCountries do @moduledoc false @spec list() :: [{String.t(), String.t()}] diff --git a/lib/algora/psp/psp.ex b/lib/algora/psp/psp.ex new file mode 100644 index 000000000..11dd3e1f5 --- /dev/null +++ b/lib/algora/psp/psp.ex @@ -0,0 +1,122 @@ +defmodule Algora.PSP do + @moduledoc """ + Payment Service Provider (PSP) interface module. + + This module serves as an abstraction layer for payment service provider interactions. + Currently, it implements Stripe as the default payment processor, but is designed + to be extensible for supporting multiple payment providers in the future (e.g., PayPal). + + The module provides a unified interface for common payment operations such as: + - Invoice management + - Payment processing + - Transfer operations + - Checkout sessions + - Payment method handling + - Setup intents + + Each submodule corresponds to a specific payment service functionality and delegates + to the configured payment provider client (currently Stripe). + """ + + def client(module) do + :algora + |> Application.get_env(:stripe_client, Stripe) + |> Module.concat(module |> Module.split() |> List.last()) + end + + @type error :: Stripe.Error.t() + + @type invoice :: Stripe.Invoice.t() + defmodule Invoice do + @moduledoc false + + def create(params), do: Algora.PSP.client(__MODULE__).create(params) + def pay(invoice_id, params), do: Algora.PSP.client(__MODULE__).pay(invoice_id, params) + def retrieve(id), do: Algora.PSP.client(__MODULE__).retrieve(id) + def retrieve(id, opts), do: Algora.PSP.client(__MODULE__).retrieve(id, opts) + end + + @type invoiceitem :: Stripe.Invoiceitem.t() + defmodule Invoiceitem do + @moduledoc false + + def create(params), do: Algora.PSP.client(__MODULE__).create(params) + end + + @type transfer :: Stripe.Transfer.t() + defmodule Transfer do + @moduledoc false + + def create(params), do: Algora.PSP.client(__MODULE__).create(params) + end + + @type session :: Stripe.Session.t() + defmodule Session do + @moduledoc false + + @type line_item_data :: Stripe.Session.line_item_data() + @type payment_intent_data :: Stripe.Session.payment_intent_data() + + def create(params), do: Algora.PSP.client(__MODULE__).create(params) + end + + @type payment_method :: Stripe.PaymentMethod.t() + defmodule PaymentMethod do + @moduledoc false + + def attach(params), do: Algora.PSP.client(__MODULE__).attach(params) + def retrieve(id), do: Algora.PSP.client(__MODULE__).retrieve(id) + end + + @type payment_intent :: Stripe.PaymentIntent.t() + defmodule PaymentIntent do + @moduledoc false + + def create(params), do: Algora.PSP.client(__MODULE__).create(params) + end + + @type setup_intent :: Stripe.SetupIntent.t() + defmodule SetupIntent do + @moduledoc false + + def retrieve(id, params), do: Algora.PSP.client(__MODULE__).retrieve(id, params) + end + + @type customer :: Stripe.Customer.t() + defmodule Customer do + @moduledoc false + + def retrieve(id), do: Algora.PSP.client(__MODULE__).retrieve(id) + def create(params), do: Algora.PSP.client(__MODULE__).create(params) + end + + @type account :: Stripe.Account.t() + defmodule Account do + @moduledoc false + + def retrieve(id), do: Algora.PSP.client(__MODULE__).retrieve(id) + def create(params), do: Algora.PSP.client(__MODULE__).create(params) + def delete(id), do: Algora.PSP.client(__MODULE__).delete(id) + end + + @type account_link :: Stripe.AccountLink.t() + defmodule AccountLink do + @moduledoc false + + def create(params), do: Algora.PSP.client(__MODULE__).create(params) + end + + @type login_link :: Stripe.LoginLink.t() + defmodule LoginLink do + @moduledoc false + + def create(params), do: Algora.PSP.client(__MODULE__).create(params) + end + + @type balance_transaction :: Stripe.BalanceTransaction.t() + defmodule BalanceTransaction do + @moduledoc false + + def retrieve(id), do: Algora.PSP.client(__MODULE__).retrieve(id) + end +end diff --git a/lib/algora_web/controllers/webhooks/github_controller.ex b/lib/algora_web/controllers/webhooks/github_controller.ex index 2d447daf8..49bbf671f 100644 --- a/lib/algora_web/controllers/webhooks/github_controller.ex +++ b/lib/algora_web/controllers/webhooks/github_controller.ex @@ -152,7 +152,7 @@ defmodule AlgoraWeb.Webhooks.GithubController do claims: claims ), {:ok, _invoice} <- - Algora.Stripe.Invoice.pay(invoice, %{ + Algora.PSP.Invoice.pay(invoice, %{ payment_method: autopayable_bounty.owner.customer.default_payment_method.provider_id, off_session: true }) do diff --git a/lib/algora_web/controllers/webhooks/stripe_controller.ex b/lib/algora_web/controllers/webhooks/stripe_controller.ex index aa2756ba6..d2e4540ed 100644 --- a/lib/algora_web/controllers/webhooks/stripe_controller.ex +++ b/lib/algora_web/controllers/webhooks/stripe_controller.ex @@ -92,9 +92,9 @@ defmodule AlgoraWeb.Webhooks.StripeController do type: "checkout.session.completed", data: %{object: %Stripe.Session{customer: customer_id, mode: "setup", setup_intent: setup_intent_id}} }) do - with {:ok, setup_intent} <- Algora.Stripe.SetupIntent.retrieve(setup_intent_id, %{}), + with {:ok, setup_intent} <- Algora.PSP.SetupIntent.retrieve(setup_intent_id, %{}), pm_id = setup_intent.payment_method, - {:ok, payment_method} <- Algora.Stripe.PaymentMethod.attach(%{payment_method: pm_id, customer: customer_id}), + {:ok, payment_method} <- Algora.PSP.PaymentMethod.attach(%{payment_method: pm_id, customer: customer_id}), {:ok, customer} <- Repo.fetch_by(Customer, provider: "stripe", provider_id: customer_id), {:ok, _} <- Payments.create_payment_method(customer, payment_method) do Payments.broadcast() diff --git a/lib/algora_web/live/contract/modals/release_drawer.ex b/lib/algora_web/live/contract/modals/release_drawer.ex index fb08cf8cd..c27101967 100644 --- a/lib/algora_web/live/contract/modals/release_drawer.ex +++ b/lib/algora_web/live/contract/modals/release_drawer.ex @@ -133,7 +133,7 @@ defmodule AlgoraWeb.Contract.Modals.ReleaseDrawer do original_contract_id: contract.original_contract_id }) - case Stripe.PaymentIntent.create(%{ + case Algora.PSP.PaymentIntent.create(%{ amount: MoneyUtils.to_minor_units(gross_amount), currency: to_string(gross_amount.currency), customer: org.customer.provider_id, diff --git a/lib/algora_web/live/org/transactions_live.ex b/lib/algora_web/live/org/transactions_live.ex index d2d32621b..715a6aab9 100644 --- a/lib/algora_web/live/org/transactions_live.ex +++ b/lib/algora_web/live/org/transactions_live.ex @@ -7,7 +7,6 @@ defmodule AlgoraWeb.Org.TransactionsLive do alias Algora.Accounts.User alias Algora.Payments - alias Algora.Stripe.ConnectCountries alias Algora.Util defmodule PayoutAccountForm do @@ -16,7 +15,7 @@ defmodule AlgoraWeb.Org.TransactionsLive do import Ecto.Changeset - @countries ConnectCountries.list() + @countries Algora.PSP.ConnectCountries.list() embedded_schema do field :country, :string @@ -359,7 +358,7 @@ defmodule AlgoraWeb.Org.TransactionsLive do
Country
- {ConnectCountries.from_code(@account.country)} + {Algora.PSP.ConnectCountries.from_code(@account.country)}
diff --git a/lib/algora_web/live/user/transactions_live.ex b/lib/algora_web/live/user/transactions_live.ex index 18c7a9db8..d2e66d970 100644 --- a/lib/algora_web/live/user/transactions_live.ex +++ b/lib/algora_web/live/user/transactions_live.ex @@ -7,7 +7,6 @@ defmodule AlgoraWeb.User.TransactionsLive do alias Algora.Accounts.User alias Algora.Payments - alias Algora.Stripe.ConnectCountries alias Algora.Util defmodule PayoutAccountForm do @@ -16,7 +15,7 @@ defmodule AlgoraWeb.User.TransactionsLive do import Ecto.Changeset - @countries ConnectCountries.list() + @countries Algora.PSP.ConnectCountries.list() embedded_schema do field :country, :string @@ -376,7 +375,7 @@ defmodule AlgoraWeb.User.TransactionsLive do
Country
- {ConnectCountries.from_code(@account.country)} + {Algora.PSP.ConnectCountries.from_code(@account.country)}
diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs index 25de58252..b3001fc60 100644 --- a/priv/repo/seeds.exs +++ b/priv/repo/seeds.exs @@ -159,8 +159,8 @@ for user <- pied_piper_members do end if customer_id = Algora.config([:stripe, :test_customer_id]) do - {:ok, cus} = Stripe.Customer.retrieve(customer_id) - {:ok, pm} = Stripe.PaymentMethod.retrieve(cus.invoice_settings.default_payment_method) + {:ok, cus} = Algora.PSP.Customer.retrieve(customer_id) + {:ok, pm} = Algora.PSP.PaymentMethod.retrieve(cus.invoice_settings.default_payment_method) customer = upsert!( @@ -188,7 +188,7 @@ if customer_id = Algora.config([:stripe, :test_customer_id]) do end if account_id = Algora.config([:stripe, :test_account_id]) do - {:ok, acct} = Stripe.Account.retrieve(account_id) + {:ok, acct} = Algora.PSP.Account.retrieve(account_id) upsert!( :account, diff --git a/test/algora/bounties_test.exs b/test/algora/bounties_test.exs index 7d8496e01..16a1a69ec 100644 --- a/test/algora/bounties_test.exs +++ b/test/algora/bounties_test.exs @@ -9,6 +9,7 @@ defmodule Algora.BountiesTest do alias Algora.Activities.SendEmail alias Algora.Bounties alias Algora.Payments.Transaction + alias Algora.PSP alias Bounties.Tip describe "bounties" do @@ -185,7 +186,7 @@ defmodule Algora.BountiesTest do ) assert {:ok, _invoice} = - Algora.Stripe.Invoice.pay(invoice, %{ + PSP.Invoice.pay(invoice, %{ payment_method: payment_method.provider_id, off_session: true }) diff --git a/test/algora_web/controllers/webhooks/stripe_controller_test.exs b/test/algora_web/controllers/webhooks/stripe_controller_test.exs index a650ed6ab..27c83b40b 100644 --- a/test/algora_web/controllers/webhooks/stripe_controller_test.exs +++ b/test/algora_web/controllers/webhooks/stripe_controller_test.exs @@ -9,6 +9,7 @@ defmodule AlgoraWeb.Webhooks.StripeControllerTest do alias Algora.Payments alias Algora.Payments.PaymentMethod alias Algora.Payments.Transaction + alias Algora.PSP alias Algora.Repo alias AlgoraWeb.Webhooks.StripeController @@ -152,7 +153,7 @@ defmodule AlgoraWeb.Webhooks.StripeControllerTest do assert :ok = StripeController.handle_event(event) - {:ok, setup_intent} = Algora.Stripe.SetupIntent.retrieve(setup_intent_id, %{}) + {:ok, setup_intent} = PSP.SetupIntent.retrieve(setup_intent_id, %{}) payment_method = Repo.one!(from p in PaymentMethod, where: p.provider_id == ^setup_intent.payment_method) assert payment_method.customer_id == customer.id