[AI] fix some modules, develop the big part of modules. TODO fix critical errors, update pipeline, test everything
This commit is contained in:
+26
-5
@@ -47,20 +47,41 @@ export const activateTrial = async () => {
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const buySubscription = async (plan: string) => {
|
||||
|
||||
export const initiatePayment = async (plan: string, provider: string, currency: string) => {
|
||||
const token = localStorage.getItem(TOKEN_KEY);
|
||||
// Путь: /api/v1/billing/subscribe
|
||||
const res = await fetch(`${API_BASE}/billing/subscribe`, {
|
||||
if (!token) throw new Error("No token found");
|
||||
|
||||
const res = await fetch(`${API_BASE}/billing/pay/initiate`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify({ plan }),
|
||||
body: JSON.stringify({ plan, provider, currency }),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const errData = await res.json().catch(() => ({}));
|
||||
throw new Error(errData.error || res.statusText || "Purchase failed");
|
||||
throw new Error(errData.error || "Initiate payment failed");
|
||||
}
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const confirmPayment = async (invoice_id: string, external_tx_id: string) => {
|
||||
const token = localStorage.getItem(TOKEN_KEY);
|
||||
const res = await fetch(`${API_BASE}/billing/pay/confirm`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify({ invoice_id, external_tx_id }),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const errData = await res.json().catch(() => ({}));
|
||||
throw new Error(errData.error || "Payment verification failed");
|
||||
}
|
||||
return res.json();
|
||||
};
|
||||
Reference in New Issue
Block a user