RewardStream_ReferAFriend - Version 1.3.0

Version Notes

Added email address verification at the point of referral code usage.

Download this release

Release Info

Developer RewardStream
Extension RewardStream_ReferAFriend
Version 1.3.0
Comparing to
See all releases


Code changes from version 1.2.0 to 1.3.0

app/code/community/Rewardstream/Referafriend/Model/Observer.php CHANGED
@@ -73,6 +73,91 @@ class Rewardstream_Referafriend_Model_Observer
73
 
74
  }
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  /**
77
  * Redeem code (POST to RewardStream API). Handles both offer codes and reward codes
78
  *
73
 
74
  }
75
 
76
+ /**
77
+ * Check if the user of the coupon code is the correct user
78
+ */
79
+ public function validateCouponCodeEmail( Varien_Event_Observer $observer ){
80
+ $status = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_status' );
81
+
82
+ if ( $status == 1 ) {
83
+ $quote = $observer->getQuote();
84
+ $couponCode = $quote->getCouponCode();
85
+
86
+ // Is the coupon code used by the correct user?
87
+ if ( $couponCode && substr( $couponCode, 0, 3 ) === 'ref' && Mage::getSingleton('customer/session')->isLoggedIn()) {
88
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
89
+ $responseData = $this->getOfferCode($couponCode);
90
+
91
+ if ($responseData['Referee']['Email'] !== $customer->getEmail()) {
92
+ Mage::getSingleton( 'checkout/session' )->addError( 'You are not eligible to use this coupon code.' );
93
+ $quote->setCouponCode('');
94
+ $quote->collectTotals()->save();
95
+ }
96
+ }
97
+ }
98
+
99
+ return $this;
100
+ }
101
+
102
+ /**
103
+ * Check if the user of the coupon code is the correct user
104
+ */
105
+ public function validateCouponCodeEmail_BeforePlacingOrder( Varien_Event_Observer $observer ){
106
+ $status = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_status' );
107
+
108
+ if ( $status == 1 ) {
109
+ $order = $observer->getEvent()->getOrder();
110
+ $email = $order->getCustomerEmail();
111
+ $couponCode = $order->getCouponCode();
112
+
113
+ // Is the coupon code used by the correct user?
114
+ if ( $couponCode && substr( $couponCode, 0, 3 ) === 'ref') {
115
+ $responseData = $this->getOfferCode($couponCode);
116
+
117
+ if ($responseData['Referee']['Email'] !== $email) {
118
+ Mage::throwException("You are not eligible to use this coupon code.");
119
+ }
120
+ }
121
+ }
122
+
123
+ return $this;
124
+ }
125
+
126
+ /**
127
+ * Check if the user has coupon code on login at checkout/onepage
128
+ */
129
+ public function validateCouponCodeEmail_customerLogin( Varien_Event_Observer $observer ) {
130
+ $status = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_status' );
131
+
132
+ if ( $status == 1 ) {
133
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
134
+ $couponCode = $quote->getCouponCode();
135
+
136
+ // Is the coupon code used by the correct user?
137
+ if ( $couponCode && substr( $couponCode, 0, 3 ) === 'ref' && Mage::getSingleton('customer/session')->isLoggedIn()) {
138
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
139
+ $responseData = $this->getOfferCode($couponCode);
140
+
141
+ if ($responseData['Referee']['Email'] !== $customer->getEmail()) {
142
+ $quote->setCouponCode('');
143
+ $quote->collectTotals()->save();
144
+ }
145
+ }
146
+ }
147
+ }
148
+
149
+ private function getOfferCode($couponCode) {
150
+ $helper = Mage::helper( 'rewardstream' );
151
+ $apiurl = 'https://' . Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_api_url' );
152
+ $apiKey = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_api_key' );
153
+ $secretKey = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_secret_key' );
154
+
155
+ $result = $helper->getDataCallAPI( $apiurl . '/api/v2/custom/getOffer?api_key=' . $apiKey . '&code=' . $couponCode, "GET", false, "Basic " . $secretKey );
156
+ $responseData = json_decode( $result, true );
157
+
158
+ return $responseData;
159
+ }
160
+
161
  /**
162
  * Redeem code (POST to RewardStream API). Handles both offer codes and reward codes
163
  *
app/code/community/Rewardstream/Referafriend/etc/config.xml CHANGED
@@ -81,8 +81,31 @@
81
  <class>rewardstream/observer</class>
82
  <method>createDiscountCode</method>
83
  </rewardstream_observers_sales_quote_collect_totals_after>
 
 
 
 
 
84
  </observers>
85
  </sales_quote_collect_totals_before>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  </events>
87
  </global>
88
  <adminhtml>
81
  <class>rewardstream/observer</class>
82
  <method>createDiscountCode</method>
83
  </rewardstream_observers_sales_quote_collect_totals_after>
84
+ <rewardstream_observers_validate_coupon_code>
85
+ <type>singleton</type>
86
+ <class>rewardstream/observer</class>
87
+ <method>validateCouponCodeEmail</method>
88
+ </rewardstream_observers_validate_coupon_code>
89
  </observers>
90
  </sales_quote_collect_totals_before>
91
+ <sales_order_place_before>
92
+ <observers>
93
+ <rewardstream_observers_validate_coupon_code_before_placing_order>
94
+ <type>singleton</type>
95
+ <class>rewardstream/observer</class>
96
+ <method>validateCouponCodeEmail_BeforePlacingOrder</method>
97
+ </rewardstream_observers_validate_coupon_code_before_placing_order>
98
+ </observers>
99
+ </sales_order_place_before>
100
+ <controller_action_predispatch_checkout_onepage_index>
101
+ <observers>
102
+ <rewardstream_observers_validate_coupon_code_on_login>
103
+ <type>singleton</type>
104
+ <class>rewardstream/observer</class>
105
+ <method>validateCouponCodeEmail_customerLogin</method>
106
+ </rewardstream_observers_validate_coupon_code_on_login>
107
+ </observers>
108
+ </controller_action_predispatch_checkout_onepage_index>
109
  </events>
110
  </global>
111
  <adminhtml>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>RewardStream_ReferAFriend</name>
4
- <version>1.2.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.rewardstream.com/magento/license">RewardStream Software License Agreement</license>
7
  <channel>community</channel>
@@ -9,13 +9,11 @@
9
  <summary>Get new customers by adding a fully automated word-of-mouth customer referral marketing solution to your store</summary>
10
  <description>Get new sales using the Refer A Friend extension. Launch a fully automated referral marketing program on your store with little-to-no IT. Customers can refer their friends and family to bring you new business. Automatically reward your existing customers for successful referrals and incentivize your new customers with special referral offers. Refer a Friend is a free Magento Extension and requires a paid service account with RewardStream.&#xD;
11
  </description>
12
- <notes>Fixed compatibility issues with common checkout extensions.&#xD;
13
- Added support for automatically generated reward codes.&#xD;
14
- Stability improvements.</notes>
15
  <authors><author><name>RewardStream</name><user>RewardStream</user><email>plugin-support@rewardstream.com</email></author></authors>
16
- <date>2017-03-01</date>
17
- <time>00:14:00</time>
18
- <contents><target name="magecommunity"><dir name="Rewardstream"><dir name="Referafriend"><dir name="Block"><file name="Button.php" hash="2d412348e526ce8259cb767b5d795fd7"/><dir name="Customer"><dir name="Account"><file name="Navigation.php" hash="18a0c268359658bd7619ce7168159364"/></dir></dir><file name="Getstartedbutton.php" hash="7bfea148b21c68ea5228ff64f4d9991e"/><dir name="Sales"><dir name="Order"><file name="History.php" hash="880e07a11f94ceab5bd5e066a4cfa838"/><file name="Recent.php" hash="8c5c64cd158205a7a5bd053a3c7a3cf0"/></dir></dir><file name="Script.php" hash="13b06afd09fada61b761ea5ff4254ede"/></dir><dir name="Helper"><file name="Data.php" hash="6ac29ba1b21d0ca246df13a216da649e"/></dir><dir name="Model"><file name="Observer.php" hash="35e825fa556ac8ffcda84828784b0441"/><file name="Options.php" hash="1c4fa6b3e55cec4b096ebbaedacacb19"/><dir name="Resource"><dir name="Rewardstream"><file name="Collection.php" hash="aeeb1df3e3eb6bdeadce8aa29d98eea5"/></dir><file name="Rewardstream.php" hash="8fe9853ebbad43796b683582db550620"/></dir><file name="Rewardstream.php" hash="884edc2f2bd98d5794c9c2bd6b84b9a8"/></dir><dir name="controllers"><file name="CartController.php" hash="e8dd6101f0e36eeb4cde1931dc2e461f"/><file name="IndexController.php" hash="d3429574e292d9c7b9c55c6a060bcb30"/></dir><dir name="data"><dir name="rewardstream_setup"><file name="data-install-0.1.0.php" hash="ffa670c6e00b15f7197e017017aa5ac2"/></dir></dir><dir name="etc"><file name="config.xml" hash="baa8ed8409a5859f3fed6017157e8a33"/><file name="system.xml" hash="4c382d84ff7c7ce434465593057132ba"/></dir><dir name="sql"><dir name="rewardstream_setup"><file name="install-0.1.0.php" hash="2ff36a8226dba730c568ce7bd5328b76"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="rewardstream.xml" hash="4c9a4575f0d44847032614368cf3924e"/></dir><dir name="template"><dir name="rewardstream"><file name="blockreward.phtml" hash="82e9d4d7d5592b40a9ada2ce3c8e1996"/><file name="general_script.phtml" hash="9386936cd1df44ccecb185e510417736"/><file name="rewardstream.phtml" hash="6f628a6916b1fffed4794276cd7c084d"/><file name="script.phtml" hash="a37b6436daeeb70f73c8dd03930ce1f9"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="layout"><file name="rewardstream.xml" hash="9453c01a065a609ba6b30e3e7420c97f"/></dir><dir name="template"><dir name="rewardstream"><file name="blockreward.phtml" hash="82e9d4d7d5592b40a9ada2ce3c8e1996"/><file name="general_script.phtml" hash="9386936cd1df44ccecb185e510417736"/><file name="rewardstream.phtml" hash="6f628a6916b1fffed4794276cd7c084d"/><file name="script.phtml" hash="a37b6436daeeb70f73c8dd03930ce1f9"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="RewardStream_ReferAFriend.xml" hash="d08d3aa024b2616e3a3792aeac0bc3cb"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="rewardstream"><dir name="css"><file name="rewardstream.css" hash="14e0164315bb6fec5354b331009b9793"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="rewardstream"><dir name="css"><file name="rewardstream.css" hash="14e0164315bb6fec5354b331009b9793"/></dir></dir></dir></dir></dir></target><target name="magemedia"><dir name="wysiwyg"><dir name="rewardstream"><file name="loading.gif" hash="dbd0f12f50cc2b56e2bce7daa36d00d0"/><file name="rewardstream-magento-store-default-image.jpg" hash="66004f46b67bbb30c8d4cd7e5fff1fa1"/><file name="sharing-is-caring.jpg" hash="079db8066ed86203bd78c52b20d6163e"/></dir></dir></target><target name="mageweb"><dir name="js"><dir name="rewardstream"><file name="RSUtility.js" hash="c56b4d2ca75647f8708ad59e6382e300"/><file name="jquery-1.10.2.min.js" hash="841dc30647f93349b7d8ef61deebe411"/><file name="noconflict.js" hash="12f820da0f5ba19abfb4f5fc270bb62c"/></dir></dir></target></contents>
19
  <compatible/>
20
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.5.0.0</min><max>1.9</max></package></required></dependencies>
21
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>RewardStream_ReferAFriend</name>
4
+ <version>1.3.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.rewardstream.com/magento/license">RewardStream Software License Agreement</license>
7
  <channel>community</channel>
9
  <summary>Get new customers by adding a fully automated word-of-mouth customer referral marketing solution to your store</summary>
10
  <description>Get new sales using the Refer A Friend extension. Launch a fully automated referral marketing program on your store with little-to-no IT. Customers can refer their friends and family to bring you new business. Automatically reward your existing customers for successful referrals and incentivize your new customers with special referral offers. Refer a Friend is a free Magento Extension and requires a paid service account with RewardStream.&#xD;
11
  </description>
12
+ <notes>Added email address verification at the point of referral code usage.</notes>
 
 
13
  <authors><author><name>RewardStream</name><user>RewardStream</user><email>plugin-support@rewardstream.com</email></author></authors>
14
+ <date>2017-03-23</date>
15
+ <time>22:54:23</time>
16
+ <contents><target name="magecommunity"><dir name="Rewardstream"><dir name="Referafriend"><dir name="Block"><file name="Button.php" hash="2d412348e526ce8259cb767b5d795fd7"/><dir name="Customer"><dir name="Account"><file name="Navigation.php" hash="18a0c268359658bd7619ce7168159364"/></dir></dir><file name="Getstartedbutton.php" hash="7bfea148b21c68ea5228ff64f4d9991e"/><dir name="Sales"><dir name="Order"><file name="History.php" hash="880e07a11f94ceab5bd5e066a4cfa838"/><file name="Recent.php" hash="8c5c64cd158205a7a5bd053a3c7a3cf0"/></dir></dir><file name="Script.php" hash="13b06afd09fada61b761ea5ff4254ede"/></dir><dir name="Helper"><file name="Data.php" hash="6ac29ba1b21d0ca246df13a216da649e"/></dir><dir name="Model"><file name="Observer.php" hash="4746e23be32ae60c3b21c271ce68b0ac"/><file name="Options.php" hash="1c4fa6b3e55cec4b096ebbaedacacb19"/><dir name="Resource"><dir name="Rewardstream"><file name="Collection.php" hash="aeeb1df3e3eb6bdeadce8aa29d98eea5"/></dir><file name="Rewardstream.php" hash="8fe9853ebbad43796b683582db550620"/></dir><file name="Rewardstream.php" hash="884edc2f2bd98d5794c9c2bd6b84b9a8"/></dir><dir name="controllers"><file name="CartController.php" hash="e8dd6101f0e36eeb4cde1931dc2e461f"/><file name="IndexController.php" hash="d3429574e292d9c7b9c55c6a060bcb30"/></dir><dir name="data"><dir name="rewardstream_setup"><file name="data-install-0.1.0.php" hash="ffa670c6e00b15f7197e017017aa5ac2"/></dir></dir><dir name="etc"><file name="config.xml" hash="1d3ec6297d24179b7d213fc1aa4c11a1"/><file name="system.xml" hash="4c382d84ff7c7ce434465593057132ba"/></dir><dir name="sql"><dir name="rewardstream_setup"><file name="install-0.1.0.php" hash="2ff36a8226dba730c568ce7bd5328b76"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="rewardstream.xml" hash="4c9a4575f0d44847032614368cf3924e"/></dir><dir name="template"><dir name="rewardstream"><file name="blockreward.phtml" hash="82e9d4d7d5592b40a9ada2ce3c8e1996"/><file name="general_script.phtml" hash="9386936cd1df44ccecb185e510417736"/><file name="rewardstream.phtml" hash="6f628a6916b1fffed4794276cd7c084d"/><file name="script.phtml" hash="a37b6436daeeb70f73c8dd03930ce1f9"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="layout"><file name="rewardstream.xml" hash="9453c01a065a609ba6b30e3e7420c97f"/></dir><dir name="template"><dir name="rewardstream"><file name="blockreward.phtml" hash="82e9d4d7d5592b40a9ada2ce3c8e1996"/><file name="general_script.phtml" hash="9386936cd1df44ccecb185e510417736"/><file name="rewardstream.phtml" hash="6f628a6916b1fffed4794276cd7c084d"/><file name="script.phtml" hash="a37b6436daeeb70f73c8dd03930ce1f9"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="RewardStream_ReferAFriend.xml" hash="d08d3aa024b2616e3a3792aeac0bc3cb"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="rewardstream"><dir name="css"><file name="rewardstream.css" hash="14e0164315bb6fec5354b331009b9793"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="rewardstream"><dir name="css"><file name="rewardstream.css" hash="14e0164315bb6fec5354b331009b9793"/></dir></dir></dir></dir></dir></target><target name="magemedia"><dir name="wysiwyg"><dir name="rewardstream"><file name="loading.gif" hash="dbd0f12f50cc2b56e2bce7daa36d00d0"/><file name="rewardstream-magento-store-default-image.jpg" hash="66004f46b67bbb30c8d4cd7e5fff1fa1"/><file name="sharing-is-caring.jpg" hash="079db8066ed86203bd78c52b20d6163e"/></dir></dir></target><target name="mageweb"><dir name="js"><dir name="rewardstream"><file name="RSUtility.js" hash="c56b4d2ca75647f8708ad59e6382e300"/><file name="jquery-1.10.2.min.js" hash="841dc30647f93349b7d8ef61deebe411"/><file name="noconflict.js" hash="12f820da0f5ba19abfb4f5fc270bb62c"/></dir></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.5.0.0</min><max>1.9</max></package></required></dependencies>
19
  </package>