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!
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
export interface IBspb {
|
||||
order: {
|
||||
id: number
|
||||
hppUrl: string
|
||||
password: string
|
||||
accessToken: string
|
||||
status: string
|
||||
cvv2AuthStatus: string
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
export interface GeoPosition {
|
||||
latitude: number
|
||||
longitude: number
|
||||
}
|
||||
|
||||
export interface PvzAddress {
|
||||
apartment: string
|
||||
building: string
|
||||
comment: string
|
||||
country: string
|
||||
full_address: string
|
||||
geoId: number
|
||||
house: string
|
||||
housing: string
|
||||
locality: string
|
||||
postal_code: string
|
||||
region: string
|
||||
street: string
|
||||
subRegion: string
|
||||
}
|
||||
|
||||
export interface Contact {
|
||||
phone: string
|
||||
}
|
||||
|
||||
export interface TimeObject {
|
||||
hours: number
|
||||
minutes: number
|
||||
}
|
||||
|
||||
export interface ScheduleRestriction {
|
||||
days: number[]
|
||||
time_from: TimeObject
|
||||
time_to: TimeObject
|
||||
}
|
||||
|
||||
export interface Schedule {
|
||||
time_zone: number
|
||||
restrictions: ScheduleRestriction[]
|
||||
}
|
||||
|
||||
export interface PickupServices {
|
||||
is_fitting_allowed: boolean
|
||||
is_partial_refuse_allowed: boolean
|
||||
is_paperless_pickup_allowed: boolean
|
||||
is_unboxing_allowed: boolean
|
||||
}
|
||||
|
||||
export interface PickupPoint {
|
||||
id: string
|
||||
operator_station_id: string
|
||||
operator_id: string
|
||||
name: string
|
||||
type: 'pickup_point'
|
||||
address: PvzAddress
|
||||
position: GeoPosition
|
||||
instruction: string
|
||||
available_for_dropoff: boolean
|
||||
available_for_c2c_dropoff: boolean
|
||||
contact: Contact
|
||||
schedule: Schedule
|
||||
pickup_services: PickupServices
|
||||
payment_methods: string[]
|
||||
is_dark_store: boolean
|
||||
is_market_partner: boolean
|
||||
is_post_office: boolean
|
||||
is_yandex_branded: boolean
|
||||
dayoffs: any[]
|
||||
deactivation_date: string | null
|
||||
deactivation_date_predicted_debt: string | null
|
||||
}
|
||||
|
||||
export interface YandexPvzResponse extends PickupPoint {
|
||||
points: PickupPoint[]
|
||||
}
|
||||
Reference in New Issue
Block a user