From 6c6940052eb8d480fc6719819c06a964dc0827dc Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 20 May 2025 13:21:30 +0700 Subject: webhook ginee and api detail orders --- fixco_api/controllers/api_v1/__init__.py | 1 + fixco_api/controllers/api_v1/webhook_ginee.py | 33 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 fixco_api/controllers/api_v1/webhook_ginee.py (limited to 'fixco_api') diff --git a/fixco_api/controllers/api_v1/__init__.py b/fixco_api/controllers/api_v1/__init__.py index 30fb10d..9f31c58 100644 --- a/fixco_api/controllers/api_v1/__init__.py +++ b/fixco_api/controllers/api_v1/__init__.py @@ -1,2 +1,3 @@ from . import partner from . import sale +from . import webhook_ginee diff --git a/fixco_api/controllers/api_v1/webhook_ginee.py b/fixco_api/controllers/api_v1/webhook_ginee.py new file mode 100644 index 0000000..dbb8bcd --- /dev/null +++ b/fixco_api/controllers/api_v1/webhook_ginee.py @@ -0,0 +1,33 @@ +from odoo import http +import json +import logging +from datetime import datetime + +_logger = logging.getLogger(__name__) + +class WebhookController(http.Controller): + @http.route('/webhook/order', type='json', auth='public', methods=['POST'], csrf=False) + def handle_webhook(self): + data = http.request.jsonrequest + _logger.info("Data webhook diterima: %s", data) + + try: + # Simpan data JSON ke model webhook.ginee + webhook_record = http.request.env['webhook.ginee'].create({ + 'json_ginee': json.dumps(data) # Konversi dict ke string JSON + }) + + _logger.info("Data berhasil disimpan dengan ID: %s", webhook_record.id) + + return { + 'status': 'success', + 'message': 'Webhook berhasil diproses', + 'record_id': webhook_record.id + } + + except Exception as e: + _logger.error("Gagal memproses webhook: %s", str(e)) + return { + 'status': 'error', + 'message': str(e) + } \ No newline at end of file -- cgit v1.2.3