This commit is contained in:
38
server/api/bsbp_create.ts
Normal file
38
server/api/bsbp_create.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import type { BsbpCreateRequest, BsbpCreateResponse } from '#shared/bsbp_create'
|
||||
import https from 'node:https'
|
||||
import axios from 'axios'
|
||||
import { defineEventHandler, readBody } from 'h3'
|
||||
|
||||
export default defineEventHandler(async (event): Promise<BsbpCreateResponse | { error: string }> => {
|
||||
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<BsbpCreateRequest>(event)
|
||||
|
||||
try {
|
||||
const response = await axios.post<BsbpCreateResponse>(`${apiUrl}/order`, orderData, {
|
||||
httpsAgent: agent,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Basic ${Buffer.from(`TerminalSys/${merchantId}:${merchantPassword}`).toString('base64')}`,
|
||||
},
|
||||
})
|
||||
|
||||
return response.data
|
||||
}
|
||||
catch (e: any) {
|
||||
return { error: e?.message ?? 'Unknown BSPB error' }
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -1,32 +0,0 @@
|
||||
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 || []
|
||||
})
|
||||
@@ -1,9 +1,10 @@
|
||||
import type { WooOrderCreateRequest, WooOrderCreateResponse } from '#shared/woo_orders_create'
|
||||
import axios from 'axios'
|
||||
import { defineEventHandler, readBody } from 'h3'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
export default defineEventHandler(async (event): Promise<WooOrderCreateResponse | { error: string }> => {
|
||||
try {
|
||||
const orderData = await readBody(event)
|
||||
const orderData = await readBody<WooOrderCreateRequest>(event)
|
||||
|
||||
const requestUrl = 'https://wp.koptilnya.xyz/wp-json/wc/v3/orders'
|
||||
const consumerKey = 'ck_8b5477a1573ce6038ef1367f25d95cede1de4559'
|
||||
@@ -11,7 +12,7 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
const encodedAuth = Buffer.from(`${consumerKey}:${consumerSecret}`).toString('base64')
|
||||
|
||||
const response = await axios.post(requestUrl, orderData, {
|
||||
const response = await axios.post<WooOrderCreateResponse>(requestUrl, orderData, {
|
||||
headers: {
|
||||
'Authorization': `Basic ${encodedAuth}`,
|
||||
'Content-Type': 'application/json',
|
||||
@@ -1,13 +1,14 @@
|
||||
import type { YandexLocationDetectRequest, YandexLocationDetectResponse } from '#shared/yandex_location_detect'
|
||||
import axios from 'axios'
|
||||
import { defineEventHandler, readBody } from 'h3'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
export default defineEventHandler(async (event): Promise<YandexLocationDetectResponse | { error: string }> => {
|
||||
try {
|
||||
const data = await readBody(event)
|
||||
const data = await readBody<YandexLocationDetectRequest>(event)
|
||||
const apiUrl = import.meta.env.VITE_YANDEX_B2B_BASE_URL!
|
||||
const token = import.meta.env.VITE_YANDEX_B2B_TOKEN!
|
||||
|
||||
const response = await axios.post(
|
||||
const response = await axios.post<YandexLocationDetectResponse>(
|
||||
`${apiUrl}/location/detect`,
|
||||
{
|
||||
location: data?.location,
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { YandexPvzResponse } from '~/server/shared/types/yandex_pvz'
|
||||
import type { YandexPvzRequest, YandexPvzResponse } from '#shared/yandex_pvz'
|
||||
import axios from 'axios'
|
||||
import { defineEventHandler, readBody } from 'h3'
|
||||
|
||||
export default defineEventHandler(async (event): Promise<YandexPvzResponse | { error: string }> => {
|
||||
try {
|
||||
const data = await readBody(event)
|
||||
const data = await readBody<YandexPvzRequest>(event)
|
||||
const apiUrl = import.meta.env.VITE_YANDEX_B2B_BASE_URL!
|
||||
const token = import.meta.env.VITE_YANDEX_B2B_TOKEN!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user