2026-02-16 20:11:59 +07:00
|
|
|
'use server'
|
|
|
|
|
|
|
|
|
|
import { YooCheckout, ICreatePayment } from '@a2seven/yoo-checkout';
|
|
|
|
|
import { getSessionData } from '@/app/actions/session';
|
2026-02-18 18:22:11 +07:00
|
|
|
import { API_BASE_URL } from '@/app/actions/definitions';
|
2026-02-16 20:11:59 +07:00
|
|
|
|
|
|
|
|
const checkout = new YooCheckout({ shopId: '1276731', secretKey: 'test_0Yns_0NHV5GJf6ypJ5HC4NSfnLO8SJkw-1PwrVWsDl4' });
|
|
|
|
|
|
|
|
|
|
const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5';
|
|
|
|
|
|
2026-02-18 18:22:11 +07:00
|
|
|
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);
|
|
|
|
|
formData.append('tariffId', tariffId.toString());
|
|
|
|
|
formData.append('operationType', 'TARIFF');
|
|
|
|
|
formData.append('operationUuid', operationUuid);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/payments/create`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: formData
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const parsed = await response.json()
|
|
|
|
|
console.log(parsed);
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function yooKasaCreatePayment(amount: number, tariff: number) {
|
2026-02-16 20:11:59 +07:00
|
|
|
console.log(amount);
|
|
|
|
|
console.log(tariff);
|
|
|
|
|
/* return true; */
|
|
|
|
|
|
|
|
|
|
const userEmail = await getSessionData('email');
|
|
|
|
|
|
2026-02-18 18:22:11 +07:00
|
|
|
if (!userEmail) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-16 20:11:59 +07:00
|
|
|
const createPayload: ICreatePayment = {
|
|
|
|
|
amount: {
|
|
|
|
|
value: amount.toLocaleString(),
|
|
|
|
|
currency: 'RUB'
|
|
|
|
|
},
|
|
|
|
|
payment_method_data: {
|
|
|
|
|
type: 'bank_card'
|
|
|
|
|
},
|
|
|
|
|
confirmation: {
|
|
|
|
|
type: 'redirect',
|
|
|
|
|
return_url: 'test'
|
|
|
|
|
},
|
|
|
|
|
metadata: {
|
2026-02-18 14:21:57 +07:00
|
|
|
userMail: userEmail,
|
2026-02-16 20:11:59 +07:00
|
|
|
tariff: tariff
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const payment = await checkout.createPayment(createPayload, Date.now().toLocaleString());
|
2026-02-18 18:22:11 +07:00
|
|
|
const response = await makePaymentOperation(userEmail, tariff, payment.id);
|
|
|
|
|
console.log('yooKasaCreatePayment')
|
|
|
|
|
console.log(response);
|
|
|
|
|
if (response) {
|
|
|
|
|
return payment?.confirmation.confirmation_url;
|
|
|
|
|
} else {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-16 20:11:59 +07:00
|
|
|
/* return payment; */
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
2026-02-18 18:22:11 +07:00
|
|
|
return null
|
2026-02-16 20:11:59 +07:00
|
|
|
}
|
|
|
|
|
}
|