add tokens bundle payments

This commit is contained in:
smanylov
2026-02-19 17:23:52 +07:00
parent 13128d282b
commit 048e1269ad
10 changed files with 316 additions and 47 deletions
+12 -24
View File
@@ -6,17 +6,7 @@ import { API_BASE_URL } from '@/app/actions/definitions';
const checkout = new YooCheckout({ shopId: '1276731', secretKey: 'test_0Yns_0NHV5GJf6ypJ5HC4NSfnLO8SJkw-1PwrVWsDl4' });
const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5';
export async function makePaymentOperation(email: string, tariffId: number, operationUuid: string) {
console.log('makePaymentOperation');
console.log({
email,
tariffId: tariffId,
operationType: 'TARIFF',
operationUuid,
});
const formData = new FormData();
formData.append('email', email);
@@ -31,12 +21,14 @@ export async function makePaymentOperation(email: string, tariffId: number, oper
});
if (response.ok) {
const parsed = await response.json()
console.log(parsed);
return true
const parsed = await response.json();
if (parsed.paymentUuid) {
return true
} else {
throw 'error'
}
} else {
return null
throw 'error'
}
} catch (error) {
return null
@@ -44,11 +36,11 @@ export async function makePaymentOperation(email: string, tariffId: number, oper
}
export async function yooKasaCreatePayment(amount: number, tariff: number) {
console.log(amount);
console.log(tariff);
/* return true; */
const userEmail = await getSessionData('email');
const timestamp = Date.now();
const random = Math.random().toString(36).substring(2, 10);
const idempotenceKey = `${userEmail}-${timestamp}-${amount}-${tariff}-${random}`;
if (!userEmail) {
return null;
@@ -73,17 +65,13 @@ export async function yooKasaCreatePayment(amount: number, tariff: number) {
};
try {
const payment = await checkout.createPayment(createPayload, Date.now().toLocaleString());
const payment = await checkout.createPayment(createPayload, idempotenceKey);
const response = await makePaymentOperation(userEmail, tariff, payment.id);
console.log('yooKasaCreatePayment')
console.log(response);
if (response) {
if (response && payment) {
return payment?.confirmation.confirmation_url;
} else {
return null
}
/* return payment; */
} catch (error) {
return null
}