def dump_request_data(data, event="create/order"): event_mapper = { "orders/create": get_webhook_address(connector_name='shopify_connection', method="sync_sales_order", exclude_uri=True), "orders/paid": get_webhook_address(connector_name='shopify_connection', method="prepare_sales_invoice", exclude_uri=True), "orders/fulfilled": get_webhook_address(connector_name='shopify_connection', method="prepare_delivery_note", exclude_uri=True) } log = frappe.get_doc({ "doctype": "Shopify Log", "request_data": json.dumps(data, indent=1), "method": event_mapper[event] }).insert(ignore_permissions=True) frappe.db.commit() frappe.enqueue(method=event_mapper[event], queue='short', timeout=300, is_async=True, **{ "order": data, "request_id": log.name })
def register_webhooks(self): webhooks = ["orders/create", "orders/paid", "orders/fulfilled"] # url = get_shopify_url('admin/webhooks.json', self) created_webhooks = [d.method for d in self.webhooks] url = get_shopify_url('admin/api/2020-04/webhooks.json', self) for method in webhooks: session = get_request_session() try: res = session.post( url, data=json.dumps({ "webhook": { "topic": method, "address": get_webhook_address( connector_name='shopify_connection', method='store_request_data'), "format": "json" } }), headers=get_header(self)) res.raise_for_status() self.update_webhook_table(method, res.json()) except HTTPError as e: error_message = res.json().get('errors', e) make_shopify_log(status="Warning", exception=error_message, rollback=True) except Exception as e: make_shopify_log(status="Warning", exception=e, rollback=True)
def register_webhooks(self): webhooks = ["orders/create", "orders/paid", "orders/fulfilled"] url = get_shopify_url('admin/webhooks.json', self) created_webhooks = [d.method for d in self.webhooks] for method in webhooks: if method in created_webhooks: continue session = get_request_session() try: d = session.post( url, data=json.dumps({ "webhook": { "topic": method, "address": get_webhook_address( connector_name='shopify_connection', method='store_request_data'), "format": "json" } }), headers=get_header(self)) d.raise_for_status() self.update_webhook_table(method, d.json()) except Exception as e: make_shopify_log(status="Warning", message=e.message, exception=False)
def dump_request_data(data, event="create/order"): event_mapper = { "orders/create": get_webhook_address(connector_name='shopify_connection', method="sync_sales_order", exclude_uri=True), "orders/paid" : get_webhook_address(connector_name='shopify_connection', method="prepare_sales_invoice", exclude_uri=True), "orders/fulfilled": get_webhook_address(connector_name='shopify_connection', method="prepare_delivery_note", exclude_uri=True) } log = frappe.get_doc({ "doctype": "Shopify Log", "request_data": json.dumps(data, indent=1), "method": event_mapper[event] }).insert(ignore_permissions=True) frappe.db.commit() frappe.enqueue(method=event_mapper[event], queue='short', timeout=300, is_async=True, **{"order": data, "request_id": log.name})
def register_webhooks(self): webhooks = ["orders/create", "orders/paid", "orders/fulfilled"] url = get_shopify_url('admin/webhooks.json', self) created_webhooks = [d.method for d in self.webhooks] for method in webhooks: if method in created_webhooks: continue session = get_request_session() try: d = session.post(url, data=json.dumps({ "webhook": { "topic": method, "address": get_webhook_address(connector_name='shopify_connection', method='store_request_data'), "format": "json" } }), headers=get_header(self)) d.raise_for_status() self.update_webhook_table(method, d.json()) except Exception as e: make_shopify_log(status="Warning", message=e.message, exception=False)