-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added subscriptions invoices endpoints (#7)
BREAKING CHANGE:
- Loading branch information
1 parent
ff12711
commit 0a1d4a8
Showing
5 changed files
with
279 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import RequestFactory from '../factories/request' | ||
import { buildURL } from '../utils/helpers' | ||
|
||
class SubscriptionInvoicesEndpoint { | ||
constructor(endpoint) { | ||
const config = { ...endpoint } | ||
this.request = new RequestFactory(config) | ||
|
||
this.endpoint = 'subscriptions/invoices' | ||
} | ||
|
||
All() { | ||
const { filter, limit, offset } = this | ||
|
||
return this.request.send( | ||
buildURL(this.endpoint, { | ||
filter, | ||
limit, | ||
offset | ||
}), | ||
'GET' | ||
) | ||
} | ||
|
||
Get(id) { | ||
return this.request.send(`${this.endpoint}/${id}`, 'GET') | ||
} | ||
|
||
GetPayments(invoiceId) { | ||
return this.request.send(`${this.endpoint}/${invoiceId}/payments`, 'GET') | ||
} | ||
|
||
GetPayment(invoiceId, paymentId) { | ||
return this.request.send( | ||
`${this.endpoint}/${invoiceId}/payments/${paymentId}`, | ||
'GET' | ||
) | ||
} | ||
|
||
Filter(filter) { | ||
this.filter = filter | ||
|
||
return this | ||
} | ||
|
||
Limit(value) { | ||
this.limit = value | ||
|
||
return this | ||
} | ||
|
||
Offset(value) { | ||
this.offset = value | ||
|
||
return this | ||
} | ||
} | ||
|
||
export default SubscriptionInvoicesEndpoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
/** | ||
* Subscription Invoices | ||
* Description: Invoices represent the amount a customer owes for a subscription. | ||
* Elastic Path Subscriptions generates an invoice for every period in a subscription billing cycle. | ||
* DOCS: https://elasticpath.dev/docs/api/subscriptions/invoices | ||
*/ | ||
import { | ||
Identifiable, | ||
CrudQueryableResource, | ||
Resource, | ||
ResourceList, | ||
ResourcePage | ||
} from './core' | ||
import { ItemTaxObject } from './cart' | ||
import { Price } from './price' | ||
|
||
interface SubscriptionInvoiceItemPrice extends Omit<Price, 'includes_tax'> { | ||
includes_tax?: boolean | ||
} | ||
|
||
interface SubscriptionInvoiceItem { | ||
description: string | ||
price: SubscriptionInvoiceItemPrice | ||
product_id?: string | ||
from_time_period?: string | ||
until_time_period?: string | ||
} | ||
|
||
/** | ||
* Core Subscription Invoice Base Interface | ||
* For custom flows, extend this interface | ||
* DOCS: https://elasticpath.dev/docs/api/subscriptions/get-invoice#responses | ||
*/ | ||
|
||
export interface SubscriptionInvoiceBase { | ||
type: 'subscription_invoice' | ||
attributes: { | ||
billing_period: { | ||
start: string | ||
end: string | ||
} | ||
invoice_items: SubscriptionInvoiceItem[] | ||
tax_items?: ItemTaxObject[] | ||
outstanding: boolean | ||
number?: number | ||
tax_required: boolean | ||
payment_retries_limit_reached: boolean | ||
updated_at?: string | ||
created_at?: string | ||
} | ||
} | ||
|
||
interface ProrationEvent { | ||
proration_policy_id: string | ||
billing_cost_before_proration: number | ||
refunded_amount_for_unused_plan: number | ||
new_plan_cost: number | ||
prorated_at: string | ||
} | ||
|
||
export interface SubscriptionInvoice | ||
extends Identifiable, | ||
SubscriptionInvoiceBase { | ||
meta: { | ||
owner: 'store' | 'organization' | ||
subscription_id?: string | ||
subscriber_id?: string | ||
price?: SubscriptionInvoiceItemPrice | ||
timestamps: { | ||
updated_at: string | ||
created_at: string | ||
taxes_added_at?: string | ||
} | ||
prorated_at: ProrationEvent[] | ||
} | ||
} | ||
|
||
/** | ||
* Core Subscription Invoice Payments Base Interface | ||
* DOCS: https://elasticpath.dev/docs/api/subscriptions/get-invoice-payment#responses | ||
*/ | ||
|
||
export interface SubscriptionInvoicePaymentBase { | ||
type: 'subscription_invoice_payment' | ||
attributes: { | ||
success: boolean | ||
gateway: string | ||
external_payment_id?: string | ||
failure_detail?: { | ||
reason?: string | ||
} | ||
amount: SubscriptionInvoiceItemPrice | ||
} | ||
} | ||
|
||
export interface SubscriptionInvoicePayment | ||
extends Identifiable, | ||
SubscriptionInvoicePaymentBase { | ||
meta: { | ||
owner: 'store' | 'organization' | ||
subscription_id: string | ||
invoice_id: string | ||
job_id: string | ||
timestamps: { | ||
updated_at: string | ||
created_at: string | ||
payment_taken_at?: string | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Subscription Invoice Filtering | ||
* DOCS: https://elasticpath.dev/docs/api/subscriptions/list-invoices#filtering | ||
*/ | ||
export interface SubscriptionInvoiceFilter { | ||
eq?: { | ||
subscriber_id?: string | ||
subscription_id?: string | ||
outstanding?: string | ||
tax_required?: string | ||
} | ||
} | ||
|
||
/** | ||
* Subscription Invoice Endpoints | ||
* DOCS: https://elasticpath.dev/docs/api/subscriptions/list-invoices | ||
*/ | ||
export interface SubscriptionInvoicesEndpoint { | ||
endpoint: 'invoices' | ||
|
||
/** | ||
* List Invoices | ||
* DOCS: https://elasticpath.dev/docs/api/subscriptions/list-invoices | ||
* @constructor | ||
*/ | ||
All(): Promise<ResourcePage<SubscriptionInvoice>> | ||
|
||
/** | ||
* Get Invoice | ||
* DOCS: https://elasticpath.dev/docs/api/subscriptions/get-invoice | ||
* @param id - The ID of the invoice. | ||
* @constructor | ||
*/ | ||
Get(id: string): Promise<Resource<SubscriptionInvoice>> | ||
|
||
/** | ||
* List Invoice Payments | ||
* DOCS: https://elasticpath.dev/docs/api/subscriptions/list-invoice-payments | ||
* @param invoiceId - The ID of the invoice to get the payments for. | ||
* @constructor | ||
*/ | ||
GetPayments( | ||
invoiceId: string | ||
): Promise<ResourceList<SubscriptionInvoicePayment>> | ||
|
||
/** | ||
* Get Invoice Payment | ||
* DOCS: https://elasticpath.dev/docs/api/subscriptions/get-invoice-payment | ||
* @param invoiceId - The ID of the invoice to get the payment for. | ||
* @param paymentId - The ID of the payment. | ||
* @constructor | ||
*/ | ||
GetPayment( | ||
invoiceId: string, | ||
paymentId: string | ||
): Promise<Resource<SubscriptionInvoicePayment>> | ||
|
||
/** | ||
* Subscription Invoice Filtering | ||
* DOCS: https://elasticpath.dev/docs/api/subscriptions/list-invoices#filtering | ||
*/ | ||
Filter(filter: SubscriptionInvoiceFilter): SubscriptionInvoicesEndpoint | ||
|
||
Limit(value: number): SubscriptionInvoicesEndpoint | ||
|
||
Offset(value: number): SubscriptionInvoicesEndpoint | ||
} |
Oops, something went wrong.