diff --git a/src/controller/webhook.controller.ts b/src/controller/webhook.controller.ts index 312ea6e..28ab2e6 100644 --- a/src/controller/webhook.controller.ts +++ b/src/controller/webhook.controller.ts @@ -14,9 +14,7 @@ import { SiteService } from '../service/site.service'; import { OrderService } from '../service/order.service'; import { SiteApiService } from '../service/site-api.service'; -import { - UnifiedOrderDTO, -} from '../dto/site-api.dto'; + @Controller('/webhook') export class WebhookController { @@ -192,76 +190,4 @@ export class WebhookController { } } - - - @Post('/shoppy') - async handleShoppyWebhook( - @Body() body: any, - @Query('siteId') siteIdStr: string, - @Query('signature') signature: string, - @Headers() header: any - ) { - console.log(`webhook shoppy`, siteIdStr, body, header) - const topic = header['x-oemsaas-event-type']; - // const source = header['x-oemsaas-shop-domain']; - const siteId = Number(siteIdStr); - - if (!signature) { - return { - code: HttpStatus.BAD_REQUEST, - success: false, - message: 'Signature missing', - }; - } - - //shopyy 无法提供加密字段校验,注释校验逻辑 - // const rawBody = this.ctx.request.rawBody; - // const hash = crypto - // .createHmac('sha256', this.secret) - // .update(rawBody) - // .digest('base64'); - const adapter = await this.siteApiService.getAdapter(siteId); - try { - if (this.secret === signature) { - switch (topic) { - case 'product.created': - case 'product.updated': - // 不再写入本地,平台事件仅确认接收 - break; - case 'product.deleted': - // 不再写入本地,平台事件仅确认接收 - break; - case 'orders/create': - case 'orders/update': - const order = adapter.mapOrder(body) - await this.orderService.syncSingleOrder(siteId, order); - break; - case 'orders/delete': - break; - case 'customer.created': - break; - case 'customer.updated': - break; - case 'customer.deleted': - break; - default: - console.log('Unhandled event:', topic); - } - - return { - code: 200, - success: true, - message: 'Webhook processed successfully', - }; - } else { - return { - code: 403, - success: false, - message: 'Webhook verification failed', - }; - } - } catch (error) { - console.log(error); - } - } }