Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 8f731e4

Browse files
feat: offering plans (#832)
1 parent 9648d67 commit 8f731e4

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-8
lines changed

src/endpoints/subscription-offerings.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,32 @@ class SubscriptionOfferingsEndpoint extends CRUDExtend {
3030
})
3131
}
3232

33+
AttachProducts(offeringId, body) {
34+
return this.request.send(`${this.endpoint}/${offeringId}/products/attach`, 'POST', {
35+
...body
36+
})
37+
}
38+
39+
RemoveProduct(offeringId, productId) {
40+
return this.request.send(`${this.endpoint}/${offeringId}/products/${productId}`, 'DELETE')
41+
}
42+
43+
AttachPlans(offeringId, body) {
44+
return this.request.send(`${this.endpoint}/${offeringId}/plans/attach`, 'POST', {
45+
...body
46+
})
47+
}
48+
49+
RemovePlan(offeringId, planId) {
50+
return this.request.send(`${this.endpoint}/${offeringId}/plans/${planId}`, 'DELETE')
51+
}
52+
3353
GetAttachedProducts(id) {
3454
return this.request.send(`${this.endpoint}/${id}/products`, 'GET')
3555
}
3656

3757
GetAttachedPlans(id) {
38-
return this.request.send(`${this.endpoint}/${id}/products`, 'GET')
58+
return this.request.send(`${this.endpoint}/${id}/plans`, 'GET')
3959
}
4060

4161
}

src/types/subscription-offerings.d.ts

+31-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,33 @@ export interface SubscriptionOfferingBuildBody {
4444
plans: string[]
4545
}
4646

47+
export interface SubscriptionOfferingAttachProductBody {
48+
products: string[]
49+
}
50+
51+
export interface SubscriptionOfferingAttachPlanBody {
52+
plans: string[]
53+
}
54+
4755
export interface SubscriptionOffering extends Identifiable, SubscriptionOfferingBase {
4856

4957
}
5058
export type SubscriptionOfferingCreate = Omit<SubscriptionOfferingBase, 'attributes'> & {attributes: Partial<SubscriptionOfferingBase['attributes']>}
5159
export type SubscriptionOfferingUpdate = Omit<SubscriptionOffering, 'attributes'> & {attributes: Partial<SubscriptionOfferingBase['attributes']>}
5260

61+
type SubscriptionOfferingAttachmentsRelationships = {
62+
relationships: {
63+
origin: {
64+
data: {
65+
id: string,
66+
type: string
67+
}
68+
}
69+
}
70+
}
71+
72+
export type SubscriptionOfferingPlan = SubscriptionPlan & SubscriptionOfferingAttachmentsRelationships
73+
export type SubscriptionOfferingProduct = SubscriptionProduct & SubscriptionOfferingAttachmentsRelationships
5374
/**
5475
* Subscription Offering Endpoints
5576
* DOCS: TODO: add docs when ready
@@ -67,7 +88,15 @@ export interface SubscriptionOfferingsEndpoint
6788

6889
Build(body: SubscriptionOfferingBuildBody): Promise<Resource<SubscriptionOffering>>
6990

70-
GetAttachedProducts(id: string) : Promise<Resource<SubscriptionProduct[]>>
91+
GetAttachedProducts(id: string) : Promise<Resource<SubscriptionOfferingProduct[]>>
92+
93+
GetAttachedPlans(id: string) : Promise<Resource<SubscriptionOfferingPlan[]>>
94+
95+
AttachProducts(offeringId: string, body: SubscriptionOfferingAttachProductBody): Promise<Resource<SubscriptionProduct[]>>
96+
97+
RemoveProduct(offeringId: string, productId: string): Promise<void>
98+
99+
AttachPlans(offeringId: string, body: SubscriptionOfferingAttachPlanBody): Promise<Resource<SubscriptionPlan[]>>
71100

72-
GetAttachedPlans(id: string) : Promise<Resource<SubscriptionPlan[]>>
101+
RemovePlan(offeringId: string, planId: string): Promise<void>
73102
}

src/types/subscription-plans.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ export interface SubscriptionPlanBase {
1717
type: string
1818
attributes: {
1919
name: string,
20-
description: string,
20+
description?: string,
2121
status: string,
2222
billing_interval_type: string,
2323
billing_frequency: number,
24-
billing_day: number,
25-
billing_month_day: number,
26-
trial_period: number,
24+
billing_day?: number,
25+
billing_month_day?: number,
26+
trial_period?: number,
2727
plan_length: number,
2828
end_behavior: string,
2929
can_pause: boolean,

src/types/subscription-products.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface SubscriptionProductBase {
1818
attributes: {
1919
created_at: string
2020
description: string
21-
main_image: string | null
21+
main_image?: string | null
2222
name: string
2323
sku: string
2424
updated_at: string

0 commit comments

Comments
 (0)