add YooMoneyWidget, change payments handler

This commit is contained in:
smanylov
2026-03-03 18:48:09 +07:00
parent 3e3a5df34d
commit a53c1b4b49
5 changed files with 217 additions and 9 deletions
+23 -5
View File
@@ -3,6 +3,7 @@
import { YooCheckout, ICreatePayment } from '@a2seven/yoo-checkout';
import { getSessionData, deleteSession } from '@/app/actions/session';
import { API_BASE_URL } from '@/app/actions/definitions';
import { id } from 'zod/v4/locales';
const checkout = new YooCheckout({ shopId: '1276731', secretKey: 'test_0Yns_0NHV5GJf6ypJ5HC4NSfnLO8SJkw-1PwrVWsDl4' });
@@ -36,6 +37,7 @@ export async function makePaymentOperation(email: string, tariffId: number, oper
}
export async function yooKasaCreatePayment(amount: number, tariff: number, operationType: 'TARIFF' | 'TOKEN') {
console.log('yooKasaCreatePayment');
const userEmail = await getSessionData('email');
const timestamp = Date.now();
@@ -51,21 +53,37 @@ export async function yooKasaCreatePayment(amount: number, tariff: number, opera
value: amount.toLocaleString().replace(/\s/g, ''),
currency: 'RUB'
},
payment_method_data: {
/* payment_method_data: {
type: 'bank_card'
},
}, */
/* payment_method_id: "3138d708-000f-5001-9000-19865cfcca68", */
confirmation: {
type: 'redirect',
return_url: 'test'
type: 'embedded',
/* type: 'redirect',
return_url: 'test' */
},
metadata: {
userMail: userEmail,
tariff: tariff
},
merchant_customer_id: userEmail,
capture: true
};
try {
const payment = await checkout.createPayment(createPayload, idempotenceKey);
const response = await makePaymentOperation(userEmail, tariff, payment.id, operationType);
console.log(payment);
if (payment && response) {
return payment?.confirmation.confirmation_token;
} else {
return null
}
} catch (error) {
return null
}
/* try {
const payment = await checkout.createPayment(createPayload, idempotenceKey);
const response = await makePaymentOperation(userEmail, tariff, payment.id, operationType);
if (response && payment) {
@@ -75,7 +93,7 @@ export async function yooKasaCreatePayment(amount: number, tariff: number, opera
}
} catch (error) {
return null
}
} */
}
export async function fetchPaymentsHistory() {