<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
import json
from frappe import _
from frappe.model.document import Document
from frappe.utils import get_request_session
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.doctype.shopify_log.shopify_log import make_shopify_log

class ShopifySettings(Document):
	def validate(self):
		if self.enable_shopify == 1:
			setup_custom_fields()
			self.validate_access_credentials()
			self.register_webhooks()
		else:
			self.unregister_webhooks()

	def validate_access_credentials(self):
		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 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/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)<commit_msg>fix: default private app type<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
import json
from frappe import _
from frappe.model.document import Document
from frappe.utils import get_request_session
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.doctype.shopify_log.shopify_log import make_shopify_log

class ShopifySettings(Document):
	def validate(self):
		if self.enable_shopify == 1:
			setup_custom_fields()
			self.validate_access_credentials()
			self.register_webhooks()
		else:
			self.unregister_webhooks()

	def validate_access_credentials(self):
		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)

	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/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)
{'fraction_non_alphanumeric': 0.09230277866496327, 'fraction_numerical': 0.0076652826572979876, 'mean_word_length': 5.635593220338983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2894645', 'n_tokens_mistral': 1062, 'n_tokens_neox': 997, 'n_words': 242}