import type { AxiosRequestConfig } from 'axios' ; import type { HttpClient } from '../../http/' ; import type { PaymentBillingData , PaymentData , PaymentDataUpdate , PaymentPlan , PaymentStripeCharge , PaymentStripeInvoices , PaymentStripePlan , } from './' ; export class PaymentAPI { public static readonly DEFAULT_INVOICES_CHUNK_SIZE = 10 ; constructor ( private readonly client ) { } public static readonly URL = { BILLING : 'billing' , CHARGES : 'charges' , CURRENCIES : 'currencies' , INFO : 'info' , INVOICES : 'invoices' , PLAN : 'plan' , PLANS : 'plans' , TEAMS : '/teams' , } ; deprecated public async putPaymentData ( teamId , paymentData ) { const config = { data : paymentData , method : 'put' , url : `${ PaymentAPI . URL . TEAMS }/${ teamId }/${ PaymentAPI . URL . BILLING }` , } ; const response = await this . client . sendJSON < PaymentData > ( config ) ; return response . data ; } deprecated public async getPaymentData ( teamId ) { const config = { method : 'get' , url : `${ PaymentAPI . URL . TEAMS }/${ teamId }/${ PaymentAPI . URL . BILLING }` , } ; const response = await this . client . sendJSON < PaymentData > ( config ) ; return response . data ; } deprecated public async deletePaymentData ( teamId , paymentData ) { const config = { data : paymentData , method : 'delete' , url : `${ PaymentAPI . URL . TEAMS }/${ teamId }/${ PaymentAPI . URL . BILLING }` , } ; const response = await this . client . sendJSON < PaymentData > ( config ) ; return response . data ; } deprecated public async putPaymentBilling ( teamId , billingInfo ) { const config = { data : billingInfo , method : 'put' , url : `${ PaymentAPI . URL . TEAMS }/${ teamId }/${ PaymentAPI . URL . BILLING }/${ PaymentAPI . URL . INFO }` , } ; const response = await this . client . sendJSON < PaymentBillingData > ( config ) ; return response . data ; } deprecated public async getPaymentBilling ( teamId ) { const config = { method : 'get' , url : `${ PaymentAPI . URL . TEAMS }/${ teamId }/${ PaymentAPI . URL . BILLING }/${ PaymentAPI . URL . INFO }` , } ; const response = await this . client . sendJSON < PaymentBillingData > ( config ) ; return response . data ; } deprecated public async putPaymentPlan ( teamId , plan ) { const config = { data : plan , method : 'put' , url : `${ PaymentAPI . URL . TEAMS }/${ teamId }/${ PaymentAPI . URL . BILLING }/${ PaymentAPI . URL . PLAN }/${ plan . id }` , } ; await this . client . sendJSON ( config ) ; } deprecated public async getPlans ( teamId ) { const config = { method : 'get' , url : `${ PaymentAPI . URL . TEAMS }/${ teamId }/${ PaymentAPI . URL . BILLING }/${ PaymentAPI . URL . PLANS }` , } ; const response = await this . client . sendJSON < PaymentStripePlan [ ] > ( config ) ; return response . data ; } deprecated public async getCharges ( teamId ) { const config = { method : 'get' , url : `${ PaymentAPI . URL . TEAMS }/${ teamId }/${ PaymentAPI . URL . BILLING }/${ PaymentAPI . URL . CHARGES }` , } ; const response = await this . client . sendJSON < PaymentStripeCharge [ ] > ( config ) ; return response . data ; } deprecated public async getInvoices ( teamId , limit = PaymentAPI . DEFAULT_INVOICES_CHUNK_SIZE , startAfterInvoiceId ? ) { const config = { method : 'get' , params : { size : limit , start : startAfterInvoiceId , } , url : `${ PaymentAPI . URL . TEAMS }/${ teamId }/${ PaymentAPI . URL . BILLING }/${ PaymentAPI . URL . INVOICES }` , } ; const response = await this . client . sendJSON < PaymentStripeInvoices > ( config ) ; return response . data ; } deprecated public async getSupportedCurrencies ( teamId ) { const config = { method : 'get' , url : `${ PaymentAPI . URL . TEAMS }/${ teamId }/${ PaymentAPI . URL . BILLING }/${ PaymentAPI . URL . CURRENCIES }` , } ; const response = await this . client . sendJSON < string [ ] > ( config ) ; return response . data ; } }