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

Commit

Permalink
feat: offering plans (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
rostyk-kanafotskyy authored Jul 18, 2023
1 parent 9648d67 commit 8f731e4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
22 changes: 21 additions & 1 deletion src/endpoints/subscription-offerings.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,32 @@ class SubscriptionOfferingsEndpoint extends CRUDExtend {
})
}

AttachProducts(offeringId, body) {
return this.request.send(`${this.endpoint}/${offeringId}/products/attach`, 'POST', {
...body
})
}

RemoveProduct(offeringId, productId) {
return this.request.send(`${this.endpoint}/${offeringId}/products/${productId}`, 'DELETE')
}

AttachPlans(offeringId, body) {
return this.request.send(`${this.endpoint}/${offeringId}/plans/attach`, 'POST', {
...body
})
}

RemovePlan(offeringId, planId) {
return this.request.send(`${this.endpoint}/${offeringId}/plans/${planId}`, 'DELETE')
}

GetAttachedProducts(id) {
return this.request.send(`${this.endpoint}/${id}/products`, 'GET')
}

GetAttachedPlans(id) {
return this.request.send(`${this.endpoint}/${id}/products`, 'GET')
return this.request.send(`${this.endpoint}/${id}/plans`, 'GET')
}

}
Expand Down
33 changes: 31 additions & 2 deletions src/types/subscription-offerings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,33 @@ export interface SubscriptionOfferingBuildBody {
plans: string[]
}

export interface SubscriptionOfferingAttachProductBody {
products: string[]
}

export interface SubscriptionOfferingAttachPlanBody {
plans: string[]
}

export interface SubscriptionOffering extends Identifiable, SubscriptionOfferingBase {

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

type SubscriptionOfferingAttachmentsRelationships = {
relationships: {
origin: {
data: {
id: string,
type: string
}
}
}
}

export type SubscriptionOfferingPlan = SubscriptionPlan & SubscriptionOfferingAttachmentsRelationships
export type SubscriptionOfferingProduct = SubscriptionProduct & SubscriptionOfferingAttachmentsRelationships
/**
* Subscription Offering Endpoints
* DOCS: TODO: add docs when ready
Expand All @@ -67,7 +88,15 @@ export interface SubscriptionOfferingsEndpoint

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

GetAttachedProducts(id: string) : Promise<Resource<SubscriptionProduct[]>>
GetAttachedProducts(id: string) : Promise<Resource<SubscriptionOfferingProduct[]>>

GetAttachedPlans(id: string) : Promise<Resource<SubscriptionOfferingPlan[]>>

AttachProducts(offeringId: string, body: SubscriptionOfferingAttachProductBody): Promise<Resource<SubscriptionProduct[]>>

RemoveProduct(offeringId: string, productId: string): Promise<void>

AttachPlans(offeringId: string, body: SubscriptionOfferingAttachPlanBody): Promise<Resource<SubscriptionPlan[]>>

GetAttachedPlans(id: string) : Promise<Resource<SubscriptionPlan[]>>
RemovePlan(offeringId: string, planId: string): Promise<void>
}
8 changes: 4 additions & 4 deletions src/types/subscription-plans.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export interface SubscriptionPlanBase {
type: string
attributes: {
name: string,
description: string,
description?: string,
status: string,
billing_interval_type: string,
billing_frequency: number,
billing_day: number,
billing_month_day: number,
trial_period: number,
billing_day?: number,
billing_month_day?: number,
trial_period?: number,
plan_length: number,
end_behavior: string,
can_pause: boolean,
Expand Down
2 changes: 1 addition & 1 deletion src/types/subscription-products.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface SubscriptionProductBase {
attributes: {
created_at: string
description: string
main_image: string | null
main_image?: string | null
name: string
sku: string
updated_at: string
Expand Down

0 comments on commit 8f731e4

Please sign in to comment.