|
| 1 | +/** |
| 2 | + * Subscription Invoices |
| 3 | + * Description: Invoices represent the amount a customer owes for a subscription. |
| 4 | + * Elastic Path Subscriptions generates an invoice for every period in a subscription billing cycle. |
| 5 | + * DOCS: https://elasticpath.dev/docs/api/subscriptions/invoices |
| 6 | + */ |
| 7 | +import { |
| 8 | + Identifiable, |
| 9 | + CrudQueryableResource, |
| 10 | + Resource, |
| 11 | + ResourceList, |
| 12 | + ResourcePage |
| 13 | +} from './core' |
| 14 | +import { ItemTaxObject } from './cart' |
| 15 | +import { Price } from './price' |
| 16 | + |
| 17 | +interface SubscriptionInvoiceItemPrice extends Omit<Price, 'includes_tax'> { |
| 18 | + includes_tax?: boolean |
| 19 | +} |
| 20 | + |
| 21 | +interface SubscriptionInvoiceItem { |
| 22 | + description: string |
| 23 | + price: SubscriptionInvoiceItemPrice |
| 24 | + product_id?: string |
| 25 | + from_time_period?: string |
| 26 | + until_time_period?: string |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * Core Subscription Invoice Base Interface |
| 31 | + * For custom flows, extend this interface |
| 32 | + * DOCS: https://elasticpath.dev/docs/api/subscriptions/get-invoice#responses |
| 33 | + */ |
| 34 | + |
| 35 | +export interface SubscriptionInvoiceBase { |
| 36 | + type: 'subscription_invoice' |
| 37 | + attributes: { |
| 38 | + billing_period: { |
| 39 | + start: string |
| 40 | + end: string |
| 41 | + } |
| 42 | + invoice_items: SubscriptionInvoiceItem[] |
| 43 | + tax_items?: ItemTaxObject[] |
| 44 | + outstanding: boolean |
| 45 | + number?: number |
| 46 | + tax_required: boolean |
| 47 | + payment_retries_limit_reached: boolean |
| 48 | + updated_at?: string |
| 49 | + created_at?: string |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +interface ProrationEvent { |
| 54 | + proration_policy_id: string |
| 55 | + billing_cost_before_proration: number |
| 56 | + refunded_amount_for_unused_plan: number |
| 57 | + new_plan_cost: number |
| 58 | + prorated_at: string |
| 59 | +} |
| 60 | + |
| 61 | +export interface SubscriptionInvoice |
| 62 | + extends Identifiable, |
| 63 | + SubscriptionInvoiceBase { |
| 64 | + meta: { |
| 65 | + owner: 'store' | 'organization' |
| 66 | + subscription_id?: string |
| 67 | + subscriber_id?: string |
| 68 | + price?: SubscriptionInvoiceItemPrice |
| 69 | + timestamps: { |
| 70 | + updated_at: string |
| 71 | + created_at: string |
| 72 | + taxes_added_at?: string |
| 73 | + } |
| 74 | + prorated_at: ProrationEvent[] |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +/** |
| 79 | + * Core Subscription Invoice Payments Base Interface |
| 80 | + * DOCS: https://elasticpath.dev/docs/api/subscriptions/get-invoice-payment#responses |
| 81 | + */ |
| 82 | + |
| 83 | +export interface SubscriptionInvoicePaymentBase { |
| 84 | + type: 'subscription_invoice_payment' |
| 85 | + attributes: { |
| 86 | + success: boolean |
| 87 | + gateway: string |
| 88 | + external_payment_id?: string |
| 89 | + failure_detail?: { |
| 90 | + reason?: string |
| 91 | + } |
| 92 | + amount: SubscriptionInvoiceItemPrice |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +export interface SubscriptionInvoicePayment |
| 97 | + extends Identifiable, |
| 98 | + SubscriptionInvoicePaymentBase { |
| 99 | + meta: { |
| 100 | + owner: 'store' | 'organization' |
| 101 | + subscription_id: string |
| 102 | + invoice_id: string |
| 103 | + job_id: string |
| 104 | + timestamps: { |
| 105 | + updated_at: string |
| 106 | + created_at: string |
| 107 | + payment_taken_at?: string |
| 108 | + } |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +/** |
| 113 | + * Subscription Invoice Filtering |
| 114 | + * DOCS: https://elasticpath.dev/docs/api/subscriptions/list-invoices#filtering |
| 115 | + */ |
| 116 | +export interface SubscriptionInvoiceFilter { |
| 117 | + eq?: { |
| 118 | + subscriber_id?: string |
| 119 | + subscription_id?: string |
| 120 | + outstanding?: string |
| 121 | + tax_required?: string |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +/** |
| 126 | + * Subscription Invoice Endpoints |
| 127 | + * DOCS: https://elasticpath.dev/docs/api/subscriptions/list-invoices |
| 128 | + */ |
| 129 | +export interface SubscriptionInvoicesEndpoint { |
| 130 | + endpoint: 'invoices' |
| 131 | + |
| 132 | + /** |
| 133 | + * List Invoices |
| 134 | + * DOCS: https://elasticpath.dev/docs/api/subscriptions/list-invoices |
| 135 | + * @constructor |
| 136 | + */ |
| 137 | + All(): Promise<ResourcePage<SubscriptionInvoice>> |
| 138 | + |
| 139 | + /** |
| 140 | + * Get Invoice |
| 141 | + * DOCS: https://elasticpath.dev/docs/api/subscriptions/get-invoice |
| 142 | + * @param id - The ID of the invoice. |
| 143 | + * @constructor |
| 144 | + */ |
| 145 | + Get(id: string): Promise<Resource<SubscriptionInvoice>> |
| 146 | + |
| 147 | + /** |
| 148 | + * List Invoice Payments |
| 149 | + * DOCS: https://elasticpath.dev/docs/api/subscriptions/list-invoice-payments |
| 150 | + * @param invoiceId - The ID of the invoice to get the payments for. |
| 151 | + * @constructor |
| 152 | + */ |
| 153 | + GetPayments( |
| 154 | + invoiceId: string |
| 155 | + ): Promise<ResourceList<SubscriptionInvoicePayment>> |
| 156 | + |
| 157 | + /** |
| 158 | + * Get Invoice Payment |
| 159 | + * DOCS: https://elasticpath.dev/docs/api/subscriptions/get-invoice-payment |
| 160 | + * @param invoiceId - The ID of the invoice to get the payment for. |
| 161 | + * @param paymentId - The ID of the payment. |
| 162 | + * @constructor |
| 163 | + */ |
| 164 | + GetPayment( |
| 165 | + invoiceId: string, |
| 166 | + paymentId: string |
| 167 | + ): Promise<Resource<SubscriptionInvoicePayment>> |
| 168 | + |
| 169 | + /** |
| 170 | + * Subscription Invoice Filtering |
| 171 | + * DOCS: https://elasticpath.dev/docs/api/subscriptions/list-invoices#filtering |
| 172 | + */ |
| 173 | + Filter(filter: SubscriptionInvoiceFilter): SubscriptionInvoicesEndpoint |
| 174 | + |
| 175 | + Limit(value: number): SubscriptionInvoicesEndpoint |
| 176 | + |
| 177 | + Offset(value: number): SubscriptionInvoicesEndpoint |
| 178 | +} |
0 commit comments