Ambassador - Version 1.1.7

Version Notes

- automatic commission approval when order is paid/shipped is now optional
- automatic commission denial when order is canceled is now optional

Download this release

Release Info

Developer Jeffrey Epstein
Extension Ambassador
Version 1.1.7
Comparing to
See all releases


Code changes from version 1.1.6 to 1.1.7

app/code/community/Ambassador/Event/Model/Observer.php CHANGED
@@ -30,6 +30,18 @@ class Ambassador_Event_Model_Observer extends Varien_Event_Observer
30
  */
31
  public function callCommissionUpdate($observer)
32
  {
 
 
 
 
 
 
 
 
 
 
 
 
33
  $snippet_type = Mage::getModel('core/variable')->loadByCode('getambassador_snippet_type')->getValue('plain');
34
  $username = Mage::getModel('core/variable')->loadByCode('getambassador_username')->getValue('plain');
35
  $api_key = Mage::getModel('core/variable')->loadByCode('getambassador_api_key')->getValue('plain');
@@ -55,29 +67,33 @@ class Ambassador_Event_Model_Observer extends Varien_Event_Observer
55
  break;
56
  }
57
 
58
- $transaction_uid = $order->getRealOrderId();
59
 
60
- $api_url = $this->ambassador_url."api/v2/$username/$api_key/json/commission/update";
61
 
62
- // Data for API call
63
- $data = array(
64
- 'transaction_uid' => $transaction_uid,
65
- 'is_approved' => $is_approved
66
- );
67
 
68
- $data = http_build_query($data);
 
 
 
 
69
 
70
- // Call to API via CURL
71
- $curl_handle = curl_init();
72
- curl_setopt($curl_handle, CURLOPT_URL, $api_url);
73
- curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
74
- curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
75
- curl_setopt($curl_handle, CURLOPT_POST, 1);
76
- curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data);
77
- $buffer = curl_exec($curl_handle);
78
- curl_close($curl_handle);
79
- // Output
80
- $returnData = json_decode($buffer, true);
 
 
 
 
81
 
82
  return $this;
83
  }
@@ -231,6 +247,60 @@ class Ambassador_Event_Model_Observer extends Varien_Event_Observer
231
  $variable->save();
232
  } catch (Exception $e) {}
233
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
  return $variable_data['plain_value'];
235
  break;
236
  }
30
  */
31
  public function callCommissionUpdate($observer)
32
  {
33
+ $is_approved_when_paid = Mage::getModel('core/variable')->loadByCode('getambassador_is_approved_when_paid')->getValue('plain');
34
+
35
+ if (is_null($is_approved_when_paid)) {
36
+ $is_approved_when_paid = $this->addMissingCustomVariable('getambassador_is_approved_when_paid');
37
+ }
38
+
39
+ $is_denied_when_canceled = Mage::getModel('core/variable')->loadByCode('getambassador_is_denied_when_canceled')->getValue('plain');
40
+
41
+ if (is_null($is_denied_when_canceled)) {
42
+ $is_denied_when_canceled = $this->addMissingCustomVariable('getambassador_is_denied_when_canceled');
43
+ }
44
+
45
  $snippet_type = Mage::getModel('core/variable')->loadByCode('getambassador_snippet_type')->getValue('plain');
46
  $username = Mage::getModel('core/variable')->loadByCode('getambassador_username')->getValue('plain');
47
  $api_key = Mage::getModel('core/variable')->loadByCode('getambassador_api_key')->getValue('plain');
67
  break;
68
  }
69
 
70
+ if (($is_approved == 1 && $is_approved_when_paid == '1') || ($is_approved == 2 && $is_denied_when_canceled == '1')) {
71
 
72
+ $transaction_uid = $order->getRealOrderId();
73
 
74
+ $api_url = $this->ambassador_url."api/v2/$username/$api_key/json/commission/update";
 
 
 
 
75
 
76
+ // Data for API call
77
+ $data = array(
78
+ 'transaction_uid' => $transaction_uid,
79
+ 'is_approved' => $is_approved
80
+ );
81
 
82
+ $data = http_build_query($data);
83
+
84
+ // Call to API via CURL
85
+ $curl_handle = curl_init();
86
+ curl_setopt($curl_handle, CURLOPT_URL, $api_url);
87
+ curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
88
+ curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
89
+ curl_setopt($curl_handle, CURLOPT_POST, 1);
90
+ curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data);
91
+ $buffer = curl_exec($curl_handle);
92
+ curl_close($curl_handle);
93
+ // Output
94
+ $returnData = json_decode($buffer, true);
95
+
96
+ }
97
 
98
  return $this;
99
  }
247
  $variable->save();
248
  } catch (Exception $e) {}
249
 
250
+ return $variable_data['plain_value'];
251
+ break;
252
+
253
+ case 'getambassador_is_approved_when_paid':
254
+
255
+ $variable = Mage::getModel('core/variable')->loadByCode('getambassador_is_approved_when_paid');
256
+ $variableData = $variable->getData();
257
+
258
+ if (empty($variableData)) {
259
+
260
+ $variable->cleanModelCache();
261
+ $variable = Mage::getModel('core/variable');
262
+
263
+ $variable_data = array(
264
+ 'code' => 'getambassador_is_approved_when_paid',
265
+ 'name' => 'getambassador Approve commission when order is paid/shipped',
266
+ 'plain_value' => '1',
267
+ 'html_value' => ''
268
+ );
269
+
270
+ $variable->setData($variable_data);
271
+ }
272
+
273
+ try {
274
+ $variable->save();
275
+ } catch (Exception $e) {}
276
+
277
+ return $variable_data['plain_value'];
278
+ break;
279
+
280
+ case 'getambassador_is_denied_when_canceled':
281
+
282
+ $variable = Mage::getModel('core/variable')->loadByCode('getambassador_is_denied_when_canceled');
283
+ $variableData = $variable->getData();
284
+
285
+ if (empty($variableData)) {
286
+
287
+ $variable->cleanModelCache();
288
+ $variable = Mage::getModel('core/variable');
289
+
290
+ $variable_data = array(
291
+ 'code' => 'getambassador_is_denied_when_canceled',
292
+ 'name' => 'getambassador Deny commission when order is canceled',
293
+ 'plain_value' => '1',
294
+ 'html_value' => ''
295
+ );
296
+
297
+ $variable->setData($variable_data);
298
+ }
299
+
300
+ try {
301
+ $variable->save();
302
+ } catch (Exception $e) {}
303
+
304
  return $variable_data['plain_value'];
305
  break;
306
  }
app/code/community/Ambassador/Event/controllers/CallbackController.php CHANGED
@@ -293,6 +293,62 @@ class Ambassador_Event_CallbackController extends Mage_Core_Controller_Front_Act
293
  echo json_encode($e->getMessage());
294
  }
295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  echo json_encode(true);
297
 
298
  } else {
293
  echo json_encode($e->getMessage());
294
  }
295
 
296
+ // save default is_approved_when_paid
297
+ $variable->cleanModelCache();
298
+ $variable = Mage::getModel('core/variable')->loadByCode('getambassador_is_approved_when_paid');
299
+ $variableData = $variable->getData();
300
+
301
+ if (empty($variableData)) {
302
+
303
+ $variable->cleanModelCache();
304
+ $variable = Mage::getModel('core/variable');
305
+
306
+ $variable_data = array(
307
+ 'code' => 'getambassador_is_approved_when_paid',
308
+ 'name' => 'getambassador Approve commission when order is paid/shipped',
309
+ 'plain_value' => '1',
310
+ 'html_value' => ''
311
+ );
312
+
313
+ $variable->setData($variable_data);
314
+ }
315
+
316
+ try {
317
+ $variable->save();
318
+
319
+ } catch (Exception $e) {
320
+
321
+ echo json_encode($e->getMessage());
322
+ }
323
+
324
+ // save default is_denied_when_canceled
325
+ $variable->cleanModelCache();
326
+ $variable = Mage::getModel('core/variable')->loadByCode('getambassador_is_denied_when_canceled');
327
+ $variableData = $variable->getData();
328
+
329
+ if (empty($variableData)) {
330
+
331
+ $variable->cleanModelCache();
332
+ $variable = Mage::getModel('core/variable');
333
+
334
+ $variable_data = array(
335
+ 'code' => 'getambassador_is_denied_when_canceled',
336
+ 'name' => 'getambassador Deny commission when order is canceled',
337
+ 'plain_value' => '1',
338
+ 'html_value' => ''
339
+ );
340
+
341
+ $variable->setData($variable_data);
342
+ }
343
+
344
+ try {
345
+ $variable->save();
346
+
347
+ } catch (Exception $e) {
348
+
349
+ echo json_encode($e->getMessage());
350
+ }
351
+
352
  echo json_encode(true);
353
 
354
  } else {
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Ambassador</name>
4
- <version>1.1.6</version>
5
  <stability>stable</stability>
6
  <license uri="https://getambassador.com/terms">Zferral, Inc, magento@getAmbassador.com</license>
7
  <channel>community</channel>
@@ -14,12 +14,12 @@ Use Ambassador to easily create, track &amp; manage custom incentives that drive
14
  Integrate Ambassador into the other existing applications you already use, including Salesforce, Sendgrid, MailChimp, Campaign Monitor, Sailthru, PayPal and Dwolla.&#xD;
15
  &#xD;
16
  Get started on Ambassador with a free trial, simply follow the instructions on how to get up and running in just minutes.</description>
17
- <notes>- added templates to base design&#xD;
18
- - allowed to overwrite mode</notes>
19
  <authors><author><name>Jeffrey Epstein</name><user>getAmbassador</user><email>magento@getambassador.com</email></author><author><name>Greg Szymczak</name><user>gpszymczak</user><email>gpszymczak@gmail.com</email></author></authors>
20
- <date>2015-07-02</date>
21
- <time>09:44:48</time>
22
- <contents><target name="magecommunity"><dir name="Ambassador"><dir name="Affiliate"><dir name="Model"><file name="Observer.php" hash="b8bb353e129bf09f5eeb6cc9d21a107c"/></dir><dir name="controllers"><file name="AffiliateController.php" hash="675abd910b45ea4320cd30455c36a200"/></dir><dir name="etc"><file name="config.xml" hash="98de110422ad3fe68c234eebba9c401a"/></dir></dir><dir name="Event"><dir name="Model"><file name="Observer.php" hash="6738b87068e51a739fda753645b8a840"/></dir><dir name="controllers"><file name="CallbackController.php" hash="ddf1904ee1ba126da320a1f934793389"/></dir><dir name="etc"><file name="config.xml" hash="2243df59895e012f99412670ed16039c"/></dir></dir><dir name="Payout"><dir name="controllers"><file name="PayoutController.php" hash="e0ff7885b47e780437a55a1982a6cb45"/></dir><dir name="etc"><file name="config.xml" hash="23dbf12c8a05edce63499f19087367a1"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="ambassador"><dir name="checkout"><file name="ecommerce.phtml" hash="38d66b1e639cd623f3f255aea2e42665"/><file name="img.phtml" hash="93450ac8ed4df0aa33e29c0c58fbb3b2"/></dir><dir name="sso"><file name="affiliate_program.phtml" hash="983bfe455fa6bfb67f78966e9a5d607a"/><file name="sso.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="sso_logout.phtml" hash="0721023e06005ca9d102a3218ca0d32f"/></dir></dir></dir></dir></dir><dir name="enterprise"><dir name="default"><dir name="template"><dir name="ambassador"><dir name="checkout"><file name="ecommerce.phtml" hash="38d66b1e639cd623f3f255aea2e42665"/><file name="img.phtml" hash="93450ac8ed4df0aa33e29c0c58fbb3b2"/></dir><dir name="sso"><file name="affiliate_program.phtml" hash="983bfe455fa6bfb67f78966e9a5d607a"/><file name="sso.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="sso_logout.phtml" hash="0721023e06005ca9d102a3218ca0d32f"/></dir></dir></dir></dir></dir><dir name="base"><dir name="default"><dir name="template"><dir name="ambassador"><dir name="checkout"><file name="ecommerce.phtml" hash="38d66b1e639cd623f3f255aea2e42665"/><file name="img.phtml" hash="93450ac8ed4df0aa33e29c0c58fbb3b2"/></dir><dir name="sso"><file name="affiliate_program.phtml" hash="983bfe455fa6bfb67f78966e9a5d607a"/><file name="sso.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="sso_logout.phtml" hash="0721023e06005ca9d102a3218ca0d32f"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ambassador_Event.xml" hash="531c19fe928c2fd3b008cf00bc865246"/><file name="Ambassador_Affiliate.xml" hash="806b368fde635b60f5dabad5cfa9e1d8"/><file name="Ambassador_Payout.xml" hash="24f665e03b13562e03b871957e959ae2"/></dir></target></contents>
23
  <compatible/>
24
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php><extension><name>curl</name><min/><max/></extension><extension><name>json</name><min/><max/></extension></required></dependencies>
25
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Ambassador</name>
4
+ <version>1.1.7</version>
5
  <stability>stable</stability>
6
  <license uri="https://getambassador.com/terms">Zferral, Inc, magento@getAmbassador.com</license>
7
  <channel>community</channel>
14
  Integrate Ambassador into the other existing applications you already use, including Salesforce, Sendgrid, MailChimp, Campaign Monitor, Sailthru, PayPal and Dwolla.&#xD;
15
  &#xD;
16
  Get started on Ambassador with a free trial, simply follow the instructions on how to get up and running in just minutes.</description>
17
+ <notes>- automatic commission approval when order is paid/shipped is now optional&#xD;
18
+ - automatic commission denial when order is canceled is now optional</notes>
19
  <authors><author><name>Jeffrey Epstein</name><user>getAmbassador</user><email>magento@getambassador.com</email></author><author><name>Greg Szymczak</name><user>gpszymczak</user><email>gpszymczak@gmail.com</email></author></authors>
20
+ <date>2017-01-23</date>
21
+ <time>17:29:45</time>
22
+ <contents><target name="magecommunity"><dir name="Ambassador"><dir name="Affiliate"><dir name="Model"><file name="Observer.php" hash="b8bb353e129bf09f5eeb6cc9d21a107c"/></dir><dir name="controllers"><file name="AffiliateController.php" hash="675abd910b45ea4320cd30455c36a200"/></dir><dir name="etc"><file name="config.xml" hash="98de110422ad3fe68c234eebba9c401a"/></dir></dir><dir name="Event"><dir name="Model"><file name="Observer.php" hash="02d1202358d606c2211f2230cfa1e9e5"/></dir><dir name="controllers"><file name="CallbackController.php" hash="eeb12dc5adca5edf223b77bb46c856cb"/></dir><dir name="etc"><file name="config.xml" hash="2243df59895e012f99412670ed16039c"/></dir></dir><dir name="Payout"><dir name="controllers"><file name="PayoutController.php" hash="e0ff7885b47e780437a55a1982a6cb45"/></dir><dir name="etc"><file name="config.xml" hash="23dbf12c8a05edce63499f19087367a1"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="ambassador"><dir name="checkout"><file name="ecommerce.phtml" hash="38d66b1e639cd623f3f255aea2e42665"/><file name="img.phtml" hash="93450ac8ed4df0aa33e29c0c58fbb3b2"/></dir><dir name="sso"><file name="affiliate_program.phtml" hash="983bfe455fa6bfb67f78966e9a5d607a"/><file name="sso.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="sso_logout.phtml" hash="0721023e06005ca9d102a3218ca0d32f"/></dir></dir></dir></dir></dir><dir name="enterprise"><dir name="default"><dir name="template"><dir name="ambassador"><dir name="checkout"><file name="ecommerce.phtml" hash="38d66b1e639cd623f3f255aea2e42665"/><file name="img.phtml" hash="93450ac8ed4df0aa33e29c0c58fbb3b2"/></dir><dir name="sso"><file name="affiliate_program.phtml" hash="983bfe455fa6bfb67f78966e9a5d607a"/><file name="sso.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="sso_logout.phtml" hash="0721023e06005ca9d102a3218ca0d32f"/></dir></dir></dir></dir></dir><dir name="base"><dir name="default"><dir name="template"><dir name="ambassador"><dir name="checkout"><file name="ecommerce.phtml" hash="38d66b1e639cd623f3f255aea2e42665"/><file name="img.phtml" hash="93450ac8ed4df0aa33e29c0c58fbb3b2"/></dir><dir name="sso"><file name="affiliate_program.phtml" hash="983bfe455fa6bfb67f78966e9a5d607a"/><file name="sso.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="sso_logout.phtml" hash="0721023e06005ca9d102a3218ca0d32f"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ambassador_Event.xml" hash="531c19fe928c2fd3b008cf00bc865246"/><file name="Ambassador_Affiliate.xml" hash="806b368fde635b60f5dabad5cfa9e1d8"/><file name="Ambassador_Payout.xml" hash="24f665e03b13562e03b871957e959ae2"/></dir></target></contents>
23
  <compatible/>
24
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php><extension><name>curl</name><min/><max/></extension><extension><name>json</name><min/><max/></extension></required></dependencies>
25
  </package>