diff --git a/src/endpoints/subscription-proration-policies.js b/src/endpoints/subscription-proration-policies.js new file mode 100644 index 000000000..83ababc8f --- /dev/null +++ b/src/endpoints/subscription-proration-policies.js @@ -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 diff --git a/src/moltin.d.ts b/src/moltin.d.ts index 3f11ab0e6..81ee4be01 100644 --- a/src/moltin.d.ts +++ b/src/moltin.d.ts @@ -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' @@ -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 @@ -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) diff --git a/src/moltin.js b/src/moltin.js index 568ac1753..dc308ba29 100644 --- a/src/moltin.js +++ b/src/moltin.js @@ -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' @@ -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 diff --git a/src/types/subscription-proration-policies.d.ts b/src/types/subscription-proration-policies.d.ts new file mode 100644 index 000000000..c3627aa73 --- /dev/null +++ b/src/types/subscription-proration-policies.d.ts @@ -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 & {attributes: Partial} + +/** + * Subscription Proration Policies Endpoints + * DOCS: TODO: add docs when ready + */ +export interface SubscriptionProrationPoliciesEndpoint + extends CrudQueryableResource< + SubscriptionProrationPolicy, + SubscriptionProrationPolicyCreate, + SubscriptionProrationPolicyUpdate, + never, + never, + never + > { + endpoint: 'proration-policies' +}