alsaze 2984e3780a
All checks were successful
Deploy / build (push) Successful in 11m3s
карты пвз
2025-11-19 21:12:47 +03:00

33 lines
998 B
TypeScript

import https from 'node:https'
import axios from 'axios'
import { defineEventHandler, readBody } from 'h3'
export default defineEventHandler(async (event) => {
const merchantId = import.meta.env.BSPB_MERCHANT_ID!
const merchantPassword = import.meta.env.BSPB_MERCHANT_PASSWORD!
const apiUrl = import.meta.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 orderData = await readBody(event)
const response = await axios.post(`${apiUrl}/order`, orderData, {
httpsAgent: agent,
headers: {
'Content-Type': 'application/json',
'Authorization': `Basic ${Buffer.from(`TerminalSys/${merchantId}:${merchantPassword}`).toString('base64')}`,
},
})
return response?.data || []
})