33 lines
986 B
TypeScript
33 lines
986 B
TypeScript
import https from 'node:https'
|
|
import axios from 'axios'
|
|
import { defineEventHandler, readBody } from 'h3'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
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 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 || []
|
|
})
|