import * as UUID from 'uuid' import { makeError, replies } from '@oyst/utils' import Merchant from '../../models/merchant' import { headers } from '../../validators/headers' import log from '../../lib/log' import merchantHandler from '../../handlers/merchant' import { orderSession } from '../../sessions' import { authorize as payload } from '../../validators/orders' import phoneChecker from '@oyst/phone-checker-lambda' const { error, success } = replies export default { config: { pre: [merchantHandler], validate: { headers, payload } }, handler: async (req, reply) => { try { const id = UUID.v4() const merchant: Merchant = req.pre.merchant if (merchant.error) { return error(makeError(merchant.error), reply) } await merchant.sign({ id }) await orderSession.setData(id, req.payload) const url = merchant.getUrl(req.payload.version) success({ url }, reply) phoneChecker.warmUp() } catch (err) { log({ errAuthOrder: err }) error(makeError(err), reply) } }, method: 'POST', path: '/v1/orders/authorize' }