import * as Utils from '@datocms/rest-client-utils'; import BaseResource from '../../BaseResource.js'; import type * as ApiTypes from '../ApiTypes.js'; import type * as RawApiTypes from '../RawApiTypes.js'; export default class Invoice extends BaseResource { static readonly TYPE = 'invoice' as const; /** * Retrieve all invoices * * @throws {ApiError} * @throws {TimeoutError} */ perOwnerPricingBillingProfileList() { return this.rawPerOwnerPricingBillingProfileList().then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Retrieve all invoices * * @throws {ApiError} * @throws {TimeoutError} */ rawPerOwnerPricingBillingProfileList(): Promise { return this.client.request( { method: 'GET', url: '/per-owner-pricing-billing-profile/invoices', }, ); } /** * Retrieve all invoices * * @throws {ApiError} * @throws {TimeoutError} */ perSitePricingBillingProfileList( perSitePricingBillingProfileId: | string | ApiTypes.PerSitePricingBillingProfileData, ) { return this.rawPerSitePricingBillingProfileList( Utils.toId(perSitePricingBillingProfileId), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Retrieve all invoices * * @throws {ApiError} * @throws {TimeoutError} */ rawPerSitePricingBillingProfileList( perSitePricingBillingProfileId: string, ): Promise { return this.client.request( { method: 'GET', url: `/per-site-pricing-billing-profiles/${perSitePricingBillingProfileId}/invoices`, }, ); } /** * Collect all unpaid invoices * * @throws {ApiError} * @throws {TimeoutError} */ perOwnerPricingBillingProfileCollectUnpaid( body: ApiTypes.InvoicePerOwnerPricingBillingProfileCollectUnpaidSchema, ) { return this.rawPerOwnerPricingBillingProfileCollectUnpaid( Utils.serializeRequestBody( body, { type: 'invoice_collection', attributes: ['payment_intent_id'], relationships: [], }, ), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Collect all unpaid invoices * * @throws {ApiError} * @throws {TimeoutError} */ rawPerOwnerPricingBillingProfileCollectUnpaid( body: RawApiTypes.InvoicePerOwnerPricingBillingProfileCollectUnpaidSchema, ): Promise { return this.client.request( { method: 'POST', url: '/per-owner-pricing-billing-profile/invoices/collect-unpaid', body, }, ); } /** * Collect all unpaid invoices * * @throws {ApiError} * @throws {TimeoutError} */ perSitePricingBillingProfileCollectUnpaid( perSitePricingBillingProfileId: | string | ApiTypes.PerSitePricingBillingProfileData, body: ApiTypes.InvoicePerSitePricingBillingProfileCollectUnpaidSchema, ) { return this.rawPerSitePricingBillingProfileCollectUnpaid( Utils.toId(perSitePricingBillingProfileId), Utils.serializeRequestBody( body, { type: 'invoice_collection', attributes: ['payment_intent_id'], relationships: [], }, ), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Collect all unpaid invoices * * @throws {ApiError} * @throws {TimeoutError} */ rawPerSitePricingBillingProfileCollectUnpaid( perSitePricingBillingProfileId: string, body: RawApiTypes.InvoicePerSitePricingBillingProfileCollectUnpaidSchema, ): Promise { return this.client.request( { method: 'POST', url: `/per-site-pricing-billing-profiles/${perSitePricingBillingProfileId}/invoices/collect-unpaid`, body, }, ); } }