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

Commit 695c1a0

Browse files
feat: added subscription dunning rules endpoint (#935)
1 parent 0de13d7 commit 695c1a0

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import CRUDExtend from '../extends/crud'
2+
3+
class SubscriptionDunningRulesEndpoint extends CRUDExtend {
4+
constructor(endpoint) {
5+
super(endpoint)
6+
7+
this.endpoint = 'subscriptions/dunning-rules'
8+
}
9+
10+
Create(body) {
11+
return this.request.send(this.endpoint, 'POST', {
12+
...body
13+
})
14+
}
15+
16+
Update(id, body, token = null) {
17+
return this.request.send(
18+
`${this.endpoint}/${id}`,
19+
'PUT',
20+
{
21+
...body
22+
},
23+
token
24+
)
25+
}
26+
27+
}
28+
29+
export default SubscriptionDunningRulesEndpoint

src/moltin.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import { SubscriptionSubscribersEndpoint } from './types/subscription-subscriber
6565
import { SubscriptionJobsEndpoint } from './types/subscription-jobs'
6666
import { SubscriptionSchedulesEndpoint } from './types/subscription-schedules'
6767
import { CustomApisEndpoint } from './types/custom-apis'
68+
import { SubscriptionDunningRulesEndpoint } from './types/subscription-dunning-rules'
6869

6970
export * from './types/config'
7071
export * from './types/storage'
@@ -140,6 +141,7 @@ export * from './types/subscription-subscribers'
140141
export * from './types/subscription-jobs'
141142
export * from './types/subscription-schedules'
142143
export * from './types/custom-apis'
144+
export * from './types/subscription-dunning-rules'
143145

144146
// UMD
145147
export as namespace moltin
@@ -206,6 +208,7 @@ export class Moltin {
206208
SubscriptionJobs : SubscriptionJobsEndpoint
207209
SubscriptionSchedules: SubscriptionSchedulesEndpoint
208210
CustomApis: CustomApisEndpoint
211+
SubscriptionDunningRules: SubscriptionDunningRulesEndpoint
209212

210213
Cart(id?: string): CartEndpoint // This optional cart id is super worrying when using the SDK in a node server :/
211214
constructor(config: Config)

src/moltin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import RulePromotionsEndpoint from './endpoints/rule-promotions'
5656
import SubscriptionSubscribersEndpoint from './endpoints/subscription-subscribers'
5757
import SubscriptionJobsEndpoint from './endpoints/subscription-jobs'
5858
import SubscriptionSchedulesEndpoint from './endpoints/subscription-schedules'
59+
import SubscriptionDunningRulesEndpoint from './endpoints/subscription-dunning-rules'
5960

6061
import {cartIdentifier, tokenInvalid, getCredentials, resolveCredentialsStorageKey} from './utils/helpers'
6162
import CatalogsEndpoint from './endpoints/catalogs'
@@ -132,6 +133,7 @@ export default class Moltin {
132133
this.SubscriptionJobs = new SubscriptionJobsEndpoint(config)
133134
this.SubscriptionSchedules = new SubscriptionSchedulesEndpoint(config)
134135
this.CustomApis = new CustomApisEndpoint(config)
136+
this.SubscriptionDunningRules = new SubscriptionDunningRulesEndpoint(config)
135137
}
136138

137139
// Expose `Cart` class on Moltin class
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Subscription Dunning Rules
3+
* Description: Subscription Dunning Rules.
4+
* DOCS: TODO: add docs when ready
5+
*/
6+
import {
7+
Identifiable,
8+
CrudQueryableResource
9+
} from './core'
10+
11+
/**
12+
* Core Subscription Dunning Rules Base Interface
13+
* For custom flows, extend this interface
14+
* DOCS: TODO: add docs when ready
15+
*/
16+
export interface SubscriptionDunningRulesBase {
17+
type: 'subscription_dunning_rule'
18+
attributes: {
19+
payment_retry_type: 'fixed' | 'backoff' | 'tiered'
20+
payment_retry_interval?: number
21+
payment_retry_unit?: 'day' | 'week'
22+
payment_retry_multiplier?: number
23+
payment_retries_limit: number
24+
action: 'none' | 'pause' | 'close'
25+
default?: boolean
26+
}
27+
}
28+
29+
export interface SubscriptionDunningRules extends Identifiable, SubscriptionDunningRulesBase {
30+
meta: {
31+
owner: 'store' | 'organization'
32+
timestamps: {
33+
updated_at: string
34+
created_at: string
35+
}
36+
}
37+
}
38+
39+
export type SubscriptionDunningRulesCreate = SubscriptionDunningRulesBase
40+
export type SubscriptionDunningRulesUpdate = Identifiable & Omit<SubscriptionDunningRulesBase, 'attributes'> & {attributes: Partial<SubscriptionDunningRules['attributes']>}
41+
42+
/**
43+
* Subscription Dunning Rules Endpoints
44+
* DOCS: TODO: add docs when ready
45+
*/
46+
export interface SubscriptionDunningRulesEndpoint
47+
extends CrudQueryableResource<
48+
SubscriptionDunningRules,
49+
SubscriptionDunningRulesCreate,
50+
SubscriptionDunningRulesUpdate,
51+
never,
52+
never,
53+
never
54+
> {
55+
endpoint: 'dunning-rules'
56+
}

0 commit comments

Comments
 (0)