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 PerSitePricingBillingProfile extends BaseResource { static readonly TYPE = 'per_site_pricing_billing_profile' as const; /** * Retrieve all account's billing profiles * * @throws {ApiError} * @throws {TimeoutError} */ list() { return this.rawList().then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Retrieve all account's billing profiles * * @throws {ApiError} * @throws {TimeoutError} */ rawList(): Promise { return this.client.request( { method: 'GET', url: '/per-site-pricing-billing-profiles', }, ); } /** * Retrieve a billing profile * * @throws {ApiError} * @throws {TimeoutError} */ find( perSitePricingBillingProfileId: | string | ApiTypes.PerSitePricingBillingProfileData, queryParams?: ApiTypes.PerSitePricingBillingProfileSelfHrefSchema, ) { return this.rawFind( Utils.toId(perSitePricingBillingProfileId), queryParams, ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Retrieve a billing profile * * @throws {ApiError} * @throws {TimeoutError} */ rawFind( perSitePricingBillingProfileId: string, queryParams?: RawApiTypes.PerSitePricingBillingProfileSelfHrefSchema, ): Promise { return this.client.request( { method: 'GET', url: `/per-site-pricing-billing-profiles/${perSitePricingBillingProfileId}`, queryParams, }, ); } /** * Update a billing profile's credit card * * @throws {ApiError} * @throws {TimeoutError} */ updateCreditCard( perSitePricingBillingProfileId: | string | ApiTypes.PerSitePricingBillingProfileData, body: ApiTypes.PerSitePricingBillingProfileUpdateCreditCardSchema, ) { return this.rawUpdateCreditCard( Utils.toId(perSitePricingBillingProfileId), Utils.serializeRequestBody( body, { type: 'card', attributes: ['payment_intent_id'], relationships: [], }, ), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Update a billing profile's credit card * * @throws {ApiError} * @throws {TimeoutError} */ rawUpdateCreditCard( perSitePricingBillingProfileId: string, body: RawApiTypes.PerSitePricingBillingProfileUpdateCreditCardSchema, ): Promise { return this.client.request( { method: 'PUT', url: `/per-site-pricing-billing-profiles/${perSitePricingBillingProfileId}/credit-card`, body, }, ); } /** * Update a billing profile's billing information * * @throws {ApiError} * @throws {TimeoutError} */ updateInfo( perSitePricingBillingProfileId: | string | ApiTypes.PerSitePricingBillingProfileData, body: ApiTypes.PerSitePricingBillingProfileUpdateInfoSchema, ) { return this.rawUpdateInfo( Utils.toId(perSitePricingBillingProfileId), Utils.serializeRequestBody( body, { type: 'per_site_pricing_billing_profile', attributes: ['billing_profile'], relationships: [], }, ), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Update a billing profile's billing information * * @throws {ApiError} * @throws {TimeoutError} */ rawUpdateInfo( perSitePricingBillingProfileId: string, body: RawApiTypes.PerSitePricingBillingProfileUpdateInfoSchema, ): Promise { return this.client.request( { method: 'PUT', url: `/per-site-pricing-billing-profiles/${perSitePricingBillingProfileId}/info`, body, }, ); } /** * Cancel subscription * * @throws {ApiError} * @throws {TimeoutError} */ cancelSubscription( perSitePricingBillingProfileId: | string | ApiTypes.PerSitePricingBillingProfileData, body: ApiTypes.PerSitePricingBillingProfileCancelSubscriptionSchema, ) { return this.rawCancelSubscription( Utils.toId(perSitePricingBillingProfileId), Utils.serializeRequestBody( body, { type: 'per_site_pricing_billing_profile', attributes: ['reason'], relationships: [], }, ), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Cancel subscription * * @throws {ApiError} * @throws {TimeoutError} */ rawCancelSubscription( perSitePricingBillingProfileId: string, body: RawApiTypes.PerSitePricingBillingProfileCancelSubscriptionSchema, ): Promise { return this.client.request( { method: 'POST', url: `/per-site-pricing-billing-profiles/${perSitePricingBillingProfileId}/cancel-subscription`, body, }, ); } /** * Delete a billing profile * * @throws {ApiError} * @throws {TimeoutError} */ destroy( perSitePricingBillingProfileId: | string | ApiTypes.PerSitePricingBillingProfileData, ) { return this.rawDestroy(Utils.toId(perSitePricingBillingProfileId)).then( (body) => Utils.deserializeResponseBody( body, ), ); } /** * Delete a billing profile * * @throws {ApiError} * @throws {TimeoutError} */ rawDestroy( perSitePricingBillingProfileId: string, ): Promise { return this.client.request( { method: 'DELETE', url: `/per-site-pricing-billing-profiles/${perSitePricingBillingProfileId}`, }, ); } }