def post_shopify_webhook(self, topic = None, domain = None, data = None, headers = None, send_hmac = True):
"""
Simulate a webhook being sent to the application's webhook endpoint with the provided parameters.
"""
# Set defaults.
domain = 'test.myshopify.com' if domain is None else domain
data = {} if data is None else data
headers = {} if headers is None else headers
# Dump data as a JSON string.
data = json.dumps(data)
# Add required headers.
headers['HTTP_X_SHOPIFY_TEST'] = 'true'
headers['HTTP_X_SHOPIFY_SHOP_DOMAIN'] = domain
# Add optional headers.
if topic:
headers['HTTP_X_SHOPIFY_TOPIC'] = topic
if send_hmac:
headers['HTTP_X_SHOPIFY_HMAC_SHA256'] = six.text_type(get_hmac(six.b(data), settings.SHOPIFY_APP_API_SECRET))
return self.client.post(self.webhook_url, data = data, content_type = 'application/json', **headers)
评论列表
文章目录