fix: update shopify api version (#22284)
Co-authored-by: Saurabh <saurabh@erpnext.com>
This commit is contained in:
parent
c178013926
commit
53b601523b
@ -8,6 +8,7 @@ import json
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import get_request_session
|
from frappe.utils import get_request_session
|
||||||
|
from requests.exceptions import HTTPError
|
||||||
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
||||||
from erpnext.erpnext_integrations.utils import get_webhook_address
|
from erpnext.erpnext_integrations.utils import get_webhook_address
|
||||||
from erpnext.erpnext_integrations.doctype.shopify_log.shopify_log import make_shopify_log
|
from erpnext.erpnext_integrations.doctype.shopify_log.shopify_log import make_shopify_log
|
||||||
@ -29,19 +30,24 @@ class ShopifySettings(Document):
|
|||||||
webhooks = ["orders/create", "orders/paid", "orders/fulfilled"]
|
webhooks = ["orders/create", "orders/paid", "orders/fulfilled"]
|
||||||
# url = get_shopify_url('admin/webhooks.json', self)
|
# url = get_shopify_url('admin/webhooks.json', self)
|
||||||
created_webhooks = [d.method for d in self.webhooks]
|
created_webhooks = [d.method for d in self.webhooks]
|
||||||
url = get_shopify_url('admin/api/2019-04/webhooks.json', self)
|
url = get_shopify_url('admin/api/2020-04/webhooks.json', self)
|
||||||
for method in webhooks:
|
for method in webhooks:
|
||||||
session = get_request_session()
|
session = get_request_session()
|
||||||
try:
|
try:
|
||||||
d = session.post(url, data=json.dumps({
|
res = session.post(url, data=json.dumps({
|
||||||
"webhook": {
|
"webhook": {
|
||||||
"topic": method,
|
"topic": method,
|
||||||
"address": get_webhook_address(connector_name='shopify_connection', method='store_request_data'),
|
"address": get_webhook_address(connector_name='shopify_connection', method='store_request_data'),
|
||||||
"format": "json"
|
"format": "json"
|
||||||
}
|
}
|
||||||
}), headers=get_header(self))
|
}), headers=get_header(self))
|
||||||
d.raise_for_status()
|
res.raise_for_status()
|
||||||
self.update_webhook_table(method, d.json())
|
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:
|
except Exception as e:
|
||||||
make_shopify_log(status="Warning", exception=e, rollback=True)
|
make_shopify_log(status="Warning", exception=e, rollback=True)
|
||||||
|
|
||||||
@ -50,13 +56,18 @@ class ShopifySettings(Document):
|
|||||||
deleted_webhooks = []
|
deleted_webhooks = []
|
||||||
|
|
||||||
for d in self.webhooks:
|
for d in self.webhooks:
|
||||||
url = get_shopify_url('admin/api/2019-04/webhooks/{0}.json'.format(d.webhook_id), self)
|
url = get_shopify_url('admin/api/2020-04/webhooks/{0}.json'.format(d.webhook_id), self)
|
||||||
try:
|
try:
|
||||||
res = session.delete(url, headers=get_header(self))
|
res = session.delete(url, headers=get_header(self))
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
deleted_webhooks.append(d)
|
deleted_webhooks.append(d)
|
||||||
|
|
||||||
|
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:
|
except Exception as e:
|
||||||
frappe.log_error(message=frappe.get_traceback(), title=e)
|
frappe.log_error(message=e, title='Shopify Webhooks Issue')
|
||||||
|
|
||||||
for d in deleted_webhooks:
|
for d in deleted_webhooks:
|
||||||
self.remove(d)
|
self.remove(d)
|
||||||
@ -125,4 +136,3 @@ def setup_custom_fields():
|
|||||||
}
|
}
|
||||||
|
|
||||||
create_custom_fields(custom_fields)
|
create_custom_fields(custom_fields)
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ from erpnext.erpnext_integrations.doctype.shopify_settings.shopify_settings impo
|
|||||||
shopify_variants_attr_list = ["option1", "option2", "option3"]
|
shopify_variants_attr_list = ["option1", "option2", "option3"]
|
||||||
|
|
||||||
def sync_item_from_shopify(shopify_settings, item):
|
def sync_item_from_shopify(shopify_settings, item):
|
||||||
url = get_shopify_url("admin/api/2019-04/products/{0}.json".format(item.get("product_id")), shopify_settings)
|
url = get_shopify_url("admin/api/2020-04/products/{0}.json".format(item.get("product_id")), shopify_settings)
|
||||||
session = get_request_session()
|
session = get_request_session()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user