mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
fix: shopify integration
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -21,32 +21,26 @@ class ShopifySettings(Document):
|
|||||||
else:
|
else:
|
||||||
self.unregister_webhooks()
|
self.unregister_webhooks()
|
||||||
|
|
||||||
self.validate_app_type()
|
|
||||||
|
|
||||||
def validate_access_credentials(self):
|
def validate_access_credentials(self):
|
||||||
if self.app_type == "Private":
|
if not (self.get_password(raise_exception=False) and self.api_key and self.shopify_url):
|
||||||
if not (self.get_password(raise_exception=False) and self.api_key and self.shopify_url):
|
frappe.msgprint(_("Missing value for Password, API Key or Shopify URL"), raise_exception=frappe.ValidationError)
|
||||||
frappe.msgprint(_("Missing value for Password, API Key or Shopify URL"), raise_exception=frappe.ValidationError)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if not (self.access_token and self.shopify_url):
|
if not (self.access_token and self.shopify_url):
|
||||||
frappe.msgprint(_("Access token or Shopify URL missing"), raise_exception=frappe.ValidationError)
|
frappe.msgprint(_("Access token or Shopify URL missing"), raise_exception=frappe.ValidationError)
|
||||||
|
|
||||||
def validate_app_type(self):
|
|
||||||
if self.app_type == "Public":
|
|
||||||
frappe.throw(_("Support for public app is deprecated. Please setup private app, for more details refer user manual"))
|
|
||||||
|
|
||||||
def register_webhooks(self):
|
def register_webhooks(self):
|
||||||
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)
|
||||||
|
print('url', url)
|
||||||
for method in webhooks:
|
for method in webhooks:
|
||||||
if method in created_webhooks:
|
if method in created_webhooks:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
session = get_request_session()
|
session = get_request_session()
|
||||||
|
print('session', session)
|
||||||
try:
|
try:
|
||||||
d = session.post(url, data=json.dumps({
|
d = session.post(url, data=json.dumps({
|
||||||
"webhook": {
|
"webhook": {
|
||||||
@@ -55,6 +49,7 @@ class ShopifySettings(Document):
|
|||||||
"format": "json"
|
"format": "json"
|
||||||
}
|
}
|
||||||
}), headers=get_header(self))
|
}), headers=get_header(self))
|
||||||
|
print('d', d.json())
|
||||||
d.raise_for_status()
|
d.raise_for_status()
|
||||||
self.update_webhook_table(method, d.json())
|
self.update_webhook_table(method, d.json())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -77,6 +72,7 @@ class ShopifySettings(Document):
|
|||||||
self.remove(d)
|
self.remove(d)
|
||||||
|
|
||||||
def update_webhook_table(self, method, res):
|
def update_webhook_table(self, method, res):
|
||||||
|
print('update')
|
||||||
self.append("webhooks", {
|
self.append("webhooks", {
|
||||||
"webhook_id": res['webhook']['id'],
|
"webhook_id": res['webhook']['id'],
|
||||||
"method": method
|
"method": method
|
||||||
@@ -84,6 +80,7 @@ class ShopifySettings(Document):
|
|||||||
|
|
||||||
def get_shopify_url(path, settings):
|
def get_shopify_url(path, settings):
|
||||||
if settings.app_type == "Private":
|
if settings.app_type == "Private":
|
||||||
|
print(settings.api_key, settings.get_password('password'), settings.shopify_url, path)
|
||||||
return 'https://{}:{}@{}/{}'.format(settings.api_key, settings.get_password('password'), settings.shopify_url, path)
|
return 'https://{}:{}@{}/{}'.format(settings.api_key, settings.get_password('password'), settings.shopify_url, path)
|
||||||
else:
|
else:
|
||||||
return 'https://{}/{}'.format(settings.shopify_url, path)
|
return 'https://{}/{}'.format(settings.shopify_url, path)
|
||||||
|
|||||||
Reference in New Issue
Block a user