@startsimpli/billing 0.4.7 → 0.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/PricingDetailPage.integration.test.tsx +27 -27
- package/src/components/PricingDetailPage.test.tsx +36 -36
- package/src/components/PricingDetailPage.tsx +8 -8
- package/src/components/PricingPage.test.tsx +36 -36
- package/src/components/PricingPage.tsx +7 -7
- package/src/components/PricingSection.test.tsx +36 -36
- package/src/components/PricingSection.tsx +7 -7
- package/src/components/SubscriptionManager.test.tsx +58 -58
- package/src/components/SubscriptionManager.tsx +15 -15
- package/src/components/UpgradeModal.test.tsx +12 -12
- package/src/components/UpgradeModal.tsx +8 -8
- package/src/hooks/useCheckout.test.tsx +6 -6
- package/src/hooks/useProduct.test.tsx +24 -24
- package/src/hooks/useSubscription.test.tsx +16 -16
- package/src/types/index.ts +30 -30
- package/src/utils/api.test.ts +3 -3
package/package.json
CHANGED
|
@@ -22,45 +22,45 @@ const mockProduct: BillingProduct = {
|
|
|
22
22
|
id: "offer-1",
|
|
23
23
|
name: "Starter",
|
|
24
24
|
slug: "starter-monthly",
|
|
25
|
-
|
|
25
|
+
unitPrice: "0.00",
|
|
26
26
|
currency: "USD",
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
pricingModel: "flat",
|
|
28
|
+
intervalUnit: "month",
|
|
29
|
+
intervalCount: 1,
|
|
30
|
+
intervalDisplay: "per month",
|
|
31
|
+
isRecurring: true,
|
|
32
|
+
isFree: true,
|
|
33
33
|
features: [
|
|
34
34
|
{ key: "seats", name: "Team seats", value: 1, limit: 1, category: "core" },
|
|
35
35
|
{ key: "projects", name: "Projects", value: 3, limit: 3, category: "core" },
|
|
36
36
|
],
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
isActive: true,
|
|
38
|
+
isFeatured: false,
|
|
39
|
+
trialDays: 0,
|
|
40
|
+
sortOrder: 0,
|
|
41
|
+
ctaText: "Start Free",
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
id: "offer-2",
|
|
45
45
|
name: "Pro",
|
|
46
46
|
slug: "pro-monthly",
|
|
47
|
-
|
|
47
|
+
unitPrice: "49.00",
|
|
48
48
|
currency: "USD",
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
pricingModel: "flat",
|
|
50
|
+
intervalUnit: "month",
|
|
51
|
+
intervalCount: 1,
|
|
52
|
+
intervalDisplay: "per month",
|
|
53
|
+
isRecurring: true,
|
|
54
|
+
isFree: false,
|
|
55
55
|
features: [
|
|
56
56
|
{ key: "seats", name: "Team seats", value: 5, limit: 5, category: "core" },
|
|
57
57
|
{ key: "projects", name: "Projects", value: "Unlimited", category: "core" },
|
|
58
58
|
],
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
isActive: true,
|
|
60
|
+
isFeatured: true,
|
|
61
|
+
trialDays: 14,
|
|
62
|
+
sortOrder: 1,
|
|
63
|
+
ctaText: "Start Trial",
|
|
64
64
|
},
|
|
65
65
|
],
|
|
66
66
|
};
|
|
@@ -140,7 +140,7 @@ describe("PricingDetailPage integration", () => {
|
|
|
140
140
|
id: "offer-1",
|
|
141
141
|
slug: "starter-monthly",
|
|
142
142
|
name: "Starter",
|
|
143
|
-
|
|
143
|
+
isFree: true,
|
|
144
144
|
})
|
|
145
145
|
);
|
|
146
146
|
});
|
|
@@ -172,8 +172,8 @@ describe("PricingDetailPage integration", () => {
|
|
|
172
172
|
id: "offer-2",
|
|
173
173
|
slug: "pro-monthly",
|
|
174
174
|
name: "Pro",
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
isFree: false,
|
|
176
|
+
unitPrice: "49.00",
|
|
177
177
|
})
|
|
178
178
|
);
|
|
179
179
|
});
|
|
@@ -26,73 +26,73 @@ const mockProduct: BillingProduct = {
|
|
|
26
26
|
id: "offer-1",
|
|
27
27
|
name: "Starter",
|
|
28
28
|
slug: "starter-monthly",
|
|
29
|
-
|
|
29
|
+
unitPrice: "0.00",
|
|
30
30
|
currency: "USD",
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
pricingModel: "flat",
|
|
32
|
+
intervalUnit: "month",
|
|
33
|
+
intervalCount: 1,
|
|
34
|
+
intervalDisplay: "per month",
|
|
35
|
+
isRecurring: true,
|
|
36
|
+
isFree: true,
|
|
37
37
|
features: [
|
|
38
38
|
{ key: "seats", name: "Team seats", value: 1, limit: 1, category: "core" },
|
|
39
39
|
{ key: "projects", name: "Projects", value: 3, limit: 3, category: "core" },
|
|
40
40
|
{ key: "email_support", name: "Email support", value: true, category: "support" },
|
|
41
41
|
{ key: "priority_support", name: "Priority support", value: false, category: "support" },
|
|
42
42
|
],
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
isActive: true,
|
|
44
|
+
isFeatured: false,
|
|
45
|
+
trialDays: 0,
|
|
46
|
+
sortOrder: 0,
|
|
47
|
+
ctaText: "Start Free",
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
id: "offer-2",
|
|
51
51
|
name: "Pro",
|
|
52
52
|
slug: "pro-monthly",
|
|
53
|
-
|
|
53
|
+
unitPrice: "49.00",
|
|
54
54
|
currency: "USD",
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
pricingModel: "flat",
|
|
56
|
+
intervalUnit: "month",
|
|
57
|
+
intervalCount: 1,
|
|
58
|
+
intervalDisplay: "per month",
|
|
59
|
+
isRecurring: true,
|
|
60
|
+
isFree: false,
|
|
61
61
|
features: [
|
|
62
62
|
{ key: "seats", name: "Team seats", value: 5, limit: 5, category: "core" },
|
|
63
63
|
{ key: "projects", name: "Projects", value: "Unlimited", category: "core" },
|
|
64
64
|
{ key: "email_support", name: "Email support", value: true, category: "support" },
|
|
65
65
|
{ key: "priority_support", name: "Priority support", value: true, category: "support" },
|
|
66
66
|
],
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
isActive: true,
|
|
68
|
+
isFeatured: true,
|
|
69
|
+
trialDays: 14,
|
|
70
|
+
sortOrder: 1,
|
|
71
|
+
ctaText: "Start Trial",
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
74
|
id: "offer-3",
|
|
75
75
|
name: "Enterprise",
|
|
76
76
|
slug: "enterprise-monthly",
|
|
77
|
-
|
|
77
|
+
unitPrice: "199.00",
|
|
78
78
|
currency: "USD",
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
pricingModel: "per_seat",
|
|
80
|
+
intervalUnit: "month",
|
|
81
|
+
intervalCount: 1,
|
|
82
|
+
intervalDisplay: "per month",
|
|
83
|
+
isRecurring: true,
|
|
84
|
+
isFree: false,
|
|
85
85
|
features: [
|
|
86
86
|
{ key: "seats", name: "Team seats", value: "Unlimited", category: "core" },
|
|
87
87
|
{ key: "projects", name: "Projects", value: "Unlimited", category: "core" },
|
|
88
88
|
{ key: "email_support", name: "Email support", value: true, category: "support" },
|
|
89
89
|
{ key: "priority_support", name: "Priority support", value: true, category: "support" },
|
|
90
90
|
],
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
isActive: true,
|
|
92
|
+
isFeatured: false,
|
|
93
|
+
trialDays: 0,
|
|
94
|
+
sortOrder: 2,
|
|
95
|
+
ctaText: "Contact Sales",
|
|
96
96
|
},
|
|
97
97
|
],
|
|
98
98
|
};
|
|
@@ -104,7 +104,7 @@ interface DetailCardProps {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
function DetailCard({ offer, onSelect }: DetailCardProps) {
|
|
107
|
-
const isFeatured = offer.
|
|
107
|
+
const isFeatured = offer.isFeatured;
|
|
108
108
|
|
|
109
109
|
return (
|
|
110
110
|
<div
|
|
@@ -126,23 +126,23 @@ function DetailCard({ offer, onSelect }: DetailCardProps) {
|
|
|
126
126
|
<h2 className="text-xl font-bold text-gray-900 mb-4">{offer.name}</h2>
|
|
127
127
|
|
|
128
128
|
<div className="mb-2">
|
|
129
|
-
{offer.
|
|
129
|
+
{offer.isFree ? (
|
|
130
130
|
<span aria-label="Free">
|
|
131
131
|
<span aria-hidden="true" className="text-4xl font-extrabold text-gray-900">Free</span>
|
|
132
132
|
</span>
|
|
133
133
|
) : (
|
|
134
|
-
<span aria-label={`${Math.floor(parseFloat(offer.
|
|
134
|
+
<span aria-label={`${Math.floor(parseFloat(offer.unitPrice) || 0)} dollars ${offer.intervalDisplay}`}>
|
|
135
135
|
<span aria-hidden="true" className="text-4xl font-extrabold text-gray-900">
|
|
136
|
-
${Math.floor(parseFloat(offer.
|
|
136
|
+
${Math.floor(parseFloat(offer.unitPrice) || 0)}
|
|
137
137
|
</span>
|
|
138
|
-
<span aria-hidden="true" className="text-base text-gray-500 ml-1"> {offer.
|
|
138
|
+
<span aria-hidden="true" className="text-base text-gray-500 ml-1"> {offer.intervalDisplay}</span>
|
|
139
139
|
</span>
|
|
140
140
|
)}
|
|
141
141
|
</div>
|
|
142
142
|
|
|
143
|
-
{offer.
|
|
143
|
+
{offer.trialDays > 0 && (
|
|
144
144
|
<span className="inline-block bg-blue-50 text-blue-700 text-sm font-semibold px-3 py-1 rounded-lg mb-5 w-fit">
|
|
145
|
-
{offer.
|
|
145
|
+
{offer.trialDays}-day free trial
|
|
146
146
|
</span>
|
|
147
147
|
)}
|
|
148
148
|
|
|
@@ -174,7 +174,7 @@ function DetailCard({ offer, onSelect }: DetailCardProps) {
|
|
|
174
174
|
}
|
|
175
175
|
`}
|
|
176
176
|
>
|
|
177
|
-
{offer.
|
|
177
|
+
{offer.ctaText}
|
|
178
178
|
</button>
|
|
179
179
|
</div>
|
|
180
180
|
);
|
|
@@ -25,67 +25,67 @@ const mockProduct: BillingProduct = {
|
|
|
25
25
|
id: "offer-1",
|
|
26
26
|
name: "Starter",
|
|
27
27
|
slug: "starter-monthly",
|
|
28
|
-
|
|
28
|
+
unitPrice: "0.00",
|
|
29
29
|
currency: "USD",
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
pricingModel: "flat",
|
|
31
|
+
intervalUnit: "month",
|
|
32
|
+
intervalCount: 1,
|
|
33
|
+
intervalDisplay: "per month",
|
|
34
|
+
isRecurring: true,
|
|
35
|
+
isFree: true,
|
|
36
36
|
features: [
|
|
37
37
|
{ key: "seats", name: "Team seats", value: 1, limit: 1 },
|
|
38
38
|
{ key: "projects", name: "Projects", value: 3, limit: 3 },
|
|
39
39
|
],
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
isActive: true,
|
|
41
|
+
isFeatured: false,
|
|
42
|
+
trialDays: 0,
|
|
43
|
+
sortOrder: 0,
|
|
44
|
+
ctaText: "Start Free",
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
47
|
id: "offer-2",
|
|
48
48
|
name: "Pro",
|
|
49
49
|
slug: "pro-monthly",
|
|
50
|
-
|
|
50
|
+
unitPrice: "49.00",
|
|
51
51
|
currency: "USD",
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
pricingModel: "flat",
|
|
53
|
+
intervalUnit: "month",
|
|
54
|
+
intervalCount: 1,
|
|
55
|
+
intervalDisplay: "per month",
|
|
56
|
+
isRecurring: true,
|
|
57
|
+
isFree: false,
|
|
58
58
|
features: [
|
|
59
59
|
{ key: "seats", name: "Team seats", value: 5, limit: 5 },
|
|
60
60
|
{ key: "projects", name: "Projects", value: "Unlimited" },
|
|
61
61
|
],
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
isActive: true,
|
|
63
|
+
isFeatured: true,
|
|
64
|
+
trialDays: 14,
|
|
65
|
+
sortOrder: 1,
|
|
66
|
+
ctaText: "Start Trial",
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
69
|
id: "offer-3",
|
|
70
70
|
name: "Enterprise",
|
|
71
71
|
slug: "enterprise-monthly",
|
|
72
|
-
|
|
72
|
+
unitPrice: "199.00",
|
|
73
73
|
currency: "USD",
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
pricingModel: "per_seat",
|
|
75
|
+
intervalUnit: "month",
|
|
76
|
+
intervalCount: 1,
|
|
77
|
+
intervalDisplay: "per month",
|
|
78
|
+
isRecurring: true,
|
|
79
|
+
isFree: false,
|
|
80
80
|
features: [
|
|
81
81
|
{ key: "seats", name: "Team seats", value: "Unlimited" },
|
|
82
82
|
{ key: "projects", name: "Projects", value: "Unlimited" },
|
|
83
83
|
],
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
isActive: true,
|
|
85
|
+
isFeatured: false,
|
|
86
|
+
trialDays: 0,
|
|
87
|
+
sortOrder: 2,
|
|
88
|
+
ctaText: "Contact Sales",
|
|
89
89
|
},
|
|
90
90
|
],
|
|
91
91
|
};
|
|
@@ -77,7 +77,7 @@ interface PricingCardProps {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
function PricingCard({ offer, onSelect }: PricingCardProps) {
|
|
80
|
-
const isFeatured = offer.
|
|
80
|
+
const isFeatured = offer.isFeatured;
|
|
81
81
|
|
|
82
82
|
return (
|
|
83
83
|
<div
|
|
@@ -100,24 +100,24 @@ function PricingCard({ offer, onSelect }: PricingCardProps) {
|
|
|
100
100
|
<h2 className="text-xl font-bold text-gray-900 mb-4">{offer.name}</h2>
|
|
101
101
|
|
|
102
102
|
<div className="mb-2">
|
|
103
|
-
{offer.
|
|
103
|
+
{offer.isFree ? (
|
|
104
104
|
<span className="text-4xl font-extrabold text-gray-900">Free</span>
|
|
105
105
|
) : (
|
|
106
106
|
<span>
|
|
107
107
|
<span className="text-4xl font-extrabold text-gray-900">
|
|
108
|
-
${Math.floor(parseFloat(offer.
|
|
108
|
+
${Math.floor(parseFloat(offer.unitPrice) || 0)}
|
|
109
109
|
</span>
|
|
110
|
-
<span className="text-base text-gray-500 ml-1"> {offer.
|
|
110
|
+
<span className="text-base text-gray-500 ml-1"> {offer.intervalDisplay}</span>
|
|
111
111
|
</span>
|
|
112
112
|
)}
|
|
113
113
|
</div>
|
|
114
114
|
|
|
115
|
-
{offer.
|
|
115
|
+
{offer.trialDays > 0 && (
|
|
116
116
|
<span
|
|
117
117
|
data-testid="trial-badge"
|
|
118
118
|
className="inline-block bg-blue-50 text-blue-700 text-sm font-semibold px-3 py-1 rounded-lg mb-5 w-fit"
|
|
119
119
|
>
|
|
120
|
-
{offer.
|
|
120
|
+
{offer.trialDays}-day free trial
|
|
121
121
|
</span>
|
|
122
122
|
)}
|
|
123
123
|
|
|
@@ -146,7 +146,7 @@ function PricingCard({ offer, onSelect }: PricingCardProps) {
|
|
|
146
146
|
}
|
|
147
147
|
`}
|
|
148
148
|
>
|
|
149
|
-
{offer.
|
|
149
|
+
{offer.ctaText}
|
|
150
150
|
</button>
|
|
151
151
|
</div>
|
|
152
152
|
);
|
|
@@ -25,14 +25,14 @@ const mockProduct: BillingProduct = {
|
|
|
25
25
|
id: "offer-1",
|
|
26
26
|
name: "Starter",
|
|
27
27
|
slug: "starter-monthly",
|
|
28
|
-
|
|
28
|
+
unitPrice: "0.00",
|
|
29
29
|
currency: "USD",
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
pricingModel: "flat",
|
|
31
|
+
intervalUnit: "month",
|
|
32
|
+
intervalCount: 1,
|
|
33
|
+
intervalDisplay: "per month",
|
|
34
|
+
isRecurring: true,
|
|
35
|
+
isFree: true,
|
|
36
36
|
features: [
|
|
37
37
|
{ key: "seats", name: "Team seats", value: 1, limit: 1 },
|
|
38
38
|
{ key: "projects", name: "Projects", value: 3, limit: 3 },
|
|
@@ -40,24 +40,24 @@ const mockProduct: BillingProduct = {
|
|
|
40
40
|
{ key: "support", name: "Support", value: "Email" },
|
|
41
41
|
{ key: "api", name: "API Access", value: "Limited" },
|
|
42
42
|
],
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
isActive: true,
|
|
44
|
+
isFeatured: false,
|
|
45
|
+
trialDays: 0,
|
|
46
|
+
sortOrder: 0,
|
|
47
|
+
ctaText: "Start Free",
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
id: "offer-2",
|
|
51
51
|
name: "Pro",
|
|
52
52
|
slug: "pro-monthly",
|
|
53
|
-
|
|
53
|
+
unitPrice: "49.00",
|
|
54
54
|
currency: "USD",
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
pricingModel: "flat",
|
|
56
|
+
intervalUnit: "month",
|
|
57
|
+
intervalCount: 1,
|
|
58
|
+
intervalDisplay: "per month",
|
|
59
|
+
isRecurring: true,
|
|
60
|
+
isFree: false,
|
|
61
61
|
features: [
|
|
62
62
|
{ key: "seats", name: "Team seats", value: 5, limit: 5 },
|
|
63
63
|
{ key: "projects", name: "Projects", value: "Unlimited" },
|
|
@@ -65,24 +65,24 @@ const mockProduct: BillingProduct = {
|
|
|
65
65
|
{ key: "support", name: "Support", value: "Priority" },
|
|
66
66
|
{ key: "api", name: "API Access", value: "Full" },
|
|
67
67
|
],
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
isActive: true,
|
|
69
|
+
isFeatured: true,
|
|
70
|
+
trialDays: 14,
|
|
71
|
+
sortOrder: 1,
|
|
72
|
+
ctaText: "Start Trial",
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
75
|
id: "offer-3",
|
|
76
76
|
name: "Enterprise",
|
|
77
77
|
slug: "enterprise-monthly",
|
|
78
|
-
|
|
78
|
+
unitPrice: "199.00",
|
|
79
79
|
currency: "USD",
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
pricingModel: "per_seat",
|
|
81
|
+
intervalUnit: "month",
|
|
82
|
+
intervalCount: 1,
|
|
83
|
+
intervalDisplay: "per month",
|
|
84
|
+
isRecurring: true,
|
|
85
|
+
isFree: false,
|
|
86
86
|
features: [
|
|
87
87
|
{ key: "seats", name: "Team seats", value: "Unlimited" },
|
|
88
88
|
{ key: "projects", name: "Projects", value: "Unlimited" },
|
|
@@ -91,11 +91,11 @@ const mockProduct: BillingProduct = {
|
|
|
91
91
|
{ key: "api", name: "API Access", value: "Full" },
|
|
92
92
|
{ key: "sla", name: "SLA", value: "99.9%" },
|
|
93
93
|
],
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
isActive: true,
|
|
95
|
+
isFeatured: false,
|
|
96
|
+
trialDays: 0,
|
|
97
|
+
sortOrder: 2,
|
|
98
|
+
ctaText: "Contact Sales",
|
|
99
99
|
},
|
|
100
100
|
],
|
|
101
101
|
};
|
|
@@ -77,7 +77,7 @@ interface SectionCardProps {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
function SectionCard({ offer, onSelect, maxFeatures }: SectionCardProps) {
|
|
80
|
-
const isFeatured = offer.
|
|
80
|
+
const isFeatured = offer.isFeatured;
|
|
81
81
|
const visibleFeatures = offer.features.slice(0, maxFeatures);
|
|
82
82
|
|
|
83
83
|
return (
|
|
@@ -95,24 +95,24 @@ function SectionCard({ offer, onSelect, maxFeatures }: SectionCardProps) {
|
|
|
95
95
|
<h3 className="text-lg font-bold text-gray-900 mb-2">{offer.name}</h3>
|
|
96
96
|
|
|
97
97
|
<div className="mb-2">
|
|
98
|
-
{offer.
|
|
98
|
+
{offer.isFree ? (
|
|
99
99
|
<span className="text-2xl font-extrabold text-gray-900">Free</span>
|
|
100
100
|
) : (
|
|
101
101
|
<span>
|
|
102
102
|
<span className="text-2xl font-extrabold text-gray-900">
|
|
103
|
-
${Math.floor(parseFloat(offer.
|
|
103
|
+
${Math.floor(parseFloat(offer.unitPrice) || 0)}
|
|
104
104
|
</span>
|
|
105
|
-
<span className="text-sm text-gray-500 ml-1"> {offer.
|
|
105
|
+
<span className="text-sm text-gray-500 ml-1"> {offer.intervalDisplay}</span>
|
|
106
106
|
</span>
|
|
107
107
|
)}
|
|
108
108
|
</div>
|
|
109
109
|
|
|
110
|
-
{offer.
|
|
110
|
+
{offer.trialDays > 0 && (
|
|
111
111
|
<span
|
|
112
112
|
data-testid="trial-badge"
|
|
113
113
|
className="inline-block bg-blue-50 text-blue-700 text-xs font-semibold px-2 py-0.5 rounded-md mb-3 w-fit"
|
|
114
114
|
>
|
|
115
|
-
{offer.
|
|
115
|
+
{offer.trialDays}-day free trial
|
|
116
116
|
</span>
|
|
117
117
|
)}
|
|
118
118
|
|
|
@@ -147,7 +147,7 @@ function SectionCard({ offer, onSelect, maxFeatures }: SectionCardProps) {
|
|
|
147
147
|
}
|
|
148
148
|
`}
|
|
149
149
|
>
|
|
150
|
-
{offer.
|
|
150
|
+
{offer.ctaText}
|
|
151
151
|
</button>
|
|
152
152
|
</div>
|
|
153
153
|
);
|
|
@@ -31,67 +31,67 @@ const mockProduct: BillingProduct = {
|
|
|
31
31
|
id: "offer-1",
|
|
32
32
|
name: "Starter",
|
|
33
33
|
slug: "starter-monthly",
|
|
34
|
-
|
|
34
|
+
unitPrice: "0.00",
|
|
35
35
|
currency: "USD",
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
pricingModel: "flat",
|
|
37
|
+
intervalUnit: "month",
|
|
38
|
+
intervalCount: 1,
|
|
39
|
+
intervalDisplay: "per month",
|
|
40
|
+
isRecurring: true,
|
|
41
|
+
isFree: true,
|
|
42
42
|
features: [
|
|
43
43
|
{ key: "seats", name: "Team seats", value: 1, limit: 1 },
|
|
44
44
|
{ key: "projects", name: "Projects", value: 3, limit: 3 },
|
|
45
45
|
],
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
isActive: true,
|
|
47
|
+
isFeatured: false,
|
|
48
|
+
trialDays: 0,
|
|
49
|
+
sortOrder: 0,
|
|
50
|
+
ctaText: "Start Free",
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
53
|
id: "offer-2",
|
|
54
54
|
name: "Pro",
|
|
55
55
|
slug: "pro-monthly",
|
|
56
|
-
|
|
56
|
+
unitPrice: "49.00",
|
|
57
57
|
currency: "USD",
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
pricingModel: "flat",
|
|
59
|
+
intervalUnit: "month",
|
|
60
|
+
intervalCount: 1,
|
|
61
|
+
intervalDisplay: "per month",
|
|
62
|
+
isRecurring: true,
|
|
63
|
+
isFree: false,
|
|
64
64
|
features: [
|
|
65
65
|
{ key: "seats", name: "Team seats", value: 5, limit: 5 },
|
|
66
66
|
{ key: "projects", name: "Projects", value: "Unlimited" },
|
|
67
67
|
],
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
isActive: true,
|
|
69
|
+
isFeatured: true,
|
|
70
|
+
trialDays: 14,
|
|
71
|
+
sortOrder: 1,
|
|
72
|
+
ctaText: "Start Trial",
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
75
|
id: "offer-3",
|
|
76
76
|
name: "Enterprise",
|
|
77
77
|
slug: "enterprise-monthly",
|
|
78
|
-
|
|
78
|
+
unitPrice: "199.00",
|
|
79
79
|
currency: "USD",
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
pricingModel: "per_seat",
|
|
81
|
+
intervalUnit: "month",
|
|
82
|
+
intervalCount: 1,
|
|
83
|
+
intervalDisplay: "per month",
|
|
84
|
+
isRecurring: true,
|
|
85
|
+
isFree: false,
|
|
86
86
|
features: [
|
|
87
87
|
{ key: "seats", name: "Team seats", value: "Unlimited" },
|
|
88
88
|
{ key: "projects", name: "Projects", value: "Unlimited" },
|
|
89
89
|
],
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
isActive: true,
|
|
91
|
+
isFeatured: false,
|
|
92
|
+
trialDays: 0,
|
|
93
|
+
sortOrder: 2,
|
|
94
|
+
ctaText: "Contact Sales",
|
|
95
95
|
},
|
|
96
96
|
],
|
|
97
97
|
};
|
|
@@ -100,40 +100,40 @@ const mockSubscriptionActive: SubscriptionInfo = {
|
|
|
100
100
|
id: "sub-123",
|
|
101
101
|
offer: mockProduct.offers[1], // Pro plan
|
|
102
102
|
status: "active",
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
currentPeriodStart: "2026-01-01T00:00:00Z",
|
|
104
|
+
currentPeriodEnd: "2026-02-01T00:00:00Z",
|
|
105
|
+
cancelAtPeriodEnd: false,
|
|
106
|
+
trialEnd: null,
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
const mockSubscriptionTrialing: SubscriptionInfo = {
|
|
110
110
|
id: "sub-456",
|
|
111
111
|
offer: mockProduct.offers[1], // Pro plan
|
|
112
112
|
status: "trialing",
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
currentPeriodStart: "2026-01-01T00:00:00Z",
|
|
114
|
+
currentPeriodEnd: "2026-02-01T00:00:00Z",
|
|
115
|
+
cancelAtPeriodEnd: false,
|
|
116
|
+
trialEnd: "2026-01-15T00:00:00Z",
|
|
117
117
|
};
|
|
118
118
|
|
|
119
119
|
const mockSubscriptionPastDue: SubscriptionInfo = {
|
|
120
120
|
id: "sub-789",
|
|
121
121
|
offer: mockProduct.offers[1], // Pro plan
|
|
122
122
|
status: "past_due",
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
currentPeriodStart: "2026-01-01T00:00:00Z",
|
|
124
|
+
currentPeriodEnd: "2026-02-01T00:00:00Z",
|
|
125
|
+
cancelAtPeriodEnd: false,
|
|
126
|
+
trialEnd: null,
|
|
127
127
|
};
|
|
128
128
|
|
|
129
129
|
const mockSubscriptionCancelled: SubscriptionInfo = {
|
|
130
130
|
id: "sub-999",
|
|
131
131
|
offer: mockProduct.offers[1], // Pro plan
|
|
132
132
|
status: "cancelled",
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
currentPeriodStart: "2026-01-01T00:00:00Z",
|
|
134
|
+
currentPeriodEnd: "2026-02-01T00:00:00Z",
|
|
135
|
+
cancelAtPeriodEnd: true,
|
|
136
|
+
trialEnd: null,
|
|
137
137
|
};
|
|
138
138
|
|
|
139
139
|
function createWrapper(fetcher: typeof fetch) {
|
|
@@ -495,15 +495,15 @@ describe("SubscriptionManager", () => {
|
|
|
495
495
|
expect(statusBadge.className).toMatch(/warning|error|danger|alert/i);
|
|
496
496
|
});
|
|
497
497
|
|
|
498
|
-
it("does not crash when
|
|
498
|
+
it("does not crash when currentPeriodEnd is null (free plan)", async () => {
|
|
499
499
|
const freeSubscription: SubscriptionInfo = {
|
|
500
500
|
id: "sub-free",
|
|
501
|
-
offer: { ...mockProduct.offers[0],
|
|
501
|
+
offer: { ...mockProduct.offers[0], isFree: true },
|
|
502
502
|
status: "active",
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
503
|
+
currentPeriodStart: null,
|
|
504
|
+
currentPeriodEnd: null,
|
|
505
|
+
cancelAtPeriodEnd: false,
|
|
506
|
+
trialEnd: null,
|
|
507
507
|
};
|
|
508
508
|
const fetcher = mockFetchRouter({
|
|
509
509
|
"/billing/subscription/current/": freeSubscription,
|
|
@@ -167,30 +167,30 @@ export function SubscriptionManager({
|
|
|
167
167
|
<div data-testid="current-plan" className="rounded-2xl border border-gray-200 bg-white shadow-sm p-8">
|
|
168
168
|
<div className="flex items-center justify-between mb-4">
|
|
169
169
|
<h2 className="text-xl font-bold text-gray-900">{subscription.offer.name}</h2>
|
|
170
|
-
<StatusBadge status={subscription.status} trialEnd={subscription.
|
|
170
|
+
<StatusBadge status={subscription.status} trialEnd={subscription.trialEnd} />
|
|
171
171
|
</div>
|
|
172
172
|
|
|
173
173
|
<div className="mb-4">
|
|
174
|
-
{subscription.offer.
|
|
174
|
+
{subscription.offer.isFree ? (
|
|
175
175
|
<span aria-label="Free">
|
|
176
176
|
<span aria-hidden="true" className="text-3xl font-extrabold text-gray-900">Free</span>
|
|
177
177
|
</span>
|
|
178
178
|
) : (
|
|
179
|
-
<span aria-label={`${Math.floor(parseFloat(subscription.offer.
|
|
179
|
+
<span aria-label={`${Math.floor(parseFloat(subscription.offer.unitPrice) || 0)} dollars ${subscription.offer.intervalDisplay}`}>
|
|
180
180
|
<span aria-hidden="true" className="text-3xl font-extrabold text-gray-900">
|
|
181
|
-
${Math.floor(parseFloat(subscription.offer.
|
|
181
|
+
${Math.floor(parseFloat(subscription.offer.unitPrice) || 0)}
|
|
182
182
|
</span>
|
|
183
183
|
<span aria-hidden="true" className="text-base text-gray-500 ml-1">
|
|
184
|
-
{subscription.offer.
|
|
184
|
+
{subscription.offer.intervalDisplay}
|
|
185
185
|
</span>
|
|
186
186
|
</span>
|
|
187
187
|
)}
|
|
188
188
|
</div>
|
|
189
189
|
|
|
190
|
-
{subscription.
|
|
190
|
+
{subscription.currentPeriodStart && subscription.currentPeriodEnd && (
|
|
191
191
|
<p className="text-sm text-gray-500">
|
|
192
|
-
Billing period: {formatDate(subscription.
|
|
193
|
-
{formatDate(subscription.
|
|
192
|
+
Billing period: {formatDate(subscription.currentPeriodStart)} to{" "}
|
|
193
|
+
{formatDate(subscription.currentPeriodEnd)}
|
|
194
194
|
</p>
|
|
195
195
|
)}
|
|
196
196
|
</div>
|
|
@@ -211,24 +211,24 @@ export function SubscriptionManager({
|
|
|
211
211
|
<div
|
|
212
212
|
key={offer.id}
|
|
213
213
|
className={`rounded-xl border p-6 ${
|
|
214
|
-
offer.
|
|
214
|
+
offer.isFeatured
|
|
215
215
|
? "border-blue-600 shadow-md"
|
|
216
216
|
: "border-gray-200 bg-white shadow-sm"
|
|
217
217
|
}`}
|
|
218
218
|
>
|
|
219
219
|
<h4 className="text-lg font-bold text-gray-900 mb-2">{offer.name}</h4>
|
|
220
220
|
<div className="mb-3">
|
|
221
|
-
{offer.
|
|
221
|
+
{offer.isFree ? (
|
|
222
222
|
<span aria-label="Free">
|
|
223
223
|
<span aria-hidden="true" className="text-2xl font-extrabold text-gray-900">Free</span>
|
|
224
224
|
</span>
|
|
225
225
|
) : (
|
|
226
|
-
<span aria-label={`${Math.floor(parseFloat(offer.
|
|
226
|
+
<span aria-label={`${Math.floor(parseFloat(offer.unitPrice) || 0)} dollars ${offer.intervalDisplay}`}>
|
|
227
227
|
<span aria-hidden="true" className="text-2xl font-extrabold text-gray-900">
|
|
228
|
-
${Math.floor(parseFloat(offer.
|
|
228
|
+
${Math.floor(parseFloat(offer.unitPrice) || 0)}
|
|
229
229
|
</span>
|
|
230
230
|
<span aria-hidden="true" className="text-sm text-gray-500 ml-1">
|
|
231
|
-
{offer.
|
|
231
|
+
{offer.intervalDisplay}
|
|
232
232
|
</span>
|
|
233
233
|
</span>
|
|
234
234
|
)}
|
|
@@ -237,12 +237,12 @@ export function SubscriptionManager({
|
|
|
237
237
|
data-testid={`upgrade-cta-${offer.slug}`}
|
|
238
238
|
onClick={() => onPlanChange?.(offer)}
|
|
239
239
|
className={`w-full py-2.5 px-4 text-sm font-bold rounded-xl cursor-pointer transition-colors ${
|
|
240
|
-
offer.
|
|
240
|
+
offer.isFeatured
|
|
241
241
|
? "bg-blue-600 text-white hover:bg-blue-700"
|
|
242
242
|
: "bg-gray-100 text-gray-800 hover:bg-gray-200"
|
|
243
243
|
}`}
|
|
244
244
|
>
|
|
245
|
-
{offer.
|
|
245
|
+
{offer.ctaText}
|
|
246
246
|
</button>
|
|
247
247
|
</div>
|
|
248
248
|
))}
|
|
@@ -30,20 +30,20 @@ const mockProduct: BillingProduct = {
|
|
|
30
30
|
id: "offer-1",
|
|
31
31
|
name: "Pro",
|
|
32
32
|
slug: "pro-monthly",
|
|
33
|
-
|
|
33
|
+
unitPrice: "49.00",
|
|
34
34
|
currency: "USD",
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
pricingModel: "flat",
|
|
36
|
+
intervalUnit: "month",
|
|
37
|
+
intervalCount: 1,
|
|
38
|
+
intervalDisplay: "per month",
|
|
39
|
+
isRecurring: true,
|
|
40
|
+
isFree: false,
|
|
41
41
|
features: [{ key: "seats", name: "Team seats", value: 5, limit: 5 }],
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
isActive: true,
|
|
43
|
+
isFeatured: true,
|
|
44
|
+
trialDays: 14,
|
|
45
|
+
sortOrder: 0,
|
|
46
|
+
ctaText: "Upgrade to Pro",
|
|
47
47
|
},
|
|
48
48
|
],
|
|
49
49
|
};
|
|
@@ -122,7 +122,7 @@ export function UpgradeModal({
|
|
|
122
122
|
{product && (
|
|
123
123
|
<div data-testid="upgrade-offers" className="flex flex-wrap justify-center gap-5">
|
|
124
124
|
{product.offers.map((offer) => {
|
|
125
|
-
const isFeatured = offer.
|
|
125
|
+
const isFeatured = offer.isFeatured;
|
|
126
126
|
return (
|
|
127
127
|
<div
|
|
128
128
|
key={offer.id}
|
|
@@ -138,23 +138,23 @@ export function UpgradeModal({
|
|
|
138
138
|
<h3 className="text-lg font-bold text-gray-900 mb-2">{offer.name}</h3>
|
|
139
139
|
|
|
140
140
|
<div className="mb-2">
|
|
141
|
-
{offer.
|
|
141
|
+
{offer.isFree ? (
|
|
142
142
|
<span aria-label="Free">
|
|
143
143
|
<span aria-hidden="true" className="text-2xl font-extrabold text-gray-900">Free</span>
|
|
144
144
|
</span>
|
|
145
145
|
) : (
|
|
146
|
-
<span aria-label={`${Math.floor(parseFloat(offer.
|
|
146
|
+
<span aria-label={`${Math.floor(parseFloat(offer.unitPrice) || 0)} dollars ${offer.intervalDisplay}`}>
|
|
147
147
|
<span aria-hidden="true" className="text-2xl font-extrabold text-gray-900">
|
|
148
|
-
${Math.floor(parseFloat(offer.
|
|
148
|
+
${Math.floor(parseFloat(offer.unitPrice) || 0)}
|
|
149
149
|
</span>
|
|
150
|
-
<span aria-hidden="true" className="text-sm text-gray-500"> {offer.
|
|
150
|
+
<span aria-hidden="true" className="text-sm text-gray-500"> {offer.intervalDisplay}</span>
|
|
151
151
|
</span>
|
|
152
152
|
)}
|
|
153
153
|
</div>
|
|
154
154
|
|
|
155
|
-
{offer.
|
|
155
|
+
{offer.trialDays > 0 && (
|
|
156
156
|
<span className="inline-block bg-blue-50 text-blue-700 text-xs font-semibold px-2.5 py-0.5 rounded-md mb-3 w-fit">
|
|
157
|
-
{offer.
|
|
157
|
+
{offer.trialDays}-day free trial
|
|
158
158
|
</span>
|
|
159
159
|
)}
|
|
160
160
|
|
|
@@ -182,7 +182,7 @@ export function UpgradeModal({
|
|
|
182
182
|
}
|
|
183
183
|
`}
|
|
184
184
|
>
|
|
185
|
-
{offer.
|
|
185
|
+
{offer.ctaText}
|
|
186
186
|
</button>
|
|
187
187
|
</div>
|
|
188
188
|
);
|
|
@@ -23,7 +23,7 @@ describe("useCheckout", () => {
|
|
|
23
23
|
ok: true,
|
|
24
24
|
json: () =>
|
|
25
25
|
Promise.resolve({
|
|
26
|
-
|
|
26
|
+
sessionId: "cs_test_123",
|
|
27
27
|
url: "https://checkout.stripe.com/test",
|
|
28
28
|
}),
|
|
29
29
|
});
|
|
@@ -41,7 +41,7 @@ describe("useCheckout", () => {
|
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
expect(checkoutResult).toEqual({
|
|
44
|
-
|
|
44
|
+
sessionId: "cs_test_123",
|
|
45
45
|
url: "https://checkout.stripe.com/test",
|
|
46
46
|
});
|
|
47
47
|
expect(result.current.loading).toBe(false);
|
|
@@ -63,7 +63,7 @@ describe("useCheckout", () => {
|
|
|
63
63
|
const mockFetch = vi.fn().mockResolvedValue({
|
|
64
64
|
ok: true,
|
|
65
65
|
json: () =>
|
|
66
|
-
Promise.resolve({
|
|
66
|
+
Promise.resolve({ sessionId: "cs_1", url: "https://test.com" }),
|
|
67
67
|
});
|
|
68
68
|
const wrapper = createWrapper(mockFetch as unknown as typeof fetch);
|
|
69
69
|
|
|
@@ -120,7 +120,7 @@ describe("useCheckout", () => {
|
|
|
120
120
|
ok: true,
|
|
121
121
|
json: () =>
|
|
122
122
|
Promise.resolve({
|
|
123
|
-
|
|
123
|
+
sessionId: "cs_redirect_1",
|
|
124
124
|
url: "https://checkout.stripe.com/pay/cs_redirect_1",
|
|
125
125
|
}),
|
|
126
126
|
});
|
|
@@ -148,7 +148,7 @@ describe("useCheckout", () => {
|
|
|
148
148
|
ok: true,
|
|
149
149
|
json: () =>
|
|
150
150
|
Promise.resolve({
|
|
151
|
-
|
|
151
|
+
subscriptionId: "sub_free_123",
|
|
152
152
|
status: "active",
|
|
153
153
|
}),
|
|
154
154
|
});
|
|
@@ -162,7 +162,7 @@ describe("useCheckout", () => {
|
|
|
162
162
|
});
|
|
163
163
|
|
|
164
164
|
expect(freeResult).toEqual({
|
|
165
|
-
|
|
165
|
+
subscriptionId: "sub_free_123",
|
|
166
166
|
status: "active",
|
|
167
167
|
});
|
|
168
168
|
expect(result.current.loading).toBe(false);
|
|
@@ -15,39 +15,39 @@ const mockProduct: BillingProduct = {
|
|
|
15
15
|
id: "offer-1",
|
|
16
16
|
name: "Starter",
|
|
17
17
|
slug: "starter-monthly",
|
|
18
|
-
|
|
18
|
+
unitPrice: "0.00",
|
|
19
19
|
currency: "USD",
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
pricingModel: "flat",
|
|
21
|
+
intervalUnit: "month",
|
|
22
|
+
intervalCount: 1,
|
|
23
|
+
intervalDisplay: "per month",
|
|
24
|
+
isRecurring: true,
|
|
25
|
+
isFree: true,
|
|
26
26
|
features: [],
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
isActive: true,
|
|
28
|
+
isFeatured: false,
|
|
29
|
+
trialDays: 0,
|
|
30
|
+
sortOrder: 0,
|
|
31
|
+
ctaText: "Start Free",
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
34
|
id: "offer-2",
|
|
35
35
|
name: "Pro",
|
|
36
36
|
slug: "pro-monthly",
|
|
37
|
-
|
|
37
|
+
unitPrice: "49.00",
|
|
38
38
|
currency: "USD",
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
pricingModel: "flat",
|
|
40
|
+
intervalUnit: "month",
|
|
41
|
+
intervalCount: 1,
|
|
42
|
+
intervalDisplay: "per month",
|
|
43
|
+
isRecurring: true,
|
|
44
|
+
isFree: false,
|
|
45
45
|
features: [{ key: "seats", name: "Team seats", value: 5, limit: 5 }],
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
isActive: true,
|
|
47
|
+
isFeatured: true,
|
|
48
|
+
trialDays: 14,
|
|
49
|
+
sortOrder: 1,
|
|
50
|
+
ctaText: "Start Trial",
|
|
51
51
|
},
|
|
52
52
|
],
|
|
53
53
|
};
|
|
@@ -9,30 +9,30 @@ const mockOffer: ProductOffer = {
|
|
|
9
9
|
id: "offer-2",
|
|
10
10
|
name: "Pro",
|
|
11
11
|
slug: "pro-monthly",
|
|
12
|
-
|
|
12
|
+
unitPrice: "49.00",
|
|
13
13
|
currency: "USD",
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
pricingModel: "flat",
|
|
15
|
+
intervalUnit: "month",
|
|
16
|
+
intervalCount: 1,
|
|
17
|
+
intervalDisplay: "per month",
|
|
18
|
+
isRecurring: true,
|
|
19
|
+
isFree: false,
|
|
20
20
|
features: [{ key: "seats", name: "Team seats", value: 5, limit: 5 }],
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
isActive: true,
|
|
22
|
+
isFeatured: true,
|
|
23
|
+
trialDays: 14,
|
|
24
|
+
sortOrder: 1,
|
|
25
|
+
ctaText: "Start Trial",
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
const mockSubscription: SubscriptionInfo = {
|
|
29
29
|
id: "sub-123",
|
|
30
30
|
offer: mockOffer,
|
|
31
31
|
status: "active",
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
currentPeriodStart: "2026-01-01T00:00:00Z",
|
|
33
|
+
currentPeriodEnd: "2026-02-01T00:00:00Z",
|
|
34
|
+
cancelAtPeriodEnd: false,
|
|
35
|
+
trialEnd: null,
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
function createWrapper(fetcher: typeof fetch) {
|
package/src/types/index.ts
CHANGED
|
@@ -9,20 +9,20 @@ export interface ProductOffer {
|
|
|
9
9
|
id: string;
|
|
10
10
|
name: string;
|
|
11
11
|
slug: string;
|
|
12
|
-
|
|
12
|
+
unitPrice: string; // Decimal as string from DRF
|
|
13
13
|
currency: string;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
pricingModel: "flat" | "per_seat" | "tiered" | "volume" | "usage";
|
|
15
|
+
intervalUnit: "day" | "week" | "month" | "year" | null;
|
|
16
|
+
intervalCount: number | null;
|
|
17
|
+
intervalDisplay: string;
|
|
18
|
+
isRecurring: boolean;
|
|
19
|
+
isFree: boolean;
|
|
20
20
|
features: OfferFeature[];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
isActive: boolean;
|
|
22
|
+
isFeatured: boolean;
|
|
23
|
+
trialDays: number;
|
|
24
|
+
sortOrder: number;
|
|
25
|
+
ctaText: string;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export interface OfferFeature {
|
|
@@ -43,12 +43,12 @@ export interface BillingProduct {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export interface CheckoutResult {
|
|
46
|
-
|
|
46
|
+
sessionId: string;
|
|
47
47
|
url: string;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export interface FreeSubscriptionResult {
|
|
51
|
-
|
|
51
|
+
subscriptionId: string;
|
|
52
52
|
status: string;
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -60,10 +60,10 @@ export interface SubscriptionInfo {
|
|
|
60
60
|
id: string;
|
|
61
61
|
offer: ProductOffer;
|
|
62
62
|
status: "active" | "trialing" | "past_due" | "cancelled" | "incomplete" | "incomplete_expired" | "unpaid";
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
currentPeriodStart: string | null;
|
|
64
|
+
currentPeriodEnd: string | null;
|
|
65
|
+
cancelAtPeriodEnd: boolean;
|
|
66
|
+
trialEnd: string | null;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export interface PaymentMethod {
|
|
@@ -72,19 +72,19 @@ export interface PaymentMethod {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export interface CachedSubscriptionState {
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
subscriptionId: string | null;
|
|
76
|
+
providerSubscriptionId: string | null;
|
|
77
77
|
status: string;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
78
|
+
customerId: string | null;
|
|
79
|
+
priceId: string | null;
|
|
80
|
+
offerId: string | null;
|
|
81
|
+
productSlug: string | null;
|
|
82
|
+
offerSlug: string | null;
|
|
83
|
+
currentPeriodStart: number | null;
|
|
84
|
+
currentPeriodEnd: number | null;
|
|
85
|
+
cancelAtPeriodEnd: boolean;
|
|
86
|
+
trialEnd: number | null;
|
|
87
|
+
paymentMethod: PaymentMethod | null;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
export interface BillingConfig {
|
package/src/utils/api.test.ts
CHANGED
|
@@ -49,7 +49,7 @@ describe("BillingApiClient", () => {
|
|
|
49
49
|
mockFetch.mockResolvedValue({
|
|
50
50
|
ok: true,
|
|
51
51
|
json: () =>
|
|
52
|
-
Promise.resolve({
|
|
52
|
+
Promise.resolve({ sessionId: "cs_1", url: "https://pay.com" }),
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
const client = createClient();
|
|
@@ -59,7 +59,7 @@ describe("BillingApiClient", () => {
|
|
|
59
59
|
cancelUrl: "https://nope.com",
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
expect(result.
|
|
62
|
+
expect(result.sessionId).toBe("cs_1");
|
|
63
63
|
expect(mockFetch).toHaveBeenCalledWith(
|
|
64
64
|
"/api/billing/offer-checkout/",
|
|
65
65
|
expect.objectContaining({
|
|
@@ -75,7 +75,7 @@ describe("BillingApiClient", () => {
|
|
|
75
75
|
mockFetch.mockResolvedValue({
|
|
76
76
|
ok: true,
|
|
77
77
|
json: () =>
|
|
78
|
-
Promise.resolve({
|
|
78
|
+
Promise.resolve({ sessionId: "cs_1", url: "https://pay.com" }),
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
const client = createClient();
|