File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -675,6 +675,15 @@ defmodule Core.Services.Payments do
675
675
defp discount ( amount , :yearly ) , do: round ( 9 * amount / 10 ) * 12
676
676
defp discount ( amount , _ ) , do: amount
677
677
678
+ def setup_enterprise_plan ( % User { } = user ) do
679
+ case Repo . preload ( user , [ account: [ subscription: :plan ] ] ) do
680
+ % { account: % Account { } = account } ->
681
+ with { :ok , _ } <- remove_trial ( account ) ,
682
+ do: setup_enterprise_plan ( user . account_id )
683
+ _ -> setup_enterprise_plan ( user . account_id )
684
+ end
685
+ end
686
+
678
687
def setup_enterprise_plan ( account_id ) do
679
688
plan = get_platform_plan_by_name! ( "Enterprise" )
680
689
Original file line number Diff line number Diff line change @@ -869,6 +869,19 @@ defmodule Core.Services.PaymentsTest do
869
869
assert subscription . plan_id == plan . id
870
870
refute subscription . external_id
871
871
end
872
+
873
+ test "it will set up a plan for a user with a trial" do
874
+ plan = insert ( :platform_plan , name: "Enterprise" , enterprise: true )
875
+ trial = insert ( :platform_plan , name: "Pro Trial" , trial: true )
876
+ account = insert ( :account )
877
+ insert ( :platform_subscription , account: account , plan: trial )
878
+ user = insert ( :user , account: account )
879
+
880
+ { :ok , subscription } = Payments . setup_enterprise_plan ( user )
881
+
882
+ assert subscription . account_id == account . id
883
+ assert subscription . plan_id == plan . id
884
+ end
872
885
end
873
886
874
887
describe "#begin_trail/1" do
You can’t perform that action at this time.
0 commit comments