создаю телегу товаров
Some checks failed
Deploy / build (push) Has been cancelled

This commit is contained in:
alsaze
2025-10-05 14:20:38 +03:00
parent 2c80b7095e
commit 66bda5d0c7
6 changed files with 166 additions and 6 deletions

View File

@@ -1,5 +1,41 @@
export default defineEventHandler((event) => {
return {
hello: 'world',
import fs from 'node:fs'
import https from 'node:https'
import path from 'node:path'
import axios from 'axios'
import { defineEventHandler } from 'h3'
export default defineEventHandler(async () => {
const merchantId = process.env.BSPB_MERCHANT_ID!
const merchantPassword = process.env.BSPB_MERCHANT_PASSWORD!
const apiUrl = process.env.BSPB_API_URL!
// читаем сертификаты из файлов
const bspbKey = fs.readFileSync(path.resolve('server/cert/pgtest_key.key'))
const bspbCert = fs.readFileSync(path.resolve('server/cert/pgtest_cer_2025.pem'))
const agent = new https.Agent({
key: bspbKey,
cert: bspbCert,
rejectUnauthorized: false, // ⚠️ только для теста!
})
const data = {
order: {
typeRid: 'Purchase',
amount: 100,
currency: 'RUB',
title: 'Название заказа',
description: 'Описание заказа',
},
}
const response = await axios.post(`${apiUrl}/order`, data, {
httpsAgent: agent,
headers: {
'Content-Type': 'application/json',
'Authorization': `Basic ${Buffer.from(`${merchantId}:${merchantPassword}`).toString('base64')}`,
},
})
return response.data
})