Files
plane/web/ee/services/payment.service.ts
Prateek Shourya 437535a9a6 dev: merge payment endpoint. (#1023)
* fix: payment link endpoint

* fix: trial remaining days

* chore: merge payment endpoint and code cleanup.

---------

Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
2024-09-03 17:38:07 +05:30

68 lines
2.2 KiB
TypeScript

import { IPaymentProduct, IWorkspaceProductSubscription } from "@plane/types";
// helpers
import { API_BASE_URL } from "@/helpers/common.helper";
// services
import { APIService } from "@/services/api.service";
export class PaymentService extends APIService {
constructor() {
super(API_BASE_URL);
}
async listProducts(workspaceSlug: string): Promise<IPaymentProduct[]> {
return this.get(`/api/payments/workspaces/${workspaceSlug}/products/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getCurrentWorkspacePaymentLink(workspaceSlug: string, data = {}) {
return this.post(`/api/payments/workspaces/${workspaceSlug}/payment-link/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getWorkspaceCurrentPlan(workspaceSlug: string): Promise<IWorkspaceProductSubscription> {
return this.get(`/api/payments/workspaces/${workspaceSlug}/current-plan/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async refreshWorkspaceCurrentPlan(workspaceSlug: string): Promise<void> {
return this.post(`/api/payments/workspaces/${workspaceSlug}/license-refresh/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getWorkspaceSubscriptionPageLink(workspaceSlug: string) {
return this.post(`/api/payments/workspaces/${workspaceSlug}/subscriptions/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getPaymentLink(data = {}) {
return this.post(`/api/payments/website/payment-link/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getFreeTrialSubscription(workspaceSlug: string, payload: { product_id: string; price_id: string }) {
return this.post(`/api/payments/workspaces/${workspaceSlug}/trial-subscriptions/`, payload)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}