Никита Круглицкий adc347e86b
Some checks failed
Deploy / build (push) Failing after 32s
keys
2025-10-05 17:36:45 +06:00

41 lines
1.1 KiB
TypeScript

import fs from 'node:fs'
import https from 'node:https'
import path from 'node:path'
import axios from 'axios'
import { defineEventHandler } from 'h3'
import bspbKey from '@/server/cert/pgtest_key.key?raw'
import bspbCert from '@/server/cert/pgtest_cer_2025.pem?raw'
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 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
})