Sharemagnet_Social_Rebate - Version 1.0.0

Version Notes

This is first stable version.

Download this release

Release Info

Developer Ben Stewart
Extension Sharemagnet_Social_Rebate
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Sharemagnet/Social/Rebate/Block/Rebateorder.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ class Sharemagnet_Social_Rebate_Block_Rebateorder extends Mage_Checkout_Block_Onepage_Success {
3
+ public function getOrder() {
4
+ return Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
5
+ }
6
+ }
app/code/community/Sharemagnet/Social/Rebate/Helper/Data.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sharemagnet_Rebateorder
4
+ *
5
+ * This module was developed by Sharemagnet Company. If you require any
6
+ * support or have any questions please contact us at alexei.liyi@gmail.com.
7
+ *
8
+ * @category Sharemagnet
9
+ * @package Sharemagnet_Rebateorder
10
+ * @author Sharemagnet Company <alexei.liyi@gmail.com>
11
+ * @copyright Copyright (c) 2013 Alexei
12
+ */
13
+ class Sharemagnet_Social_Rebate_Helper_Data extends Mage_Core_Helper_Abstract {
14
+
15
+ }
app/code/community/Sharemagnet/Social/Rebate/Model/Observer.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sharemagnet_Social_Rebate_Model_Observer
4
+ {
5
+ /*
6
+ Resource name: rebate_session
7
+ Request method: POST
8
+ Endpoint URL: http://stg.sharemagnet.com/rest/v1/social-rebates/rebate_session/
9
+ Mime type: application/json
10
+ */
11
+ protected $_initSharemagnetApiUrl = 'http://sharemagnet.com/rest/v1/social-rebates/rebate_session/';
12
+
13
+ /*
14
+ Resource name: rebate_session
15
+ Request method: GET
16
+ Endpoint URL: http://stg.sharemagnet.com/rest/v1/social-rebates/rebate_session/<id>/
17
+ GET params:
18
+
19
+ magnet_key = ‘538441DA’
20
+ */
21
+ protected $_requestSharemagnetApiUrl = 'http://sharemagnet.com/rest/v1/social-rebates/rebate_session/';
22
+
23
+ /**
24
+ *
25
+ * Resource name: rebate_session_order
26
+ Request method: PUT
27
+ Endpoint URL: http://stg.sharemagnet.com/rest/v1/social-rebates/rebate_session_order/<order_id>/
28
+ GET params:
29
+
30
+ api_key = ‘c7c43d18154e8fa317f0d0b8ae76d321f97fd221’
31
+ api_secret = ‘0491c4c7f8e90ee93fd5b9e7be1b1d70a35374ca’
32
+ magnet_key = ‘538441DA’
33
+ backend = ‘magento’
34
+ PUT params:
35
+
36
+ order_verified (boolean)
37
+ *
38
+ *
39
+ */
40
+ protected $_verifySharemagnetApiUrl = 'http://sharemagnet.com/rest/v1/social-rebates/rebate_session_order/';
41
+
42
+ public function prepareService($event)
43
+ {
44
+ $order = $event->getOrder();
45
+ $orderId= $order->getId();
46
+ $orderEmail=$order->getCustomerEmail();
47
+ $purchase_amount = $order->getGrandTotal() - $order->getShippingAmount();
48
+ try
49
+ {
50
+ $restApiKey = $this->getRestApiKey();
51
+ $restApiSecret = $this->getRestApiSecret();
52
+ $restApiMagnet = $this->getRestMagnetKey();
53
+
54
+ if ($restApiKey !="" && $restApiSecret !="" & $restApiMagnet!="")
55
+ {
56
+ $client = new Zend_Http_Client();
57
+
58
+ // initialize api session
59
+ $client->setUri($this->_initSharemagnetApiUrl);
60
+
61
+
62
+ $arr=array('magnet_key'=>$restApiMagnet,'type'=>'magento','order_id'=>$orderId,'order_email'=>$orderEmail,'total_purchase'=>$purchase_amount);
63
+ $response=$client->setRawData(json_encode($arr), 'application/json')->request('POST');
64
+ $call_integration_url=$response->getHeader("Location")."?magnet_key=".$restApiMagnet."&format=json";
65
+ if ($response->getStatus()==201 && $response->getMessage()=="CREATED")
66
+ {
67
+ // $s = file_get_contents('http://stg.sharemagnet.com/rest/v1/social-rebates/rebate_session/1591/?magnet_key=538441DA&format=json');
68
+ //get existing api session
69
+ $client1 =new Zend_Http_Client();
70
+
71
+ // $UrI=$this->_requestSharemagnetApiUrl.$orderId."/";
72
+ // $client1->setConfig(array('adapter'=> 'Zend_Http_Client_Adapter_Curl'));
73
+ $client1->setUri($response->getHeader("Location"));
74
+ $client1->setParameterGet(array('magnet_key'=>$restApiMagnet,'format'=>'json'));
75
+
76
+ $response1 = $client1->request();
77
+ if ($response1->getStatus()==500 || $response1->getStatus()==501)
78
+ {
79
+
80
+ }
81
+ else
82
+ {
83
+ $responseBody1 = json_decode($response1->getBody());
84
+ $integration_code=$responseBody1->integration_code;
85
+ $offer_type=$responseBody1->offer_type;
86
+ $order_id=$responseBody1->order_id;
87
+ $order_email=$responseBody1->order_email;
88
+
89
+ Mage::getSingleton('core/session')->setIntegrationCode($integration_code);
90
+ /* */
91
+ Mage::getSingleton('core/session')->setOfferType($offer_type);
92
+ }
93
+ }
94
+ else
95
+ {
96
+
97
+ }
98
+ }
99
+ } catch (Exception $e) {
100
+ $debugData['result'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
101
+ $responseBody = '';
102
+ }
103
+
104
+ return $this;
105
+ }
106
+ public function getRestApiKey() {
107
+ return trim(Mage::getStoreConfig('social_rebate_section/social_rebate_group/social_rebate_apikey'));
108
+ }
109
+
110
+ public function getRestApiSecret() {
111
+ return trim(Mage::getStoreConfig('social_rebate_section/social_rebate_group/social_rebate_apisecret'));
112
+ }
113
+ public function getRestMagnetKey() {
114
+ return trim(Mage::getStoreConfig('social_rebate_section/social_rebate_group/social_rebate_magnetkey'));
115
+ }
116
+
117
+ }
118
+ ?>
app/code/community/Sharemagnet/Social/Rebate/Model/Order.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sharemagnet_Social_Rebate_Model_Order extends Mage_Sales_Model_Order
3
+ {
4
+ /**
5
+ *
6
+ * Resource name: rebate_session_order
7
+ Request method: PUT
8
+ Endpoint URL: http://stg.sharemagnet.com/rest/v1/social-rebates/rebate_session_order/<order_id>/
9
+ GET params:
10
+
11
+ api_key = ‘c7c43d18154e8fa317f0d0b8ae76d321f97fd221’
12
+ api_secret = ‘0491c4c7f8e90ee93fd5b9e7be1b1d70a35374ca’
13
+ magnet_key = ‘538441DA’
14
+ backend = ‘magento’
15
+ PUT params:
16
+
17
+ order_verified (boolean)
18
+ *
19
+ *
20
+ */
21
+ protected $_verifySharemagnetApiUrl = 'http://sharemagnet.com/rest/v1/social-rebates/rebate_session_order/';
22
+
23
+ protected function _beforeSave()
24
+ {
25
+ parent::_beforeSave();
26
+ if ($this->getState()==Mage_Sales_Model_Order::STATE_PROCESSING) //STATE_PROCESSING
27
+ {
28
+ $restApiKey = $this->getRestApiKey();
29
+ $restApiSecret = $this->getRestApiSecret();
30
+ $restApiMagnet = $this->getRestMagnetKey();
31
+ if ($restApiKey !="" && $restApiSecret !="" & $restApiMagnet!="")
32
+ {
33
+ $client1 =new Zend_Http_Client();
34
+
35
+ // $UrI=$this->_requestSharemagnetApiUrl.$orderId."/";
36
+ // $client1->setConfig(array('adapter'=> 'Zend_Http_Client_Adapter_Curl'));
37
+ $client1->setUri($this->_verifySharemagnetApiUrl.$this->getId().'/?api_key='.$restApiKey.'&api_secret='.$restApiSecret.'&magnet_key='.$restApiMagnet.'&backend=magento');
38
+
39
+
40
+ $arr1=array('order_verified'=>1);
41
+ $response=$client1->setRawData(json_encode($arr1), 'application/json')->request(Zend_Http_Client::PUT);
42
+
43
+
44
+ }
45
+ }
46
+
47
+ }
48
+ public function getRestApiKey() {
49
+ return trim(Mage::getStoreConfig('social_rebate_section/social_rebate_group/social_rebate_apikey'));
50
+ }
51
+
52
+ public function getRestApiSecret() {
53
+ return trim(Mage::getStoreConfig('social_rebate_section/social_rebate_group/social_rebate_apisecret'));
54
+ }
55
+ public function getRestMagnetKey() {
56
+ return trim(Mage::getStoreConfig('social_rebate_section/social_rebate_group/social_rebate_magnetkey'));
57
+ }
58
+ }
59
+ ?>
app/code/community/Sharemagnet/Social/Rebate/etc/config.xml ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Sharemagnet_Social_Rebate>
5
+ <version>1.5.0.0</version>
6
+ </Sharemagnet_Social_Rebate>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <social_rebate>
11
+ <class>Sharemagnet_Social_Rebate_Block</class>
12
+ </social_rebate>
13
+ </blocks>
14
+ <models>
15
+ <social_rebate>
16
+ <class>Sharemagnet_Social_Rebate_Model</class>
17
+ </social_rebate>
18
+ <sales>
19
+ <rewrite>
20
+ <order>Sharemagnet_Social_Rebate_Model_Order</order>
21
+ </rewrite>
22
+ </sales>
23
+ </models>
24
+ <helpers>
25
+ <social_rebate>
26
+ <class>Sharemagnet_Social_Rebate_Helper</class>
27
+ </social_rebate>
28
+ </helpers>
29
+ <events>
30
+ <sales_order_place_after>
31
+ <observers>
32
+ <prepare_sharemagent_service>
33
+ <type>singleton</type>
34
+ <class>Sharemagnet_Social_Rebate_Model_Observer</class>
35
+ <method>prepareService</method>
36
+ </prepare_sharemagent_service>
37
+ </observers>
38
+ </sales_order_place_after>
39
+ </events>
40
+ </global>
41
+ <frontend>
42
+ <layout>
43
+ <updates>
44
+ <social_rebate>
45
+ <file>sharemagnet/social/rebate.xml</file>
46
+ </social_rebate>
47
+ </updates>
48
+ </layout>
49
+
50
+ </frontend>
51
+
52
+ <admin>
53
+ <routers>
54
+ <adminhtml>
55
+ <args>
56
+ <modules>
57
+ <Sharemagnet_Social_Rebate before="Mage_Adminhtml">Sharemagnet_Social_Rebate_Adminhtml</Sharemagnet_Social_Rebate>
58
+ </modules>
59
+ </args>
60
+ </adminhtml>
61
+ </routers>
62
+ </admin>
63
+
64
+ <adminhtml>
65
+ <acl>
66
+ <resources>
67
+ <admin>
68
+ <children>
69
+ <system>
70
+ <children>
71
+ <config>
72
+ <children>
73
+ <social_rebate_section>
74
+ <title>Social Rebate Section</title>
75
+ </social_rebate_section>
76
+ </children>
77
+ </config>
78
+ </children>
79
+ </system>
80
+ </children>
81
+ </admin>
82
+ </resources>
83
+ </acl>
84
+ </adminhtml>
85
+ </config>
app/code/community/Sharemagnet/Social/Rebate/etc/system.xml ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Sharemagnet_Rebateorder
5
+ *
6
+ * This module was developed by Sharemagnet Company. If you require any
7
+ * support or have any questions please contact us at alexei.liyi@gmail.com.
8
+ *
9
+ * @category Sharemagnet
10
+ * @package Sharemagnet_Rebateorder
11
+ * @author Sharemagnet Company <alexei.liyi@gmail.com>
12
+ * @copyright Copyright (c) 2013 Alexei
13
+ */
14
+ -->
15
+ <config>
16
+ <tabs>
17
+ <social_rebate_tab module="social_rebate" translate="label">
18
+ <label>Social Rebate</label>
19
+ <sort_order>100</sort_order>
20
+ </social_rebate_tab>
21
+ </tabs>
22
+ <sections>
23
+ <social_rebate_section module="social_rebate" translate="label">
24
+ <label>Social Rebate Settings</label>
25
+ <sort_order>200</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ <tab>social_rebate_tab</tab>
30
+ <groups>
31
+ <social_rebate_group translate="label">
32
+ <label>Rebate Integration Setting</label>
33
+ <comment>Let's do rebate order setting here</comment>
34
+ <sort_order>10</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ <fields>
39
+ <social_rebate_apikey translate="label tooltip comment">
40
+ <label>Social Rebate API Key</label>
41
+ <frontend_type>text</frontend_type>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>1</show_in_website>
44
+ <show_in_store>1</show_in_store>
45
+
46
+ </social_rebate_apikey>
47
+ <social_rebate_apisecret translate="label tooltip comment">
48
+ <label>Social Rebate API Secret</label>
49
+ <frontend_type>text</frontend_type>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ </social_rebate_apisecret>
54
+ <social_rebate_magnetkey translate="label tooltip comment">
55
+ <label>Social Rebate Store Key</label>
56
+ <frontend_type>text</frontend_type>
57
+ <show_in_default>1</show_in_default>
58
+ <show_in_website>1</show_in_website>
59
+ <show_in_store>1</show_in_store>
60
+
61
+ </social_rebate_magnetkey>
62
+ </fields>
63
+ </social_rebate_group>
64
+ </groups>
65
+ </social_rebate_section>
66
+ </sections>
67
+ </config>
app/design/frontend/base/default/layout/sharemagnet/social/rebate.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <checkout_onepage_success>
4
+ <remove name="checkout.success" />
5
+ <reference name="content">
6
+ <block type="social_rebate/rebateorder" name="sharemagnet.social_rebate" template="sharemagnet/social/rebate.phtml"/>
7
+ </reference>
8
+ </checkout_onepage_success>
9
+ </layout>
app/etc/modules/Sharemagnet_Social_Rebate.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Sharemagnet_Social_Rebate>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Sharemagnet_Social_Rebate>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Sharemagnet_Social_Rebate</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/artistic-license-2.0">Artistic License 2.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Turn customers&#x2019; purchases into highly credible Social Media Marketing for your store with Social Rebate!</summary>
10
+ <description>Social Rebate provides a comprehensive Social Commerce platform for online retailers to help increase social sharing and customer referrals from Social Media to their eCommerce stores.</description>
11
+ <notes>This is first stable version.</notes>
12
+ <authors><author><name>Ben Stewart</name><user>SocialRebate</user><email>info@sharemagnet.com</email></author></authors>
13
+ <date>2013-04-10</date>
14
+ <time>18:23:18</time>
15
+ <contents><target name="magecommunity"><dir name="Sharemagnet"><dir name="Social"><dir name="Rebate"><dir><dir name="Block"><file name="Rebateorder.php" hash="894088ccc6bf24d5d3221666b9484c63"/></dir><dir name="Helper"><file name="Data.php" hash="eb8159561687773312ad8b668b4739ee"/></dir><dir name="Model"><file name="Observer.php" hash="d78e6b30b8dd4e612e9453afed917a37"/><file name="Order.php" hash="550719d07eb7ac7482067aaad07b7b2a"/></dir><dir name="etc"><file name="config.xml" hash="810c87942360b4b1d440657fee091652"/><file name="system.xml" hash="e0b332415bc1279c72cfbfec7f67f880"/></dir></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="sharemagnet"><dir name="social"><file name="rebate.xml" hash="18aeacd2950d493fde5042326944d98e"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Sharemagnet_Social_Rebate.xml" hash="ddd29c70265716206160515bc8f980f0"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.5</min><max>1.7</max></package></required></dependencies>
18
+ </package>