fix: shopify integration
This commit is contained in:
parent
201bcaf2ca
commit
f380b215b2
File diff suppressed because it is too large
Load Diff
@ -21,32 +21,26 @@ class ShopifySettings(Document):
|
||||
else:
|
||||
self.unregister_webhooks()
|
||||
|
||||
self.validate_app_type()
|
||||
|
||||
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):
|
||||
frappe.msgprint(_("Missing value for Password, API Key or Shopify URL"), raise_exception=frappe.ValidationError)
|
||||
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)
|
||||
|
||||
else:
|
||||
if not (self.access_token and self.shopify_url):
|
||||
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):
|
||||
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]
|
||||
|
||||
url = get_shopify_url('admin/api/2019-04/webhooks.json', self)
|
||||
print('url', url)
|
||||
for method in webhooks:
|
||||
if method in created_webhooks:
|
||||
continue
|
||||
|
||||
session = get_request_session()
|
||||
print('session', session)
|
||||
try:
|
||||
d = session.post(url, data=json.dumps({
|
||||
"webhook": {
|
||||
@ -55,6 +49,7 @@ class ShopifySettings(Document):
|
||||
"format": "json"
|
||||
}
|
||||
}), headers=get_header(self))
|
||||
print('d', d.json())
|
||||
d.raise_for_status()
|
||||
self.update_webhook_table(method, d.json())
|
||||
except Exception as e:
|
||||
@ -77,6 +72,7 @@ class ShopifySettings(Document):
|
||||
self.remove(d)
|
||||
|
||||
def update_webhook_table(self, method, res):
|
||||
print('update')
|
||||
self.append("webhooks", {
|
||||
"webhook_id": res['webhook']['id'],
|
||||
"method": method
|
||||
@ -84,6 +80,7 @@ class ShopifySettings(Document):
|
||||
|
||||
def get_shopify_url(path, settings):
|
||||
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)
|
||||
else:
|
||||
return 'https://{}/{}'.format(settings.shopify_url, path)
|
||||
|
Loading…
x
Reference in New Issue
Block a user