alsaze dd7abe1fc6
All checks were successful
Deploy / build (push) Successful in 45s
создаю телегу товаров
2025-10-05 15:54:16 +03:00

42 lines
1.2 KiB
TypeScript

import https from 'node:https'
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 assetsStorage = useStorage('assets:server')
const bspbKey = await assetsStorage.getItem<string>('pgtest_key.key')
const bspbCert = await assetsStorage.getItem<string>('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: 'Описание заказа',
hppRedirectUrl: 'https://pgtest.bspb.ru/result',
},
}
const response = await axios.post(`${apiUrl}/order`, data, {
httpsAgent: agent,
headers: {
'Content-Type': 'application/json',
'Authorization': `Basic ${Buffer.from(`TerminalSys/${merchantId}:${merchantPassword}`).toString('base64')}`,
},
})
return response?.data || []
})