1
0
Fork 0
mirror of synced 2024-06-12 23:44:39 +12:00
budibase/qa-core/src/account-api/api/apis/StripeAPI.ts

75 lines
1.9 KiB
TypeScript
Raw Normal View History

import AccountInternalAPIClient from "../AccountInternalAPIClient"
import BaseAPI from "./BaseAPI"
import { APIRequestOpts } from "../../../types"
export default class StripeAPI extends BaseAPI {
2023-10-06 05:43:25 +13:00
client: AccountInternalAPIClient
2023-10-06 05:43:25 +13:00
constructor(client: AccountInternalAPIClient) {
super()
this.client = client
}
2023-10-06 05:43:25 +13:00
async createCheckoutSession(
price: object,
2023-10-06 05:43:25 +13:00
opts: APIRequestOpts = { status: 200 }
) {
return this.doRequest(() => {
return this.client.post(`/api/stripe/checkout-session`, {
body: { prices: [price] },
2023-10-06 05:43:25 +13:00
})
}, opts)
}
2023-10-06 05:43:25 +13:00
async checkoutSuccess(opts: APIRequestOpts = { status: 200 }) {
return this.doRequest(() => {
return this.client.post(`/api/stripe/checkout-success`)
}, opts)
}
2023-10-06 05:43:25 +13:00
async createPortalSession(
stripeCustomerId: string,
opts: APIRequestOpts = { status: 200 }
) {
return this.doRequest(() => {
return this.client.post(`/api/stripe/portal-session`, {
body: { stripeCustomerId },
})
}, opts)
}
async linkStripeCustomer(
2023-11-01 07:20:27 +13:00
accountId: string,
stripeCustomerId: string,
opts: APIRequestOpts = { status: 200 }
) {
2023-10-06 05:43:25 +13:00
return this.doRequest(() => {
return this.client.post(`/api/stripe/link`, {
body: {
accountId,
2023-11-01 07:20:27 +13:00
stripeCustomerId,
},
internal: true,
})
2023-10-06 05:43:25 +13:00
}, opts)
}
2023-10-06 05:43:25 +13:00
async getInvoices(opts: APIRequestOpts = { status: 200 }) {
return this.doRequest(() => {
return this.client.get(`/api/stripe/invoices`)
}, opts)
}
2023-10-06 05:43:25 +13:00
async getUpcomingInvoice(opts: APIRequestOpts = { status: 200 }) {
return this.doRequest(() => {
return this.client.get(`/api/stripe/upcoming-invoice`)
}, opts)
}
2023-10-06 05:43:25 +13:00
async getStripeCustomers(opts: APIRequestOpts = { status: 200 }) {
return this.doRequest(() => {
return this.client.get(`/api/stripe/customers`)
}, opts)
}
}