@@ -663,7 +663,7 @@ func (s *SubscriptionHandlerTestSuite) TestInArrearsProrating() {
663
663
s .Equal (flatFeeLine .FlatFee .Quantity .InexactFloat64 (), 1.0 )
664
664
})
665
665
666
- s .Run ("canceling the subscription causes the existing item to be pro-rated" , func () {
666
+ s .Run ("canceling the subscription DOES NOT cause the existing item to be pro-rated" , func () {
667
667
clock .SetTime (s .mustParseTime ("2024-01-01T10:00:00Z" ))
668
668
669
669
cancelAt := s .mustParseTime ("2024-01-01T12:00:00Z" )
@@ -706,8 +706,8 @@ func (s *SubscriptionHandlerTestSuite) TestInArrearsProrating() {
706
706
Start : s .mustParseTime ("2024-01-01T00:00:00Z" ),
707
707
End : cancelAt ,
708
708
})
709
- s .Equal (flatFeeLine .FlatFee .PerUnitAmount .InexactFloat64 (), 2.5 )
710
- s .Equal (flatFeeLine .FlatFee .Quantity .InexactFloat64 (), 1.0 )
709
+ s .Equal (5.0 , flatFeeLine .FlatFee .PerUnitAmount .InexactFloat64 ())
710
+ s .Equal (1.0 , flatFeeLine .FlatFee .Quantity .InexactFloat64 ())
711
711
})
712
712
}
713
713
@@ -801,24 +801,44 @@ func (s *SubscriptionHandlerTestSuite) TestInAdvanceGatheringSyncNonBillableAmou
801
801
// the gathering invoice will only contain both versions of the fee as we are not
802
802
// doing any pro-rating logic
803
803
804
- subsView := s .createSubscriptionFromPlanPhases ([]productcatalog.Phase {
805
- {
806
- PhaseMeta : s .phaseMeta ("first-phase" , "" ),
807
- RateCards : productcatalog.RateCards {
808
- & productcatalog.UsageBasedRateCard {
809
- RateCardMeta : productcatalog.RateCardMeta {
810
- Key : "in-advance" ,
811
- Name : "in-advance" ,
812
- Price : productcatalog .NewPriceFrom (productcatalog.FlatPrice {
813
- Amount : alpacadecimal .NewFromFloat (5 ),
814
- PaymentTerm : productcatalog .InAdvancePaymentTerm ,
815
- }),
804
+ planInput := plan.CreatePlanInput {
805
+ NamespacedModel : models.NamespacedModel {
806
+ Namespace : s .Namespace ,
807
+ },
808
+ Plan : productcatalog.Plan {
809
+ PlanMeta : productcatalog.PlanMeta {
810
+ Name : "Test Plan" ,
811
+ Key : "test-plan" ,
812
+ Version : 1 ,
813
+ Currency : currency .USD ,
814
+ BillingCadence : isodate .MustParse (s .T (), "P1M" ),
815
+ ProRatingConfig : productcatalog.ProRatingConfig {
816
+ Enabled : false ,
817
+ Mode : productcatalog .ProRatingModeProratePrices ,
818
+ },
819
+ },
820
+ Phases : []productcatalog.Phase {
821
+ {
822
+ PhaseMeta : s .phaseMeta ("first-phase" , "" ),
823
+ RateCards : productcatalog.RateCards {
824
+ & productcatalog.UsageBasedRateCard {
825
+ RateCardMeta : productcatalog.RateCardMeta {
826
+ Key : "in-advance" ,
827
+ Name : "in-advance" ,
828
+ Price : productcatalog .NewPriceFrom (productcatalog.FlatPrice {
829
+ Amount : alpacadecimal .NewFromFloat (5 ),
830
+ PaymentTerm : productcatalog .InAdvancePaymentTerm ,
831
+ }),
832
+ },
833
+ BillingCadence : isodate .MustParse (s .T (), "P1D" ),
834
+ },
816
835
},
817
- BillingCadence : isodate .MustParse (s .T (), "P1D" ),
818
836
},
819
837
},
820
838
},
821
- })
839
+ }
840
+
841
+ subsView := s .createSubscriptionFromPlan (planInput )
822
842
823
843
s .NoError (s .Handler .SyncronizeSubscription (ctx , subsView , s .mustParseTime ("2024-01-05T12:00:00Z" )))
824
844
s .DebugDumpInvoice ("gathering invoice" , s .gatheringInvoice (ctx , s .Namespace , s .Customer .ID ))
@@ -897,24 +917,44 @@ func (s *SubscriptionHandlerTestSuite) TestInArrearsGatheringSyncNonBillableAmou
897
917
// the gathering invoice will only contain both versions of the fee as we are not
898
918
// doing any pro-rating logic
899
919
900
- subsView := s .createSubscriptionFromPlanPhases ([]productcatalog.Phase {
901
- {
902
- PhaseMeta : s .phaseMeta ("first-phase" , "" ),
903
- RateCards : productcatalog.RateCards {
904
- & productcatalog.UsageBasedRateCard {
905
- RateCardMeta : productcatalog.RateCardMeta {
906
- Key : "in-arrears" ,
907
- Name : "in-arrears" ,
908
- Price : productcatalog .NewPriceFrom (productcatalog.FlatPrice {
909
- Amount : alpacadecimal .NewFromFloat (5 ),
910
- PaymentTerm : productcatalog .InArrearsPaymentTerm ,
911
- }),
920
+ planInput := plan.CreatePlanInput {
921
+ NamespacedModel : models.NamespacedModel {
922
+ Namespace : s .Namespace ,
923
+ },
924
+ Plan : productcatalog.Plan {
925
+ PlanMeta : productcatalog.PlanMeta {
926
+ Name : "Test Plan" ,
927
+ Key : "test-plan" ,
928
+ Version : 1 ,
929
+ Currency : currency .USD ,
930
+ BillingCadence : isodate .MustParse (s .T (), "P1M" ),
931
+ ProRatingConfig : productcatalog.ProRatingConfig {
932
+ Enabled : false ,
933
+ Mode : productcatalog .ProRatingModeProratePrices ,
934
+ },
935
+ },
936
+ Phases : []productcatalog.Phase {
937
+ {
938
+ PhaseMeta : s .phaseMeta ("first-phase" , "" ),
939
+ RateCards : productcatalog.RateCards {
940
+ & productcatalog.UsageBasedRateCard {
941
+ RateCardMeta : productcatalog.RateCardMeta {
942
+ Key : "in-arrears" ,
943
+ Name : "in-arrears" ,
944
+ Price : productcatalog .NewPriceFrom (productcatalog.FlatPrice {
945
+ Amount : alpacadecimal .NewFromFloat (5 ),
946
+ PaymentTerm : productcatalog .InArrearsPaymentTerm ,
947
+ }),
948
+ },
949
+ BillingCadence : isodate .MustParse (s .T (), "P1D" ),
950
+ },
912
951
},
913
- BillingCadence : isodate .MustParse (s .T (), "P1D" ),
914
952
},
915
953
},
916
954
},
917
- })
955
+ }
956
+
957
+ subsView := s .createSubscriptionFromPlan (planInput )
918
958
919
959
s .NoError (s .Handler .SyncronizeSubscription (ctx , subsView , s .mustParseTime ("2024-01-05T12:00:00Z" )))
920
960
s .DebugDumpInvoice ("gathering invoice" , s .gatheringInvoice (ctx , s .Namespace , s .Customer .ID ))
@@ -1467,7 +1507,7 @@ func (s *SubscriptionHandlerTestSuite) TestAlignedSubscriptionInvoicing() {
1467
1507
},
1468
1508
BillingCadence : isodate .MustParse (s .T (), "P4W" ),
1469
1509
ProRatingConfig : productcatalog.ProRatingConfig {
1470
- Enabled : true ,
1510
+ Enabled : false ,
1471
1511
Mode : productcatalog .ProRatingModeProratePrices ,
1472
1512
},
1473
1513
},
@@ -3675,6 +3715,9 @@ func (s *SubscriptionHandlerTestSuite) TestAlignedSubscriptionProratingBehavior(
3675
3715
gatheringInvoice := s .gatheringInvoice (ctx , s .Namespace , s .Customer .ID )
3676
3716
s .DebugDumpInvoice ("gathering invoice" , gatheringInvoice )
3677
3717
3718
+ // January is 31 days, wechange phase after 2 weeks (14 days)
3719
+ // 5 * 14/31 = 2.258... which we round to 2.26
3720
+
3678
3721
s .expectLines (gatheringInvoice , subView .Subscription .ID , []expectedLine {
3679
3722
// First phase lines
3680
3723
{
@@ -3683,7 +3726,7 @@ func (s *SubscriptionHandlerTestSuite) TestAlignedSubscriptionProratingBehavior(
3683
3726
ItemKey : "in-advance" ,
3684
3727
},
3685
3728
Qty : mo .Some (1.0 ),
3686
- UnitPrice : mo .Some (2.5 ),
3729
+ UnitPrice : mo .Some (2.26 ),
3687
3730
Periods : []billing.Period {
3688
3731
{
3689
3732
Start : s .mustParseTime ("2024-01-01T00:00:00Z" ),
@@ -3698,7 +3741,7 @@ func (s *SubscriptionHandlerTestSuite) TestAlignedSubscriptionProratingBehavior(
3698
3741
ItemKey : "in-arrears" ,
3699
3742
},
3700
3743
Qty : mo .Some (1.0 ),
3701
- UnitPrice : mo .Some (2.5 ),
3744
+ UnitPrice : mo .Some (2.26 ),
3702
3745
Periods : []billing.Period {
3703
3746
{
3704
3747
Start : s .mustParseTime ("2024-01-01T00:00:00Z" ),
@@ -3712,8 +3755,7 @@ func (s *SubscriptionHandlerTestSuite) TestAlignedSubscriptionProratingBehavior(
3712
3755
PhaseKey : "first-phase" ,
3713
3756
ItemKey : "api-requests-total" ,
3714
3757
},
3715
- Qty : mo .Some (1.0 ),
3716
- UnitPrice : mo.Some [float64 ](10 ),
3758
+ Price : mo .Some (productcatalog .NewPriceFrom (productcatalog.UnitPrice {Amount : alpacadecimal .NewFromFloat (10 )})),
3717
3759
Periods : []billing.Period {
3718
3760
{
3719
3761
Start : s .mustParseTime ("2024-01-01T00:00:00Z" ),
@@ -3731,7 +3773,7 @@ func (s *SubscriptionHandlerTestSuite) TestAlignedSubscriptionProratingBehavior(
3731
3773
PeriodMax : 1 ,
3732
3774
},
3733
3775
Qty : mo .Some (1.0 ),
3734
- UnitPrice : mo .Some (2.5 ),
3776
+ UnitPrice : mo .Some (5.0 ),
3735
3777
Periods : []billing.Period {
3736
3778
{
3737
3779
Start : s .mustParseTime ("2024-01-15T00:00:00Z" ),
@@ -3752,7 +3794,7 @@ func (s *SubscriptionHandlerTestSuite) TestAlignedSubscriptionProratingBehavior(
3752
3794
PeriodMax : 1 ,
3753
3795
},
3754
3796
Qty : mo .Some (1.0 ),
3755
- UnitPrice : mo .Some (2.5 ),
3797
+ UnitPrice : mo .Some (5.0 ),
3756
3798
Periods : []billing.Period {
3757
3799
{
3758
3800
Start : s .mustParseTime ("2024-01-15T00:00:00Z" ),
@@ -3772,8 +3814,7 @@ func (s *SubscriptionHandlerTestSuite) TestAlignedSubscriptionProratingBehavior(
3772
3814
PeriodMin : 0 ,
3773
3815
PeriodMax : 1 ,
3774
3816
},
3775
- Qty : mo .Some (1.0 ),
3776
- UnitPrice : mo.Some [float64 ](10 ),
3817
+ Price : mo .Some (productcatalog .NewPriceFrom (productcatalog.UnitPrice {Amount : alpacadecimal .NewFromFloat (10 )})),
3777
3818
Periods : []billing.Period {
3778
3819
{
3779
3820
Start : s .mustParseTime ("2024-01-15T00:00:00Z" ),
@@ -3824,19 +3865,29 @@ func (s *SubscriptionHandlerTestSuite) expectLines(invoice billing.Invoice, subs
3824
3865
3825
3866
if expectedLine .Qty .IsPresent () {
3826
3867
if line .Type == billing .InvoiceLineTypeFee {
3827
- s .Equal (expectedLine .Qty .OrEmpty (), line .FlatFee .Quantity .InexactFloat64 (), "%s: quantity" , childID )
3868
+ if line .FlatFee == nil {
3869
+ s .Failf ("flat fee line not found" , "line not found with child id %s" , childID )
3870
+ } else {
3871
+ s .Equal (expectedLine .Qty .OrEmpty (), line .FlatFee .Quantity .InexactFloat64 (), "%s: quantity" , childID )
3872
+ }
3828
3873
} else {
3829
- s .Equal (expectedLine .Qty .OrEmpty (), line .UsageBased .Quantity .InexactFloat64 (), "%s: quantity" , childID )
3874
+ if line .UsageBased == nil {
3875
+ s .Failf ("usage based line not found" , "line not found with child id %s" , childID )
3876
+ } else if line .UsageBased .Quantity == nil {
3877
+ s .Failf ("usage based line quantity not found" , "line not found with child id %s" , childID )
3878
+ } else {
3879
+ s .Equal (expectedLine .Qty .OrEmpty (), line .UsageBased .Quantity .InexactFloat64 (), "%s: quantity" , childID )
3880
+ }
3830
3881
}
3831
3882
}
3832
3883
3833
3884
if expectedLine .UnitPrice .IsPresent () {
3834
- s .Equal (line . Type , billing . InvoiceLineTypeFee , "%s: line type" , childID )
3885
+ s .Equal (billing . InvoiceLineTypeFee , line . Type , "%s: line type" , childID )
3835
3886
s .Equal (expectedLine .UnitPrice .OrEmpty (), line .FlatFee .PerUnitAmount .InexactFloat64 (), "%s: unit price" , childID )
3836
3887
}
3837
3888
3838
3889
if expectedLine .Price .IsPresent () {
3839
- s .Equal (line . Type , billing . InvoiceLineTypeUsageBased , "%s: line type" , childID )
3890
+ s .Equal (billing . InvoiceLineTypeUsageBased , line . Type , "%s: line type" , childID )
3840
3891
s .Equal (* expectedLine .Price .OrEmpty (), * line .UsageBased .Price , "%s: price" , childID )
3841
3892
}
3842
3893
0 commit comments