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

Commit

Permalink
feat: added subscription dunning rules endpoint (#935)
Browse files Browse the repository at this point in the history
  • Loading branch information
rostyk-kanafotskyy authored Jun 13, 2024
1 parent 0de13d7 commit 695c1a0
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/endpoints/subscription-dunning-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import CRUDExtend from '../extends/crud'

class SubscriptionDunningRulesEndpoint extends CRUDExtend {
constructor(endpoint) {
super(endpoint)

this.endpoint = 'subscriptions/dunning-rules'
}

Create(body) {
return this.request.send(this.endpoint, 'POST', {
...body
})
}

Update(id, body, token = null) {
return this.request.send(
`${this.endpoint}/${id}`,
'PUT',
{
...body
},
token
)
}

}

export default SubscriptionDunningRulesEndpoint
3 changes: 3 additions & 0 deletions src/moltin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { SubscriptionSubscribersEndpoint } from './types/subscription-subscriber
import { SubscriptionJobsEndpoint } from './types/subscription-jobs'
import { SubscriptionSchedulesEndpoint } from './types/subscription-schedules'
import { CustomApisEndpoint } from './types/custom-apis'
import { SubscriptionDunningRulesEndpoint } from './types/subscription-dunning-rules'

export * from './types/config'
export * from './types/storage'
Expand Down Expand Up @@ -140,6 +141,7 @@ export * from './types/subscription-subscribers'
export * from './types/subscription-jobs'
export * from './types/subscription-schedules'
export * from './types/custom-apis'
export * from './types/subscription-dunning-rules'

// UMD
export as namespace moltin
Expand Down Expand Up @@ -206,6 +208,7 @@ export class Moltin {
SubscriptionJobs : SubscriptionJobsEndpoint
SubscriptionSchedules: SubscriptionSchedulesEndpoint
CustomApis: CustomApisEndpoint
SubscriptionDunningRules: SubscriptionDunningRulesEndpoint

Cart(id?: string): CartEndpoint // This optional cart id is super worrying when using the SDK in a node server :/
constructor(config: Config)
Expand Down
2 changes: 2 additions & 0 deletions src/moltin.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import RulePromotionsEndpoint from './endpoints/rule-promotions'
import SubscriptionSubscribersEndpoint from './endpoints/subscription-subscribers'
import SubscriptionJobsEndpoint from './endpoints/subscription-jobs'
import SubscriptionSchedulesEndpoint from './endpoints/subscription-schedules'
import SubscriptionDunningRulesEndpoint from './endpoints/subscription-dunning-rules'

import {cartIdentifier, tokenInvalid, getCredentials, resolveCredentialsStorageKey} from './utils/helpers'
import CatalogsEndpoint from './endpoints/catalogs'
Expand Down Expand Up @@ -132,6 +133,7 @@ export default class Moltin {
this.SubscriptionJobs = new SubscriptionJobsEndpoint(config)
this.SubscriptionSchedules = new SubscriptionSchedulesEndpoint(config)
this.CustomApis = new CustomApisEndpoint(config)
this.SubscriptionDunningRules = new SubscriptionDunningRulesEndpoint(config)
}

// Expose `Cart` class on Moltin class
Expand Down
56 changes: 56 additions & 0 deletions src/types/subscription-dunning-rules.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Subscription Dunning Rules
* Description: Subscription Dunning Rules.
* DOCS: TODO: add docs when ready
*/
import {
Identifiable,
CrudQueryableResource
} from './core'

/**
* Core Subscription Dunning Rules Base Interface
* For custom flows, extend this interface
* DOCS: TODO: add docs when ready
*/
export interface SubscriptionDunningRulesBase {
type: 'subscription_dunning_rule'
attributes: {
payment_retry_type: 'fixed' | 'backoff' | 'tiered'
payment_retry_interval?: number
payment_retry_unit?: 'day' | 'week'
payment_retry_multiplier?: number
payment_retries_limit: number
action: 'none' | 'pause' | 'close'
default?: boolean
}
}

export interface SubscriptionDunningRules extends Identifiable, SubscriptionDunningRulesBase {
meta: {
owner: 'store' | 'organization'
timestamps: {
updated_at: string
created_at: string
}
}
}

export type SubscriptionDunningRulesCreate = SubscriptionDunningRulesBase
export type SubscriptionDunningRulesUpdate = Identifiable & Omit<SubscriptionDunningRulesBase, 'attributes'> & {attributes: Partial<SubscriptionDunningRules['attributes']>}

/**
* Subscription Dunning Rules Endpoints
* DOCS: TODO: add docs when ready
*/
export interface SubscriptionDunningRulesEndpoint
extends CrudQueryableResource<
SubscriptionDunningRules,
SubscriptionDunningRulesCreate,
SubscriptionDunningRulesUpdate,
never,
never,
never
> {
endpoint: 'dunning-rules'
}

0 comments on commit 695c1a0

Please sign in to comment.