diff --git a/lib/algora/contracts/contracts.ex b/lib/algora/contracts/contracts.ex index 44240342c..9be089f24 100644 --- a/lib/algora/contracts/contracts.ex +++ b/lib/algora/contracts/contracts.ex @@ -472,9 +472,7 @@ defmodule Algora.Contracts do defp maybe_pay_invoice(contract, invoice, txs) do pm_id = contract.client.customer.default_payment_method.provider_id - case Invoice.pay(invoice.id, %{off_session: true, payment_method: pm_id}, %{ - idempotency_key: "contract-#{contract.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} diff --git a/lib/algora/psp/psp.ex b/lib/algora/psp/psp.ex index 0e67138c0..9e33f80d7 100644 --- a/lib/algora/psp/psp.ex +++ b/lib/algora/psp/psp.ex @@ -47,17 +47,14 @@ defmodule Algora.PSP do } def create(params, opts), do: Algora.PSP.client(__MODULE__).create(params, Keyword.new(opts)) - @spec pay(Stripe.id() | t, params, options) :: {:ok, t} | {:error, Algora.PSP.error()} + @spec pay(Stripe.id() | t, params) :: {:ok, t} | {:error, Algora.PSP.error()} when params: %{ optional(:off_session) => boolean, optional(:payment_method) => String.t() } - | %{}, - options: %{ - :idempotency_key => String.t() - } - def pay(invoice_id, params, opts), do: Algora.PSP.client(__MODULE__).pay(invoice_id, params, Keyword.new(opts)) + | %{} + 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, Keyword.new(opts)) diff --git a/lib/algora_web/controllers/webhooks/github_controller.ex b/lib/algora_web/controllers/webhooks/github_controller.ex index b57e3fa05..4c423b310 100644 --- a/lib/algora_web/controllers/webhooks/github_controller.ex +++ b/lib/algora_web/controllers/webhooks/github_controller.ex @@ -208,14 +208,12 @@ defmodule AlgoraWeb.Webhooks.GithubController do autopay_result = if autopayable_bounty do - idempotency_key = "bounty-#{autopayable_bounty.id}" - with {:ok, invoice} <- Bounties.create_invoice( %{ owner: autopayable_bounty.owner, amount: autopayable_bounty.amount, - idempotency_key: idempotency_key + idempotency_key: "bounty-#{autopayable_bounty.id}" }, ticket_ref: %{ owner: payload["repository"]["owner"]["login"], @@ -231,8 +229,7 @@ defmodule AlgoraWeb.Webhooks.GithubController do %{ payment_method: autopayable_bounty.owner.customer.default_payment_method.provider_id, off_session: true - }, - %{idempotency_key: idempotency_key} + } ) do Algora.Admin.alert( "Autopay successful (#{autopayable_bounty.owner.name} - #{autopayable_bounty.amount}).", @@ -439,8 +436,6 @@ defmodule AlgoraWeb.Webhooks.GithubController do not is_nil(amount) and autopay_cooldown_expired?.() - idempotency_key = "tip-#{recipient}-#{webhook.delivery}" - autopay_result = if autopayable? do with {:ok, owner} <- Accounts.fetch_user_by(id: installation.connected_user_id), @@ -458,21 +453,14 @@ defmodule AlgoraWeb.Webhooks.GithubController do %{ owner: owner, amount: amount, - idempotency_key: idempotency_key + idempotency_key: "invoice-#{recipient.provider_login}-#{webhook.delivery}" }, ticket_ref: ticket_ref, tip_id: tip.id, recipient: recipient ), {:ok, _invoice} <- - Invoice.pay( - invoice, - %{ - payment_method: customer.default_payment_method.provider_id, - off_session: true - }, - %{idempotency_key: idempotency_key} - ) do + Invoice.pay(invoice, %{payment_method: customer.default_payment_method.provider_id, off_session: true}) do Algora.Admin.alert( "Autopay successful (#{payload["repository"]["full_name"]}##{ticket_ref.number} - #{amount}).", :info diff --git a/test/algora/bounties_test.exs b/test/algora/bounties_test.exs index a2e264871..ffdcceb8f 100644 --- a/test/algora/bounties_test.exs +++ b/test/algora/bounties_test.exs @@ -197,15 +197,7 @@ defmodule Algora.BountiesTest do claims: [claim] ) - assert {:ok, _invoice} = - PSP.Invoice.pay( - invoice, - %{ - payment_method: payment_method.provider_id, - off_session: true - }, - %{idempotency_key: "bounty-#{bounty.id}"} - ) + assert {:ok, _invoice} = PSP.Invoice.pay(invoice, %{payment_method: payment_method.provider_id, off_session: true}) charge = Repo.one!(from t in Transaction, where: t.type == :charge) assert Money.equal?(charge.net_amount, amount) diff --git a/test/support/stripe_mock.ex b/test/support/stripe_mock.ex index 4527d54b6..27c6d64ba 100644 --- a/test/support/stripe_mock.ex +++ b/test/support/stripe_mock.ex @@ -12,7 +12,7 @@ defmodule Algora.Support.StripeMock do }} end - def pay(_invoice_id, %{payment_method: "pm_card_declined"}, _opts) do + def pay(_invoice_id, %{payment_method: "pm_card_declined"}) do {:error, %Stripe.Error{ source: :stripe, @@ -21,7 +21,7 @@ defmodule Algora.Support.StripeMock do }} end - def pay(invoice_id, _params, _opts) do + def pay(invoice_id, _params) do {:ok, %Stripe.Invoice{id: invoice_id, paid: true, status: "paid"}} end end