Skip to content

Commit e8dd51f

Browse files
authored
feat: allow attaching same payment method or customer record to multiple orgs (#67)
1 parent 0f7de10 commit e8dd51f

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

lib/algora/payments/schemas/customer.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ defmodule Algora.Payments.Customer do
2828
|> cast(attrs, [:user_id, :provider, :provider_id, :provider_meta, :name])
2929
|> generate_id()
3030
|> validate_required([:user_id, :provider, :provider_id, :provider_meta, :name])
31-
|> unique_constraint([:provider, :provider_id])
3231
|> unique_constraint(:user_id)
3332
|> foreign_key_constraint(:user_id)
3433
end

lib/algora/payments/schemas/payment_method.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ defmodule Algora.Payments.PaymentMethod do
2323
|> cast(attrs, [:provider, :provider_id, :provider_meta, :provider_customer_id, :is_default, :customer_id])
2424
|> generate_id()
2525
|> validate_required([:provider, :provider_id, :provider_meta, :provider_customer_id, :is_default, :customer_id])
26-
|> unique_constraint([:provider, :provider_id])
2726
|> foreign_key_constraint(:customer_id)
2827
end
2928
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defmodule Algora.Repo.Migrations.DropProviderIndexes do
2+
use Ecto.Migration
3+
4+
def up do
5+
drop unique_index(:payment_methods, [:provider, :provider_id])
6+
drop unique_index(:customers, [:provider, :provider_id])
7+
end
8+
9+
def down do
10+
create unique_index(:payment_methods, [:provider, :provider_id])
11+
create unique_index(:customers, [:provider, :provider_id])
12+
end
13+
end

scripts/database_migration.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ defmodule DatabaseMigration do
7373
{"Reward", ["bounty_id"]}
7474
]
7575

76+
@test_org_id "cljo6j981000el60f1k1cvtns"
77+
7678
defp relevant_tables do
7779
@schema_mappings
7880
|> Enum.map(fn {k, _v} -> k end)
@@ -699,7 +701,7 @@ defmodule DatabaseMigration do
699701
raise "Owner not found: #{inspect(row)}"
700702
end
701703

702-
if owner["id"] not in ["clfqtao4h0001mo0gkp9az0bn", "cm251pvg40007ld031q5t2hj2", "cljo6j981000el60f1k1cvtns"] do
704+
if owner["id"] != @test_org_id do
703705
%{
704706
"id" => row["id"],
705707
"provider" => "stripe",
@@ -726,7 +728,7 @@ defmodule DatabaseMigration do
726728
raise "StripeCustomer not found: #{inspect(row)}"
727729
end
728730

729-
if owner["id"] not in ["clfqtao4h0001mo0gkp9az0bn", "cm251pvg40007ld031q5t2hj2", "cljo6j981000el60f1k1cvtns"] do
731+
if owner["id"] != @test_org_id do
730732
%{
731733
"id" => row["id"],
732734
"provider" => "stripe",

0 commit comments

Comments
 (0)