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

feat: subscription proration policies endpoint #936

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/endpoints/subscription-proration-policies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import CRUDExtend from '../extends/crud'

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

this.endpoint = 'subscriptions/proration-policies'
}

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 SubscriptionProrationPoliciesEndpoint
3 changes: 3 additions & 0 deletions src/moltin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ 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'
import { SubscriptionProrationPoliciesEndpoint } from './types/subscription-proration-policies'

export * from './types/config'
export * from './types/storage'
Expand Down Expand Up @@ -142,6 +143,7 @@ export * from './types/subscription-jobs'
export * from './types/subscription-schedules'
export * from './types/custom-apis'
export * from './types/subscription-dunning-rules'
export * from './types/subscription-proration-policies'

// UMD
export as namespace moltin
Expand Down Expand Up @@ -209,6 +211,7 @@ export class Moltin {
SubscriptionSchedules: SubscriptionSchedulesEndpoint
CustomApis: CustomApisEndpoint
SubscriptionDunningRules: SubscriptionDunningRulesEndpoint
SubscriptionProrationPolicies: SubscriptionProrationPoliciesEndpoint

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 @@ -57,6 +57,7 @@ import SubscriptionSubscribersEndpoint from './endpoints/subscription-subscriber
import SubscriptionJobsEndpoint from './endpoints/subscription-jobs'
import SubscriptionSchedulesEndpoint from './endpoints/subscription-schedules'
import SubscriptionDunningRulesEndpoint from './endpoints/subscription-dunning-rules'
import SubscriptionProrationPoliciesEndpoint from './endpoints/subscription-proration-policies'

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

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

/**
* Core Subscription Proration Policies Base Interface
* For custom flows, extend this interface
* DOCS: TODO: add docs when ready
*/
export interface SubscriptionProrationPolicyBase {
type: 'proration_policy'
attributes: {
name: string
rounding: 'up' | 'down' | 'nearest'
external_ref?: string
}
}

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

export type SubscriptionProrationPolicyCreate = SubscriptionProrationPolicyBase
export type SubscriptionProrationPolicyUpdate = Identifiable & Omit<SubscriptionProrationPolicyBase, 'attributes'> & {attributes: Partial<SubscriptionProrationPolicy['attributes']>}

/**
* Subscription Proration Policies Endpoints
* DOCS: TODO: add docs when ready
*/
export interface SubscriptionProrationPoliciesEndpoint
extends CrudQueryableResource<
SubscriptionProrationPolicy,
SubscriptionProrationPolicyCreate,
SubscriptionProrationPolicyUpdate,
never,
never,
never
> {
endpoint: 'proration-policies'
}
Loading