Version Notes
Updated version
Download this release
Release Info
| Developer | Magento Core Team |
| Extension | Cyclr_Webhook |
| Version | 1.0.2 |
| Comparing to | |
| See all releases | |
Version 1.0.2
app/code/community/Cyclr/Webhook/Helper/Data.php
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Cyclr_Webhook_Helper_Data extends Mage_Core_Helper_Abstract
|
| 3 |
+
{
|
| 4 |
+
}
|
app/code/community/Cyclr/Webhook/Model/Observer.php
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Cyclr_Webhook_Model_Observer
|
| 3 |
+
{
|
| 4 |
+
public function handleCustomerRegister(Varien_Event_Observer $observer)
|
| 5 |
+
{
|
| 6 |
+
$customer = $observer->getEvent()->getCustomer();
|
| 7 |
+
$email = $customer->getEmail();
|
| 8 |
+
$url = Mage::getStoreConfig('webhook/newcustomer/url', $customer->getSendemailStoreId());
|
| 9 |
+
|
| 10 |
+
// set the customer to be a new object
|
| 11 |
+
$customer->isObjectNew(true);
|
| 12 |
+
|
| 13 |
+
//$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
|
| 14 |
+
//if ($subscriber->getId()) {
|
| 15 |
+
//$json = Mage::helper('core')->jsonEncode($customer->getData());
|
| 16 |
+
$json = Mage::helper('core')->jsonEncode(array(
|
| 17 |
+
'entity_id' => $customer->getData('entity_id'),
|
| 18 |
+
'email' => $customer->getData('email'),
|
| 19 |
+
'firstname' => $customer->getData('firstname'),
|
| 20 |
+
'lastname' => $customer->getData('lastname'),
|
| 21 |
+
'is_subscribed' => $customer->getData('is_subscribed'),
|
| 22 |
+
'created_at' => $customer->getData('created_at'),
|
| 23 |
+
'updated_at' => $customer->getData('updated_at')
|
| 24 |
+
));
|
| 25 |
+
|
| 26 |
+
$client = new Varien_Http_Client();
|
| 27 |
+
$client->setUri($url)
|
| 28 |
+
->setMethod('POST');
|
| 29 |
+
$client->setHeaders('Content-type','application/json;charset=UTF-8');
|
| 30 |
+
$client->setRawData($json); // not pretty
|
| 31 |
+
$response = $client->request();
|
| 32 |
+
|
| 33 |
+
// if not response 200, then log a message
|
| 34 |
+
if(!$response->isSuccessful()) {
|
| 35 |
+
Mage::log("POST customer register request failed for {$email} to {$url}", null, "cyclr-webhook.log");
|
| 36 |
+
}
|
| 37 |
+
//}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
public function handleCustomerSave(Varien_Event_Observer $observer)
|
| 41 |
+
{
|
| 42 |
+
$customer = $observer->getEvent()->getCustomer();
|
| 43 |
+
$email = $customer->getEmail();
|
| 44 |
+
$url = Mage::getStoreConfig('webhook/existingcustomer/url', $customer->getSendemailStoreId());
|
| 45 |
+
|
| 46 |
+
//$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
|
| 47 |
+
if (!$customer.isObjectNew()) {
|
| 48 |
+
//$json = Mage::helper('core')->jsonEncode($customer->getData());
|
| 49 |
+
$json = Mage::helper('core')->jsonEncode(array(
|
| 50 |
+
'entity_id' => $customer->getData('entity_id'),
|
| 51 |
+
'email' => $customer->getData('email'),
|
| 52 |
+
'firstname' => $customer->getData('firstname'),
|
| 53 |
+
'lastname' => $customer->getData('lastname'),
|
| 54 |
+
'is_subscribed' => $customer->getData('is_subscribed'),
|
| 55 |
+
'created_at' => $customer->getData('created_at'),
|
| 56 |
+
'updated_at' => $customer->getData('updated_at')
|
| 57 |
+
));
|
| 58 |
+
|
| 59 |
+
$client = new Varien_Http_Client();
|
| 60 |
+
$client->setUri($url)
|
| 61 |
+
->setMethod('POST');
|
| 62 |
+
$client->setHeaders('Content-type','application/json;charset=UTF-8');
|
| 63 |
+
$client->setRawData($json); // not pretty
|
| 64 |
+
$response = $client->request();
|
| 65 |
+
|
| 66 |
+
// if not response 200, then log a message
|
| 67 |
+
if(!$response->isSuccessful()) {
|
| 68 |
+
Mage::log("POST customer save request failed for {$email} to {$url}", null, "cyclr-webhook.log");
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
}
|
app/code/community/Cyclr/Webhook/Model/Url.php
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Cyclr_Webhook_Model_Url extends Mage_Core_Model_Config_Data
|
| 3 |
+
{
|
| 4 |
+
public function save()
|
| 5 |
+
{
|
| 6 |
+
$url = $this->getValue();
|
| 7 |
+
$cyclrUrl = 'https://my.cyclr.com/';
|
| 8 |
+
|
| 9 |
+
// validate the URL
|
| 10 |
+
if (!(substr($url, 0, strlen($cyclrUrl)) === $cyclrUrl)) {
|
| 11 |
+
Mage::throwException('Invalid webhook URL. You should only use webhooks generated on Cyclr.');
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
return parent::save();
|
| 15 |
+
}
|
| 16 |
+
}
|
app/code/community/Cyclr/Webhook/etc/config.xml
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Cyclr_Webhook>
|
| 5 |
+
<version>1.0.2</version>
|
| 6 |
+
</Cyclr_Webhook>
|
| 7 |
+
</modules>
|
| 8 |
+
<global>
|
| 9 |
+
<models>
|
| 10 |
+
<webhook>
|
| 11 |
+
<class>Cyclr_Webhook_Model</class>
|
| 12 |
+
</webhook>
|
| 13 |
+
</models>
|
| 14 |
+
<events>
|
| 15 |
+
<customer_register_success>
|
| 16 |
+
<observers>
|
| 17 |
+
<webhook>
|
| 18 |
+
<class>Cyclr_Webhook_Model_Observer</class>
|
| 19 |
+
<method>handleCustomerRegister</method>
|
| 20 |
+
<type>singleton</type>
|
| 21 |
+
</webhook>
|
| 22 |
+
</observers>
|
| 23 |
+
</customer_register_success>
|
| 24 |
+
<customer_save_before>
|
| 25 |
+
<observers>
|
| 26 |
+
<webhook>
|
| 27 |
+
<class>Cyclr_Webhook_Model_Observer</class>
|
| 28 |
+
<method>handleCustomerSave</method>
|
| 29 |
+
<type>singleton</type>
|
| 30 |
+
</webhook>
|
| 31 |
+
</observers>
|
| 32 |
+
</customer_save_before>
|
| 33 |
+
</events>
|
| 34 |
+
<helpers>
|
| 35 |
+
<webhook>
|
| 36 |
+
<class>Cyclr_Webhook_Helper</class>
|
| 37 |
+
</webhook>
|
| 38 |
+
</helpers>
|
| 39 |
+
</global>
|
| 40 |
+
<adminhtml>
|
| 41 |
+
<acl>
|
| 42 |
+
<resources>
|
| 43 |
+
<admin>
|
| 44 |
+
<children>
|
| 45 |
+
<system>
|
| 46 |
+
<children>
|
| 47 |
+
<config>
|
| 48 |
+
<children>
|
| 49 |
+
<webhook>
|
| 50 |
+
<title>Cylr Extensions to Magento</title>
|
| 51 |
+
</webhook>
|
| 52 |
+
</children>
|
| 53 |
+
</config>
|
| 54 |
+
</children>
|
| 55 |
+
</system>
|
| 56 |
+
</children>
|
| 57 |
+
</admin>
|
| 58 |
+
</resources>
|
| 59 |
+
</acl>
|
| 60 |
+
</adminhtml>
|
| 61 |
+
</config>
|
app/code/community/Cyclr/Webhook/etc/system.xml
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<config>
|
| 3 |
+
<tabs>
|
| 4 |
+
<cyclr_webhook translate="label" module="webhook">
|
| 5 |
+
<label>Cyclr</label>
|
| 6 |
+
<sort_order>99999</sort_order>
|
| 7 |
+
</cyclr_webhook>
|
| 8 |
+
</tabs>
|
| 9 |
+
<sections>
|
| 10 |
+
<webhook translate="label" module="webhook">
|
| 11 |
+
<label>Cyclr Settings</label>
|
| 12 |
+
<tab>cyclr_webhook</tab>
|
| 13 |
+
<frontend_type>text</frontend_type>
|
| 14 |
+
<sort_order>1000</sort_order>
|
| 15 |
+
<show_in_default>1</show_in_default>
|
| 16 |
+
<show_in_website>1</show_in_website>
|
| 17 |
+
<show_in_store>1</show_in_store>
|
| 18 |
+
<groups>
|
| 19 |
+
<newcustomer translate="label">
|
| 20 |
+
<label>Customer Create Webhook</label>
|
| 21 |
+
<frontend_type>text</frontend_type>
|
| 22 |
+
<sort_order>1</sort_order>
|
| 23 |
+
<show_in_default>1</show_in_default>
|
| 24 |
+
<show_in_website>1</show_in_website>
|
| 25 |
+
<show_in_store>1</show_in_store>
|
| 26 |
+
<fields>
|
| 27 |
+
<url>
|
| 28 |
+
<label>URL</label>
|
| 29 |
+
<frontend_type>text</frontend_type>
|
| 30 |
+
<backend_model>webhook/url</backend_model>
|
| 31 |
+
<sort_order>1</sort_order>
|
| 32 |
+
<show_in_default>1</show_in_default>
|
| 33 |
+
<show_in_website>1</show_in_website>
|
| 34 |
+
<show_in_store>1</show_in_store>
|
| 35 |
+
<comment><![CDATA[This URL is notified when a customer is created. Customer information, including their newsletter subscription settings, is posted to the URL.]]></comment>
|
| 36 |
+
</url>
|
| 37 |
+
</fields>
|
| 38 |
+
</newcustomer>
|
| 39 |
+
<existingcustomer translate="label">
|
| 40 |
+
<label>Customer Update Webhook</label>
|
| 41 |
+
<frontend_type>text</frontend_type>
|
| 42 |
+
<sort_order>2</sort_order>
|
| 43 |
+
<show_in_default>1</show_in_default>
|
| 44 |
+
<show_in_website>1</show_in_website>
|
| 45 |
+
<show_in_store>1</show_in_store>
|
| 46 |
+
<fields>
|
| 47 |
+
<url>
|
| 48 |
+
<label>URL</label>
|
| 49 |
+
<frontend_type>text</frontend_type>
|
| 50 |
+
<backend_model>webhook/url</backend_model>
|
| 51 |
+
<sort_order>1</sort_order>
|
| 52 |
+
<show_in_default>1</show_in_default>
|
| 53 |
+
<show_in_website>1</show_in_website>
|
| 54 |
+
<show_in_store>1</show_in_store>
|
| 55 |
+
<comment><![CDATA[This URL is notified when a customer is updated. Customer information, including their newsletter subscription settings, is posted to the URL.]]></comment>
|
| 56 |
+
</url>
|
| 57 |
+
</fields>
|
| 58 |
+
</existingcustomer>
|
| 59 |
+
</groups>
|
| 60 |
+
</webhook>
|
| 61 |
+
</sections>
|
| 62 |
+
</config>
|
package.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>Cyclr_Webhook</name>
|
| 4 |
+
<version>1.0.2</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license/>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>Cyclr webhook integration</summary>
|
| 10 |
+
<description>Provides integration between Magento and Cyclr</description>
|
| 11 |
+
<notes>Updated version</notes>
|
| 12 |
+
<authors><author><name>CyclrDevs</name><user>auto-converted</user><email>devs@cyclr.com</email></author></authors>
|
| 13 |
+
<date>2015-12-16</date>
|
| 14 |
+
<time>13:01:02</time>
|
| 15 |
+
<contents><target name="magecommunity"><dir name="Cyclr"><dir name="Webhook"><dir name="Helper"><file name="Data.php" hash="8e2ef78dc0c9bb9a7325459c388121e2"/></dir><dir name="Model"><file name="Observer.php" hash="5792b6624a0f6ac65ebcdf4c1f0234c4"/><file name="Url.php" hash="fb01bf252735a229cba0834ec6ee3191"/></dir><dir name="etc"><file name="config.xml" hash="e031ba25ea8d0ef5c7a4a49f2a35f10b"/><file name="system.xml" hash="8933f8849a1685dba5e08b669429db14"/></dir></dir></dir></target></contents>
|
| 16 |
+
<compatible/>
|
| 17 |
+
<dependencies/>
|
| 18 |
+
</package>
|
