This commit is contained in:
@@ -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
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user