Creative Mail – Easier WordPress & WooCommerce Email Marketing - Version 1.5.1

Version Description

Download this release

Release Info

Developer constantcontact
Plugin Icon 128x128 Creative Mail – Easier WordPress & WooCommerce Email Marketing
Version 1.5.1
Comparing to
See all releases

Code changes from version 1.5.0 to 1.5.1

CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
  Changelog
2
  =========
 
 
 
3
  #### 1.5.0 - March 1 2022
4
  - Fix WooCommerce product lists
5
  - WooCommerce order workflows improved.
1
  Changelog
2
  =========
3
+ #### 1.5.1 - March 22 2022
4
+ - Fix outdated PHP classes
5
+
6
  #### 1.5.0 - March 1 2022
7
  - Fix WooCommerce product lists
8
  - WooCommerce order workflows improved.
README.md CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: Constant Contact
3
  Tags: email, marketing, newsletter, subscribe, contact form, constant contact, crm, automations, ecommerce, promotion, offers, retargeting
4
  Requires at least: 4.6
5
- Tested up to: 5.8
6
- Stable tag: 1.5.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.6
@@ -90,6 +90,7 @@ Creative Mail by Constant Contact [Privacy Notice](https://www.endurance.com/pri
90
  6. Enhance your brand with LogoBuilder
91
 
92
  == Changelog ==
 
93
  * 1.5.0 - Fix WooCommerce product lists, improved WooCommerce order workflows and improved contact management.
94
  * 1.4.9 - Fixes regarding WooCoomerce and Contact Sync Updates.
95
  * 1.4.8 - Redirect to main Creativ Email templates page when user has abandoned cart template deactivated. Fix sync error with contact form 7. Added automation trigger for customer buying products.
2
  Contributors: Constant Contact
3
  Tags: email, marketing, newsletter, subscribe, contact form, constant contact, crm, automations, ecommerce, promotion, offers, retargeting
4
  Requires at least: 4.6
5
+ Tested up to: 5.9
6
+ Stable tag: 1.5.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.6
90
  6. Enhance your brand with LogoBuilder
91
 
92
  == Changelog ==
93
+ * 1.5.1 - Fix outdated PHP classes
94
  * 1.5.0 - Fix WooCommerce product lists, improved WooCommerce order workflows and improved contact management.
95
  * 1.4.9 - Fixes regarding WooCoomerce and Contact Sync Updates.
96
  * 1.4.8 - Redirect to main Creativ Email templates page when user has abandoned cart template deactivated. Fix sync error with contact form 7. Added automation trigger for customer buying products.
composer.json CHANGED
@@ -10,11 +10,13 @@
10
  "a5hleyrich/wp-background-processing": "^1.0",
11
  "squizlabs/php_codesniffer": "*",
12
  "ext-zip": "*",
13
- "mindscape/raygun4php": "1.*"
 
14
  },
15
  "autoload": {
16
  "psr-4": {
17
  "CreativeMail\\Managers\\": "src/managers/",
 
18
  "CreativeMail\\Helpers\\": "src/helpers/",
19
  "CreativeMail\\Modules\\": "src/modules/",
20
  "CreativeMail\\Constants\\": "src/constants/",
@@ -22,8 +24,5 @@
22
  "CreativeMail\\Blocks\\": "src/blocks/",
23
  "CreativeMail\\": "src/"
24
  }
25
- },
26
- "require-dev": {
27
- "phpcompatibility/php-compatibility": "^9.3"
28
  }
29
  }
10
  "a5hleyrich/wp-background-processing": "^1.0",
11
  "squizlabs/php_codesniffer": "*",
12
  "ext-zip": "*",
13
+ "mindscape/raygun4php": "1.*",
14
+ "phpcompatibility/php-compatibility": "^9.3"
15
  },
16
  "autoload": {
17
  "psr-4": {
18
  "CreativeMail\\Managers\\": "src/managers/",
19
+ "CreativeMail\\Models\\": "src/models/",
20
  "CreativeMail\\Helpers\\": "src/helpers/",
21
  "CreativeMail\\Modules\\": "src/modules/",
22
  "CreativeMail\\Constants\\": "src/constants/",
24
  "CreativeMail\\Blocks\\": "src/blocks/",
25
  "CreativeMail\\": "src/"
26
  }
 
 
 
27
  }
28
  }
composer.lock CHANGED
@@ -4,7 +4,7 @@
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
  "This file is @generated automatically"
6
  ],
7
- "content-hash": "83b72bd8ee9681d20c2c9261361a957f",
8
  "packages": [
9
  {
10
  "name": "a5hleyrich/wp-background-processing",
@@ -117,16 +117,16 @@
117
  },
118
  {
119
  "name": "firebase/php-jwt",
120
- "version": "v5.3.0",
121
  "source": {
122
  "type": "git",
123
  "url": "https://github.com/firebase/php-jwt.git",
124
- "reference": "3c2d70f2e64e2922345e89f2ceae47d2463faae1"
125
  },
126
  "dist": {
127
  "type": "zip",
128
- "url": "https://api.github.com/repos/firebase/php-jwt/zipball/3c2d70f2e64e2922345e89f2ceae47d2463faae1",
129
- "reference": "3c2d70f2e64e2922345e89f2ceae47d2463faae1",
130
  "shasum": ""
131
  },
132
  "require": {
@@ -135,6 +135,9 @@
135
  "require-dev": {
136
  "phpunit/phpunit": ">=4.8 <=9"
137
  },
 
 
 
138
  "type": "library",
139
  "autoload": {
140
  "psr-4": {
@@ -165,9 +168,9 @@
165
  ],
166
  "support": {
167
  "issues": "https://github.com/firebase/php-jwt/issues",
168
- "source": "https://github.com/firebase/php-jwt/tree/v5.3.0"
169
  },
170
- "time": "2021-05-20T17:37:02+00:00"
171
  },
172
  {
173
  "name": "mindscape/raygun4php",
@@ -273,64 +276,6 @@
273
  },
274
  "time": "2020-10-15T08:29:30+00:00"
275
  },
276
- {
277
- "name": "squizlabs/php_codesniffer",
278
- "version": "3.6.0",
279
- "source": {
280
- "type": "git",
281
- "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
282
- "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625"
283
- },
284
- "dist": {
285
- "type": "zip",
286
- "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ffced0d2c8fa8e6cdc4d695a743271fab6c38625",
287
- "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625",
288
- "shasum": ""
289
- },
290
- "require": {
291
- "ext-simplexml": "*",
292
- "ext-tokenizer": "*",
293
- "ext-xmlwriter": "*",
294
- "php": ">=5.4.0"
295
- },
296
- "require-dev": {
297
- "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
298
- },
299
- "bin": [
300
- "bin/phpcs",
301
- "bin/phpcbf"
302
- ],
303
- "type": "library",
304
- "extra": {
305
- "branch-alias": {
306
- "dev-master": "3.x-dev"
307
- }
308
- },
309
- "notification-url": "https://packagist.org/downloads/",
310
- "license": [
311
- "BSD-3-Clause"
312
- ],
313
- "authors": [
314
- {
315
- "name": "Greg Sherwood",
316
- "role": "lead"
317
- }
318
- ],
319
- "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
320
- "homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
321
- "keywords": [
322
- "phpcs",
323
- "standards"
324
- ],
325
- "support": {
326
- "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues",
327
- "source": "https://github.com/squizlabs/PHP_CodeSniffer",
328
- "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
329
- },
330
- "time": "2021-04-09T00:54:41+00:00"
331
- }
332
- ],
333
- "packages-dev": [
334
  {
335
  "name": "phpcompatibility/php-compatibility",
336
  "version": "9.3.5",
@@ -392,8 +337,65 @@
392
  "source": "https://github.com/PHPCompatibility/PHPCompatibility"
393
  },
394
  "time": "2019-12-27T09:44:58+00:00"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
  }
396
  ],
 
397
  "aliases": [],
398
  "minimum-stability": "stable",
399
  "stability-flags": [],
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
  "This file is @generated automatically"
6
  ],
7
+ "content-hash": "2432870f0eed5d73f35f7f6fcb058336",
8
  "packages": [
9
  {
10
  "name": "a5hleyrich/wp-background-processing",
117
  },
118
  {
119
  "name": "firebase/php-jwt",
120
+ "version": "v5.5.1",
121
  "source": {
122
  "type": "git",
123
  "url": "https://github.com/firebase/php-jwt.git",
124
+ "reference": "83b609028194aa042ea33b5af2d41a7427de80e6"
125
  },
126
  "dist": {
127
  "type": "zip",
128
+ "url": "https://api.github.com/repos/firebase/php-jwt/zipball/83b609028194aa042ea33b5af2d41a7427de80e6",
129
+ "reference": "83b609028194aa042ea33b5af2d41a7427de80e6",
130
  "shasum": ""
131
  },
132
  "require": {
135
  "require-dev": {
136
  "phpunit/phpunit": ">=4.8 <=9"
137
  },
138
+ "suggest": {
139
+ "paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present"
140
+ },
141
  "type": "library",
142
  "autoload": {
143
  "psr-4": {
168
  ],
169
  "support": {
170
  "issues": "https://github.com/firebase/php-jwt/issues",
171
+ "source": "https://github.com/firebase/php-jwt/tree/v5.5.1"
172
  },
173
+ "time": "2021-11-08T20:18:51+00:00"
174
  },
175
  {
176
  "name": "mindscape/raygun4php",
276
  },
277
  "time": "2020-10-15T08:29:30+00:00"
278
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  {
280
  "name": "phpcompatibility/php-compatibility",
281
  "version": "9.3.5",
337
  "source": "https://github.com/PHPCompatibility/PHPCompatibility"
338
  },
339
  "time": "2019-12-27T09:44:58+00:00"
340
+ },
341
+ {
342
+ "name": "squizlabs/php_codesniffer",
343
+ "version": "3.6.2",
344
+ "source": {
345
+ "type": "git",
346
+ "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
347
+ "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a"
348
+ },
349
+ "dist": {
350
+ "type": "zip",
351
+ "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a",
352
+ "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a",
353
+ "shasum": ""
354
+ },
355
+ "require": {
356
+ "ext-simplexml": "*",
357
+ "ext-tokenizer": "*",
358
+ "ext-xmlwriter": "*",
359
+ "php": ">=5.4.0"
360
+ },
361
+ "require-dev": {
362
+ "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
363
+ },
364
+ "bin": [
365
+ "bin/phpcs",
366
+ "bin/phpcbf"
367
+ ],
368
+ "type": "library",
369
+ "extra": {
370
+ "branch-alias": {
371
+ "dev-master": "3.x-dev"
372
+ }
373
+ },
374
+ "notification-url": "https://packagist.org/downloads/",
375
+ "license": [
376
+ "BSD-3-Clause"
377
+ ],
378
+ "authors": [
379
+ {
380
+ "name": "Greg Sherwood",
381
+ "role": "lead"
382
+ }
383
+ ],
384
+ "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
385
+ "homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
386
+ "keywords": [
387
+ "phpcs",
388
+ "standards"
389
+ ],
390
+ "support": {
391
+ "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues",
392
+ "source": "https://github.com/squizlabs/PHP_CodeSniffer",
393
+ "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
394
+ },
395
+ "time": "2021-12-12T21:44:58+00:00"
396
  }
397
  ],
398
+ "packages-dev": [],
399
  "aliases": [],
400
  "minimum-stability": "stable",
401
  "stability-flags": [],
creative-mail-plugin.php CHANGED
@@ -9,7 +9,7 @@
9
  * Plugin URI: https://wordpress.org/plugins/creative-mail-by-constant-contact/
10
  * Description: Free email marketing designed specifically for WordPress, Jetpack and WooCommerce. Send newsletters, promotions, updates and transactional e-commerce emails. Simple and easy, powered by Constant Contact’s rock solid reliability.
11
  * Author: Constant Contact
12
- * Version: 1.5.0
13
  * Author URI: https://www.constantcontact.com
14
  * WC requires at least: 3.0.0
15
  * WC tested up to: 5.1.0
@@ -27,7 +27,7 @@ function _load_ce4wp_plugin()
27
  define('CE4WP_PLUGIN_DIR', __DIR__ . '/');
28
  define('CE4WP_PLUGIN_URL', plugin_dir_url(__FILE__) . '/');
29
  define('CE4WP_PLUGIN_FILE', __FILE__);
30
- define('CE4WP_PLUGIN_VERSION', '1.5.0');
31
  define('CE4WP_INSTANCE_UUID_KEY', 'ce4wp_instance_uuid');
32
  define('CE4WP_INSTANCE_HANDSHAKE_TOKEN', 'ce4wp_handshake_token');
33
  define('CE4WP_INSTANCE_HANDSHAKE_EXPIRATION', 'ce4wp_handshake_expiration');
@@ -44,7 +44,7 @@ function _load_ce4wp_plugin()
44
  define('CE4WP_APP_GATEWAY_URL', 'https://app-gateway.creativemail.com/');
45
  define('CE4WP_APP_URL', 'https://app.creativemail.com/');
46
  define('CE4WP_ENVIRONMENT', 'PRODUCTION');
47
- define('CE4WP_BUILD_NUMBER', '1607');
48
  define('CE4WP_RAYGUN_PHP_KEY', 'Z85xL3mkgnW13Ri9DajGUg');
49
  define('CE4WP_BATCH_SIZE', 500);
50
  define('CE4WP_WC_API_KEY_ID', 'ce4wp_woocommerce_api_key_id');
9
  * Plugin URI: https://wordpress.org/plugins/creative-mail-by-constant-contact/
10
  * Description: Free email marketing designed specifically for WordPress, Jetpack and WooCommerce. Send newsletters, promotions, updates and transactional e-commerce emails. Simple and easy, powered by Constant Contact’s rock solid reliability.
11
  * Author: Constant Contact
12
+ * Version: 1.5.1
13
  * Author URI: https://www.constantcontact.com
14
  * WC requires at least: 3.0.0
15
  * WC tested up to: 5.1.0
27
  define('CE4WP_PLUGIN_DIR', __DIR__ . '/');
28
  define('CE4WP_PLUGIN_URL', plugin_dir_url(__FILE__) . '/');
29
  define('CE4WP_PLUGIN_FILE', __FILE__);
30
+ define('CE4WP_PLUGIN_VERSION', '1.5.1');
31
  define('CE4WP_INSTANCE_UUID_KEY', 'ce4wp_instance_uuid');
32
  define('CE4WP_INSTANCE_HANDSHAKE_TOKEN', 'ce4wp_handshake_token');
33
  define('CE4WP_INSTANCE_HANDSHAKE_EXPIRATION', 'ce4wp_handshake_expiration');
44
  define('CE4WP_APP_GATEWAY_URL', 'https://app-gateway.creativemail.com/');
45
  define('CE4WP_APP_URL', 'https://app.creativemail.com/');
46
  define('CE4WP_ENVIRONMENT', 'PRODUCTION');
47
+ define('CE4WP_BUILD_NUMBER', '1631');
48
  define('CE4WP_RAYGUN_PHP_KEY', 'Z85xL3mkgnW13Ri9DajGUg');
49
  define('CE4WP_BATCH_SIZE', 500);
50
  define('CE4WP_WC_API_KEY_ID', 'ce4wp_woocommerce_api_key_id');
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: Constant Contact
3
  Tags: email, marketing, newsletter, subscribe, contact form, constant contact, crm, automations, ecommerce, promotion, offers, retargeting
4
  Requires at least: 4.6
5
- Tested up to: 5.8
6
- Stable tag: 1.5.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.6
@@ -104,6 +104,7 @@ Creative Mail by Constant Contact [Privacy Notice](https://www.endurance.com/pri
104
  6. Enhance your brand with LogoBuilder
105
 
106
  == Changelog ==
 
107
  * 1.5.0 - Fix WooCommerce product lists, improved WooCommerce order workflows and improved contact management.
108
  * 1.4.9 - Fixes regarding WooCoomerce and Contact Sync Updates.
109
  * 1.4.8 - Redirect to main Creativ Email templates page when user has abandoned cart template deactivated. Fix sync error with contact form 7. Added automation trigger for customer buying products.
2
  Contributors: Constant Contact
3
  Tags: email, marketing, newsletter, subscribe, contact form, constant contact, crm, automations, ecommerce, promotion, offers, retargeting
4
  Requires at least: 4.6
5
+ Tested up to: 5.9
6
+ Stable tag: 1.5.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.6
104
  6. Enhance your brand with LogoBuilder
105
 
106
  == Changelog ==
107
+ * 1.5.1 - Fix outdated PHP classes
108
  * 1.5.0 - Fix WooCommerce product lists, improved WooCommerce order workflows and improved contact management.
109
  * 1.4.9 - Fixes regarding WooCoomerce and Contact Sync Updates.
110
  * 1.4.8 - Redirect to main Creativ Email templates page when user has abandoned cart template deactivated. Fix sync error with contact form 7. Added automation trigger for customer buying products.
src/Clients/CreativeMailClient.php CHANGED
@@ -5,7 +5,7 @@ namespace CreativeMail\Clients;
5
  use CreativeMail\Exceptions\CreativeMailException;
6
  use CreativeMail\Helpers\EnvironmentHelper;
7
  use CreativeMail\Helpers\OptionsHelper;
8
- use stdClass;
9
 
10
  class CreativeMailClient {
11
 
@@ -70,7 +70,7 @@ class CreativeMailClient {
70
  $most_recent_campaigns = [];
71
 
72
  foreach ( $campaigns_data as $campaign_data ) {
73
- $campaign = new stdClass();
74
  $campaign->id = $campaign_data['external_id'];
75
  $campaign->name = $campaign_data['name'];
76
 
5
  use CreativeMail\Exceptions\CreativeMailException;
6
  use CreativeMail\Helpers\EnvironmentHelper;
7
  use CreativeMail\Helpers\OptionsHelper;
8
+ use CreativeMail\Models\Campaign;
9
 
10
  class CreativeMailClient {
11
 
70
  $most_recent_campaigns = [];
71
 
72
  foreach ( $campaigns_data as $campaign_data ) {
73
+ $campaign = new Campaign();
74
  $campaign->id = $campaign_data['external_id'];
75
  $campaign->name = $campaign_data['name'];
76
 
src/Helpers/OptionsHelper.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  namespace CreativeMail\Helpers;
4
 
5
- use stdClass;
6
 
7
  /**
8
  * Class CE4WP_OptionsHelper
@@ -268,9 +268,9 @@ class OptionsHelper
268
  return self::convert_managed_email_notifications($row->option_value);
269
  }
270
 
271
- $item = new stdClass();
272
  $item->name = str_replace(CE4WP_MANAGED_EMAIL_NOTIFICATIONS . '_', '', $name);
273
- $item->active =$row->option_value == 'true';
274
  array_push($result, $item);
275
  }
276
 
2
 
3
  namespace CreativeMail\Helpers;
4
 
5
+ use CreativeMail\Models\OptionsSchema;
6
 
7
  /**
8
  * Class CE4WP_OptionsHelper
268
  return self::convert_managed_email_notifications($row->option_value);
269
  }
270
 
271
+ $item = new OptionsSchema();
272
  $item->name = str_replace(CE4WP_MANAGED_EMAIL_NOTIFICATIONS . '_', '', $name);
273
+ $item->active = $row->option_value == 'true';
274
  array_push($result, $item);
275
  }
276
 
src/Managers/AdminManager.php CHANGED
@@ -6,10 +6,10 @@ use CreativeMail\CreativeMail;
6
  use CreativeMail\Helpers\EnvironmentHelper;
7
  use CreativeMail\Helpers\OptionsHelper;
8
  use CreativeMail\Helpers\SsoHelper;
 
9
  use CreativeMail\Modules\DashboardWidgetModule;
10
  use CreativeMail\Modules\FeedbackNoticeModule;
11
  use Exception;
12
- use stdClass;
13
 
14
  /**
15
  * The AdminManager will manage the admin section of the plugin.
@@ -92,7 +92,7 @@ class AdminManager
92
 
93
  if (!wp_verify_nonce($nonce,self::ADMIN_AJAX_NONCE))
94
  {
95
- $response = new stdClass();
96
  $response->url = admin_url('admin.php?page=creativemail');
97
  wp_send_json_success($response);
98
  }
@@ -144,7 +144,7 @@ class AdminManager
144
  $linkReference = array_key_exists('link_reference', $_POST) ? $_POST['link_reference'] : null;
145
  $linkParameters = array_key_exists('link_parameters', $_POST) ? $_POST['link_parameters'] : null;
146
 
147
- $response = new stdClass();
148
  $response->url = $this->request_single_sign_on_url_internal($linkReference, $linkParameters);
149
 
150
  wp_send_json_success($response);
6
  use CreativeMail\Helpers\EnvironmentHelper;
7
  use CreativeMail\Helpers\OptionsHelper;
8
  use CreativeMail\Helpers\SsoHelper;
9
+ use CreativeMail\Models\Response;
10
  use CreativeMail\Modules\DashboardWidgetModule;
11
  use CreativeMail\Modules\FeedbackNoticeModule;
12
  use Exception;
 
13
 
14
  /**
15
  * The AdminManager will manage the admin section of the plugin.
92
 
93
  if (!wp_verify_nonce($nonce,self::ADMIN_AJAX_NONCE))
94
  {
95
+ $response = new Response();
96
  $response->url = admin_url('admin.php?page=creativemail');
97
  wp_send_json_success($response);
98
  }
144
  $linkReference = array_key_exists('link_reference', $_POST) ? $_POST['link_reference'] : null;
145
  $linkParameters = array_key_exists('link_parameters', $_POST) ? $_POST['link_parameters'] : null;
146
 
147
+ $response = new Response();
148
  $response->url = $this->request_single_sign_on_url_internal($linkReference, $linkParameters);
149
 
150
  wp_send_json_success($response);
src/Managers/ApiManager.php CHANGED
@@ -5,6 +5,8 @@ namespace CreativeMail\Managers;
5
 
6
  use CreativeMail\CreativeMail;
7
  use CreativeMail\Helpers\OptionsHelper;
 
 
8
  use CreativeMail\Modules\Api\Processes\ApiBackgroundProcess;
9
  use CreativeMail\Modules\Blog\Models\BlogAttachment;
10
  use CreativeMail\Modules\Blog\Models\BlogInformation;
@@ -477,7 +479,7 @@ class ApiManager
477
  $cs = openssl_encrypt($wcKey->consumer_secret, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
478
  $ck = openssl_encrypt($wcKey->consumer_key, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
479
 
480
- $result = new \stdClass();
481
  $result->salt = bin2hex($salt);
482
  $result->secret = base64_encode($cs);
483
  $result->key = base64_encode($ck);
@@ -632,7 +634,7 @@ class ApiManager
632
  throw new Exception('The key could not be saved');
633
  }
634
 
635
- $key = new \stdClass();
636
 
637
  $key->key_id = $wpdb->insert_id;
638
  $key->user_id = $user->ID;
5
 
6
  use CreativeMail\CreativeMail;
7
  use CreativeMail\Helpers\OptionsHelper;
8
+ use CreativeMail\Models\ApiSchema;
9
+ use CreativeMail\Models\HashSchema;
10
  use CreativeMail\Modules\Api\Processes\ApiBackgroundProcess;
11
  use CreativeMail\Modules\Blog\Models\BlogAttachment;
12
  use CreativeMail\Modules\Blog\Models\BlogInformation;
479
  $cs = openssl_encrypt($wcKey->consumer_secret, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
480
  $ck = openssl_encrypt($wcKey->consumer_key, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
481
 
482
+ $result = new HashSchema();
483
  $result->salt = bin2hex($salt);
484
  $result->secret = base64_encode($cs);
485
  $result->key = base64_encode($ck);
634
  throw new Exception('The key could not be saved');
635
  }
636
 
637
+ $key = new ApiSchema();
638
 
639
  $key->key_id = $wpdb->insert_id;
640
  $key->user_id = $user->ID;
src/Managers/CheckoutManager.php CHANGED
@@ -6,8 +6,14 @@ namespace CreativeMail\Managers;
6
  use CreativeMail\CreativeMail;
7
  use CreativeMail\Helpers\EnvironmentHelper;
8
  use CreativeMail\Helpers\OptionsHelper;
 
 
 
 
9
  use CreativeMail\Modules\Contacts\Models\OptActionBy;
10
- use stdClass;
 
 
11
  use WC_Coupon;
12
  use WC_Order;
13
 
@@ -102,7 +108,7 @@ class CheckoutManager
102
  *
103
  * @since 1.3.0
104
  */
105
- public function ce4wp_filter_checkout_fields($fields) {
106
  $fields['billing'][self::BILLING_EMAIL_NOTICE] = array(
107
  'type' => 'ce4wp_notice',
108
  'required' => false,
@@ -141,10 +147,10 @@ class CheckoutManager
141
  *
142
  * @return void
143
  */
144
- public function order_completed($order_id)
145
  {
146
- $this->update_checkout($order_id, '/v1.0/checkout/order_completed');
147
- $this->cleanup_old_checkouts($order_id);
148
  }
149
 
150
  /**
@@ -156,8 +162,8 @@ class CheckoutManager
156
  *
157
  * @return void
158
  */
159
- public function order_processed( $order_id) {
160
- $this->update_checkout($order_id, '/v1.0/checkout/order_created');
161
  }
162
 
163
  /**
@@ -180,7 +186,7 @@ class CheckoutManager
180
  $data = $this->get_checkout_uuid_by_email($order->get_billing_email());
181
  foreach ($data as $checkout_data)
182
  {
183
- $endpoint = EnvironmentHelper::get_app_gateway_url('wordpress') . '/v1.0/checkout/'. $checkout_data->checkout_uuid;
184
  $this->ce4wp_remote_delete($endpoint);
185
  CreativeMail::get_instance()->get_database_manager()->remove_checkout_data($checkout_data->checkout_uuid);
186
  }
@@ -199,8 +205,8 @@ class CheckoutManager
199
  *
200
  * @since 1.3.0
201
  */
202
- private function update_checkout($order_id, $endpoint) {
203
- $order = wc_get_order($order_id);
204
  if ( empty( $order ) ) {
205
  return;
206
  }
@@ -208,23 +214,23 @@ class CheckoutManager
208
  // check if order had checkout uuid
209
  $uuid = $order->get_meta( self::META_CHECKOUT_UUID, true);
210
  // check if order is created with checkout meta
211
- if (empty($uuid)) {
212
  return;
213
  }
214
 
215
  // try find recovery date from order meta data
216
- $recovery_date = $order->get_meta( self::META_CHECKOUT_RECOVERED, true);
217
  // Remote post to ce4wp marking checkout as completed/created
218
- $requestItem = new stdClass();
219
  $requestItem->uuid = $uuid;
220
  $requestItem->order_id = $order->get_id();
221
  $requestItem->order_total = $order->get_total();
222
  $requestItem->order_currency = $order->get_currency();
223
- $requestItem->recovery_date = (empty($recovery_date) || $recovery_date === self::DATETIME_ZERO) ? null : $recovery_date;
224
 
225
- $endpoint = EnvironmentHelper::get_app_gateway_url('wordpress') . $endpoint;
226
  // call remote endpoint to update
227
- $this->ce4wp_remote_post($requestItem, $endpoint);
228
  }
229
 
230
  /**
@@ -291,9 +297,9 @@ class CheckoutManager
291
  wp_send_json_success();
292
  }
293
 
294
- $endpoint = EnvironmentHelper::get_app_gateway_url('wordpress') . '/v1.0/checkout/'. $checkout_id;
295
- $this->ce4wp_remote_delete($endpoint);
296
- CreativeMail::get_instance()->get_database_manager()->change_checkout_consent($checkout_id, false);
297
 
298
  wp_send_json_success();
299
  }
@@ -305,7 +311,7 @@ class CheckoutManager
305
  *
306
  * @since 1.3.0
307
  */
308
- public function save_or_clear_checkout_data( $template_name) {
309
 
310
  // If checkout page displayed, save checkout data.
311
  if ( 'checkout/form-checkout.php' === $template_name ) {
@@ -407,15 +413,15 @@ class CheckoutManager
407
  }
408
  }
409
  }
410
- $is_checkout = $is_checkout ?: is_checkout();
411
  $uuid = WC()->session->get( self::CHECKOUT_UUID );
412
 
413
  if ( empty( $billing_email ) ) {
414
  return;
415
  }
416
 
417
- $has_no_consent = WC()->session->get( self::BILLING_EMAIL_NO_CONSENT);
418
- if($has_no_consent === true)
419
  {
420
  return;
421
  }
@@ -451,23 +457,23 @@ class CheckoutManager
451
  $cart_coupons = WC()->cart->get_applied_coupons();
452
 
453
  $checkout_content = [
454
- self::PRODUCTS => array_values($cart_products),
455
  self::COUPONS => $cart_coupons,
456
  ];
457
 
458
- CreativeMail::get_instance()->get_database_manager()->upsert_checkout($uuid, $user_id, $billing_email, $checkout_content, $current_time);
459
 
460
  // Remote post to ce4wp create or update cart if email is provided
461
- $requestItem = new stdClass();
462
- $requestItem->data = wp_json_encode($this->get_cart_data_for_endpoint($cart_products, $cart_coupons));
463
  $requestItem->uuid = $uuid;
464
  $requestItem->user_id = $user_id;
465
  $requestItem->billing_email = $billing_email;
466
- $requestItem->timestamp = strtotime($current_time);
467
- $endpoint = EnvironmentHelper::get_app_gateway_url('wordpress') . '/v1.0/checkout/upsert';
468
 
469
- $consent = CreativeMail::get_instance()->get_database_manager()->has_checkout_consent($uuid);
470
- if ($consent) {
471
  $this->ce4wp_remote_post($requestItem, $endpoint);
472
  }
473
  }
@@ -477,20 +483,19 @@ class CheckoutManager
477
  *
478
  * @since 1.3.0
479
  */
480
- private function get_cart_data_for_endpoint($cart_products, $cart_coupons) {
481
- $data = new stdClass();
482
  $data->products = array();
483
  $data->coupons = array();
484
  $data->currency_symbol = get_woocommerce_currency_symbol();
485
  $data->currency = get_woocommerce_currency();
486
 
487
- $data->user = new stdClass();
488
-
489
  try
490
  {
491
  // Get user first and last name of available
492
  $current_user = wp_get_current_user();
493
- if ($current_user->exists() ) {
494
  $data->user->id = $current_user->ID;
495
  $data->user->username = $current_user->user_login;
496
  $data->user->display_name = $current_user->display_name;
@@ -501,30 +506,30 @@ class CheckoutManager
501
 
502
  $dp = 2; // decimal point
503
 
504
- foreach ($cart_products as $value)
505
  {
506
- $product = array_key_exists('data', $value) ? $value['data'] : wc_get_product($value[self::PRODUCT_ID]);
507
  $product_id = $product->get_id();
508
  $product_data = array(
509
  'images' => array()
510
  );
511
  $attachment_ids = $product->get_gallery_image_ids();
512
- foreach ($attachment_ids as $attachment_id) {
513
- $product_data['images'][] = wp_get_attachment_url($attachment_id);
514
  }
515
 
516
- $product_data["on_sale"] = $product->is_on_sale();
517
- $product_data["sale_price"] = $product->get_sale_price();
518
- $product_data["regular_price"] = $product->get_regular_price();
519
  $src = wc_placeholder_img_src();
520
- if ($image_id = $product->get_image_id()) {
521
- list($src) = wp_get_attachment_image_src($image_id, 'full');
522
  }
523
 
524
- $line_subtotal = empty($value['line_subtotal']) ? 0: $value['line_subtotal'];
525
- $line_subtotal_tax =empty($value['line_subtotal_tax']) ? 0: $value['line_subtotal_tax'];
526
- $line_total = empty($value['line_total']) ? 0: $value['line_total'];
527
- $line_tax = empty($value['line_tax']) ? 0: $value['line_tax'];
528
 
529
  $data->products[] = array(
530
  'name' => $product->get_name(),
@@ -532,23 +537,23 @@ class CheckoutManager
532
  'product_image' => $src,
533
  'product_data' => $product_data,
534
  'sku' => is_object($product) ? $product->get_sku() : null,
535
- 'product_url' => get_the_permalink($product_id),
536
- 'variation_id' => $value[self::VARIATION_ID],
537
- 'subtotal' => wc_format_decimal($line_subtotal, $dp),
538
- 'subtotal_tax' => wc_format_decimal($line_subtotal_tax, $dp),
539
- 'total' => wc_format_decimal($line_total, $dp),
540
- 'total_tax' => wc_format_decimal($line_tax, $dp),
541
- 'price' => wc_format_decimal($line_subtotal, $dp),
542
- 'quantity' => $value[self::QUANTITY]
543
  );
544
  }
545
 
546
- foreach ($cart_coupons as $coupon_code)
547
  {
548
- $coupon_id = wc_get_coupon_id_by_code($coupon_code);
549
- if ($coupon_id)
550
  {
551
- $coupon = new WC_Coupon($coupon_id);
552
 
553
  $data->coupons[] = array(
554
  'code' => $coupon->get_code(),
@@ -562,7 +567,7 @@ class CheckoutManager
562
  }
563
  catch (\Exception $e)
564
  {
565
- RaygunManager::get_instance()->exception_handler($e);
566
  }
567
 
568
  return $data;
@@ -577,22 +582,22 @@ class CheckoutManager
577
  *
578
  * @return void
579
  */
580
- public function clear_purchased_data( $order) {
581
  $checkout_id = WC()->session->get( self::CHECKOUT_UUID );
582
- if (empty($checkout_id)) {
583
  return;
584
  }
585
 
586
  $order->update_meta_data( self::META_CHECKOUT_UUID, $checkout_id );
587
 
588
  // get the recovery date if recovered
589
- $recovery_date = $this->get_checkout_recovery_date($checkout_id);
590
- if (!empty($recovery_date) && $recovery_date !== self::DATETIME_ZERO)
591
  {
592
- $order->update_meta_data(self::META_CHECKOUT_RECOVERED, $recovery_date);
593
  }
594
- CreativeMail::get_instance()->get_database_manager()->remove_checkout_data($checkout_id);
595
- WC()->session->__unset( self::CHECKOUT_UUID );
596
  }
597
 
598
  /**
@@ -613,18 +618,18 @@ class CheckoutManager
613
  // Get saved checkout contents.
614
  $checkout_contents = $this->get_checkout_contents( $this->checkout_uuid );
615
 
616
- if ( empty($checkout_contents) ) {
617
  return;
618
  }
619
 
620
  // Mark checkout as recovered
621
- CreativeMail::get_instance()->get_database_manager()->mark_checkout_recovered($this->checkout_uuid);
622
 
623
  // Recover saved products.
624
- $this->recover_products( $checkout_contents[self::PRODUCTS] );
625
 
626
  // Apply coupons.
627
- foreach ( $checkout_contents[self::COUPONS] as $coupon ) {
628
  WC()->cart->apply_coupon( $coupon );
629
  }
630
 
@@ -641,7 +646,7 @@ class CheckoutManager
641
  }
642
 
643
  public function return_to_shop() {
644
- wp_safe_redirect(wc_get_page_permalink('shop'));
645
 
646
  exit();
647
  }
@@ -674,20 +679,20 @@ class CheckoutManager
674
  * @since 1.3.0
675
  */
676
  protected function recover_products( $products ) {
677
- if (empty($products)) {
678
  return;
679
  }
680
  // Programmatically add each product to cart.
681
  $products_added = [];
682
  foreach ( $products as $product ) {
683
  $added = WC()->cart->add_to_cart(
684
- $product[self::PRODUCT_ID],
685
- $product[self::QUANTITY],
686
- empty( $product[self::VARIATION_ID] ) ? 0 : $product[self::VARIATION_ID],
687
- empty( $product[self::VARIATION] ) ? array() : $product[self::VARIATION]
688
  );
689
  if ( false !== $added ) {
690
- $products_added[ ( empty( $product[self::VARIATION_ID] ) ? $product[self::PRODUCT_ID] : $product[self::VARIATION_ID] ) ] = $product[self::QUANTITY];
691
  }
692
  }
693
 
@@ -712,12 +717,12 @@ class CheckoutManager
712
  }
713
  }
714
 
715
- private function ce4wp_remote_post($requestItem, $endpoint) {
716
  try
717
  {
718
  // check if abandoned cart email is managed by creative mail
719
- $enabled = CreativeMail::get_instance()->get_email_manager()->is_email_managed('cart_abandoned_ce4wp');
720
- if($enabled) {
721
  wp_remote_post(
722
  $endpoint, array(
723
  'method' => 'POST',
@@ -727,18 +732,18 @@ class CheckoutManager
727
  'x-api-key' => OptionsHelper::get_instance_api_key(),
728
  'content-type' => 'application/json'
729
  ),
730
- 'body' => wp_json_encode($requestItem)
731
  )
732
  );
733
  }
734
- } catch (\Exception $e) {
735
- RaygunManager::get_instance()->exception_handler($e);
736
  }
737
  }
738
 
739
- private function ce4wp_remote_delete($endpoint) {
740
  try {
741
- wp_remote_request($endpoint,
742
  array(
743
  'method' => 'DELETE',
744
  'headers' => array(
@@ -747,43 +752,43 @@ class CheckoutManager
747
  )
748
  )
749
  );
750
- } catch (\Exception $e) {
751
  // silent
752
  }
753
  }
754
 
755
- private function get_opt_action_by($products_detail) {
756
  return OptActionBy::Visitor;
757
  }
758
 
759
- private function get_opt_in_checkbox_value($products_detail) {
760
- if (!empty($products_detail["ce4wp_checkout_consent"])) {
761
- return $products_detail["ce4wp_checkout_consent"][0]; //this value appears to be in array;
762
  }
763
 
764
  return null;
765
  }
766
 
767
- private function get_opt_in($products_detail) {
768
- $checkbox_value = $this->get_opt_in_checkbox_value($products_detail);
769
- if ($checkbox_value == true)
770
  return true;
771
  return null;
772
  }
773
 
774
- private function get_opt_out($products_detail) {
775
- $checkbox_value = $this->get_opt_in_checkbox_value($products_detail);
776
- if ($checkbox_value == false)
777
  return true;
778
  return null;
779
  }
780
 
781
  public function add_order_completed_wc_hooks() {
782
- add_action('woocommerce_order_status_completed', array($this, 'order_completed_trigger_wc_hook'), 10, 1);
783
  }
784
 
785
- public function order_completed_trigger_wc_hook($order_id) {
786
- $order = wc_get_order($order_id);
787
  if ( empty( $order ) ) {
788
  return;
789
  }
@@ -794,7 +799,10 @@ class CheckoutManager
794
  $decimal_point = 2;
795
 
796
  // General Info
797
- $requestItem = new stdClass();
 
 
 
798
  $requestItem->order_id = $order->get_id();
799
  $requestItem->order_number = $order->get_order_number();
800
  $requestItem->date_created = $order->get_date_created() ? $order->get_date_created()->getTimestamp() : 0;
@@ -807,25 +815,24 @@ class CheckoutManager
807
  $requestItem->customer_user_agent = $order->get_customer_user_agent();
808
  $requestItem->customer_id = $order->get_user_id();
809
  // Order Billing
810
- $requestItem->order->billing->email = $order->get_billing_email();
811
-
812
- $requestItem->order->billing->opt_action_by = $this->get_opt_action_by($products_detail);
813
- $requestItem->order->billing->opt_in = $this->get_opt_in($products_detail);
814
- $requestItem->order->billing->opt_out = $this->get_opt_out($products_detail);
815
-
816
- $requestItem->order->billing->first_name = $order->get_billing_first_name();
817
- $requestItem->order->billing->last_name = $order->get_billing_last_name();
818
- $requestItem->order->billing->is_first_time_buyer = count(wc_get_orders(array('email' => $order->get_billing_email()))) <= 1;
819
- $requestItem->order->billing->company = $order->get_billing_company();
820
- $requestItem->order->billing->address_1 = $order->get_billing_address_1();
821
- $requestItem->order->billing->address_2 = $order->get_billing_address_2();
822
- $requestItem->order->billing->city = $order->get_billing_city();
823
- $requestItem->order->billing->state = $order->get_billing_state();
824
- $requestItem->order->billing->postcode = $order->get_billing_postcode();
825
- $requestItem->order->billing->country = $order->get_billing_country();
826
- $requestItem->order->billing->email = $order->get_billing_email();
827
- $requestItem->order->billing->phone = $order->get_billing_phone();
828
- $requestItem->order->billing->shipping = array(
829
  'first_name' => $order->get_shipping_first_name(),
830
  'last_name' => $order->get_shipping_last_name(),
831
  'company' => $order->get_shipping_company(),
@@ -837,37 +844,37 @@ class CheckoutManager
837
  'country' => $order->get_shipping_country(),
838
  'shipping_methods' => $order->get_shipping_method()
839
  );
840
- $requestItem->order->billing->payment_details = array(
841
  'method_id' => $order->get_payment_method(),
842
  'method_title' => $order->get_payment_method_title(),
843
  'paid' => !is_null($order->get_date_paid()),
844
  );
845
  // Order Currency and Total Info
846
- $requestItem->total = wc_format_decimal($order->get_total(), $decimal_point);
847
- $requestItem->subtotal = wc_format_decimal($order->get_subtotal(), $decimal_point);
848
- $requestItem->total_tax = wc_format_decimal($order->get_total_tax(), $decimal_point);
849
- $requestItem->shipping_total = wc_format_decimal($order->get_shipping_total(), $decimal_point);
850
- $requestItem->cart_tax = wc_format_decimal($order->get_cart_tax(), $decimal_point);
851
- $requestItem->shipping_tax = wc_format_decimal($order->get_shipping_tax(), $decimal_point);
852
- $requestItem->discount_total = wc_format_decimal($order->get_total_discount(), $decimal_point);
853
- $requestItem->order->currency_symbol = get_woocommerce_currency_symbol();
854
- $requestItem->order->currency = $order->get_currency();
855
  // Order Products Info
856
- $requestItem->order->total_line_items_quantity = $order->get_item_count();
857
  // Line Items / Products array for the expected endpoint
858
- foreach ($order->get_items() as $itemsKey => $item) {
859
  $product = $item->get_product();
860
 
861
- if (empty($product)) {
862
  continue;
863
  }
864
 
865
  $item_meta = $item->get_formatted_meta_data();
866
 
867
- foreach ($item_meta as $key => $values) {
868
- $item_meta[$key]->label = $values->display_key;
869
- unset($item_meta[$key]->display_key);
870
- unset($item_meta[$key]->display_value);
871
  }
872
 
873
  try {
@@ -876,62 +883,65 @@ class CheckoutManager
876
  'downloads' => array()
877
  );
878
  $attachment_ids = $product->get_gallery_image_ids();
879
- foreach ($attachment_ids as $attachment_id) {
880
- $product_data['images'][] = wp_get_attachment_url($attachment_id);
881
  }
882
 
883
- $product_data["on_sale"] = $product->is_on_sale();
884
- $product_data["sale_price"] = $product->get_sale_price();
885
- $product_data["regular_price"] = $product->get_regular_price();
886
 
887
- if ($product->is_downloadable()) {
888
  $item_downloads = $item->get_item_downloads();
889
- foreach ($item_downloads as $item_download)
890
  {
891
- $product_data["downloads"][] = array(
892
  'line_item_id' => $item->get_id(),
893
  'product_id' => $item->get_product_id(),
894
- 'download_url' => $item_download["download_url"],
895
- 'download_file' => $item_download["file"],
896
- 'download_name' => $item_download["name"],
897
- 'download_id' => $item_download["id"],
898
- 'downloads_remaining' => $item_download["downloads_remaining"],
899
- 'download_access_expires' => wc_format_datetime($item_download["access_expires"], 'U'),
900
  'download_limit' => $product->get_download_limit(),
901
  'download_expiry' => $product->get_download_expiry(),
902
  );
903
  }
904
  }
905
- } catch (\Exception $ex) {
906
- RaygunManager::get_instance()->exception_handler($ex);
907
  }
908
 
909
  $src = wc_placeholder_img_src();
910
- if ($image_id = $product->get_image_id() ) {
911
- list( $src ) = wp_get_attachment_image_src($image_id, 'full');
912
  }
913
 
914
- $requestItem->order->line_items[] = array(
915
  'product_id' => $item->get_product_id(),
916
  'item_meta' => $item->get_formatted_meta_data(),
917
- 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $decimal_point),
918
- 'subtotal_tax' => wc_format_decimal($item->get_subtotal_tax(), $decimal_point),
919
- 'total' => wc_format_decimal($order->get_line_total($item, false, false), $decimal_point),
920
- 'total_tax' => wc_format_decimal($item->get_total_tax(), $decimal_point),
921
- 'price' => wc_format_decimal($order->get_item_total($item, false, false), $decimal_point),
922
  'quantity' => $item->get_quantity(),
923
  'tax_class' => $item->get_tax_class(),
924
  'name' => $item->get_name(),
925
  'product_image' => $src,
926
  'product_data' => $product_data,
927
- 'sku' => is_object($product) ? $product->get_sku() : null,
928
- 'meta' => array_values($item_meta),
929
- 'product_url' => get_the_permalink($item->get_product_id()),
930
  'variation_id' => $item->get_variation_id()
931
  );
932
  }
933
 
934
- $endpoint = EnvironmentHelper::get_app_gateway_url('wordpress') . $endpoint;
 
 
 
935
  try
936
  {
937
  wp_remote_post(
@@ -943,11 +953,11 @@ class CheckoutManager
943
  'x-api-key' => OptionsHelper::get_instance_api_key(),
944
  'content-type' => 'application/json'
945
  ),
946
- 'body' => wp_json_encode($requestItem)
947
  )
948
  );
949
- } catch (\Exception $e) {
950
- RaygunManager::get_instance()->exception_handler($e);
951
  }
952
  }
953
  }
6
  use CreativeMail\CreativeMail;
7
  use CreativeMail\Helpers\EnvironmentHelper;
8
  use CreativeMail\Helpers\OptionsHelper;
9
+ use CreativeMail\Models\CartData;
10
+ use CreativeMail\Models\Checkout;
11
+ use CreativeMail\Models\CheckoutSave;
12
+ use CreativeMail\Models\User;
13
  use CreativeMail\Modules\Contacts\Models\OptActionBy;
14
+ use CreativeMail\Models\Order;
15
+ use CreativeMail\Models\OrderBilling;
16
+ use CreativeMail\Models\RequestItem;
17
  use WC_Coupon;
18
  use WC_Order;
19
 
108
  *
109
  * @since 1.3.0
110
  */
111
+ public function ce4wp_filter_checkout_fields( $fields ) {
112
  $fields['billing'][self::BILLING_EMAIL_NOTICE] = array(
113
  'type' => 'ce4wp_notice',
114
  'required' => false,
147
  *
148
  * @return void
149
  */
150
+ public function order_completed( $order_id )
151
  {
152
+ $this->update_checkout( $order_id, '/v1.0/checkout/order_completed' );
153
+ $this->cleanup_old_checkouts( $order_id );
154
  }
155
 
156
  /**
162
  *
163
  * @return void
164
  */
165
+ public function order_processed( $order_id ) {
166
+ $this->update_checkout( $order_id, '/v1.0/checkout/order_created' );
167
  }
168
 
169
  /**
186
  $data = $this->get_checkout_uuid_by_email($order->get_billing_email());
187
  foreach ($data as $checkout_data)
188
  {
189
+ $endpoint = EnvironmentHelper::get_app_gateway_url( 'wordpress' ) . '/v1.0/checkout/'. $checkout_data->checkout_uuid;
190
  $this->ce4wp_remote_delete($endpoint);
191
  CreativeMail::get_instance()->get_database_manager()->remove_checkout_data($checkout_data->checkout_uuid);
192
  }
205
  *
206
  * @since 1.3.0
207
  */
208
+ private function update_checkout( $order_id, $endpoint ) {
209
+ $order = wc_get_order( $order_id );
210
  if ( empty( $order ) ) {
211
  return;
212
  }
214
  // check if order had checkout uuid
215
  $uuid = $order->get_meta( self::META_CHECKOUT_UUID, true);
216
  // check if order is created with checkout meta
217
+ if ( empty( $uuid ) ) {
218
  return;
219
  }
220
 
221
  // try find recovery date from order meta data
222
+ $recovery_date = $order->get_meta( self::META_CHECKOUT_RECOVERED, true );
223
  // Remote post to ce4wp marking checkout as completed/created
224
+ $requestItem = new Checkout();
225
  $requestItem->uuid = $uuid;
226
  $requestItem->order_id = $order->get_id();
227
  $requestItem->order_total = $order->get_total();
228
  $requestItem->order_currency = $order->get_currency();
229
+ $requestItem->recovery_date = ( empty( $recovery_date ) || $recovery_date === self::DATETIME_ZERO ) ? null : $recovery_date;
230
 
231
+ $endpoint = EnvironmentHelper::get_app_gateway_url( 'wordpress' ) . $endpoint;
232
  // call remote endpoint to update
233
+ $this->ce4wp_remote_post( $requestItem, $endpoint );
234
  }
235
 
236
  /**
297
  wp_send_json_success();
298
  }
299
 
300
+ $endpoint = EnvironmentHelper::get_app_gateway_url( 'wordpress' ) . '/v1.0/checkout/'. $checkout_id;
301
+ $this->ce4wp_remote_delete( $endpoint );
302
+ CreativeMail::get_instance()->get_database_manager()->change_checkout_consent( $checkout_id, false );
303
 
304
  wp_send_json_success();
305
  }
311
  *
312
  * @since 1.3.0
313
  */
314
+ public function save_or_clear_checkout_data( $template_name ) {
315
 
316
  // If checkout page displayed, save checkout data.
317
  if ( 'checkout/form-checkout.php' === $template_name ) {
413
  }
414
  }
415
  }
416
+ $is_checkout = $is_checkout ?: is_checkout();
417
  $uuid = WC()->session->get( self::CHECKOUT_UUID );
418
 
419
  if ( empty( $billing_email ) ) {
420
  return;
421
  }
422
 
423
+ $has_no_consent = WC()->session->get( self::BILLING_EMAIL_NO_CONSENT );
424
+ if( $has_no_consent === true )
425
  {
426
  return;
427
  }
457
  $cart_coupons = WC()->cart->get_applied_coupons();
458
 
459
  $checkout_content = [
460
+ self::PRODUCTS => array_values( $cart_products ),
461
  self::COUPONS => $cart_coupons,
462
  ];
463
 
464
+ CreativeMail::get_instance()->get_database_manager()->upsert_checkout( $uuid, $user_id, $billing_email, $checkout_content, $current_time );
465
 
466
  // Remote post to ce4wp create or update cart if email is provided
467
+ $requestItem = new CheckoutSave();
468
+ $requestItem->data = wp_json_encode($this->get_cart_data_for_endpoint( $cart_products, $cart_coupons ) );
469
  $requestItem->uuid = $uuid;
470
  $requestItem->user_id = $user_id;
471
  $requestItem->billing_email = $billing_email;
472
+ $requestItem->timestamp = strtotime( $current_time );
473
+ $endpoint = EnvironmentHelper::get_app_gateway_url( 'wordpress' ) . '/v1.0/checkout/upsert';
474
 
475
+ $consent = CreativeMail::get_instance()->get_database_manager()->has_checkout_consent( $uuid );
476
+ if ( $consent ) {
477
  $this->ce4wp_remote_post($requestItem, $endpoint);
478
  }
479
  }
483
  *
484
  * @since 1.3.0
485
  */
486
+ private function get_cart_data_for_endpoint( $cart_products, $cart_coupons ) {
487
+ $data = new CartData();
488
  $data->products = array();
489
  $data->coupons = array();
490
  $data->currency_symbol = get_woocommerce_currency_symbol();
491
  $data->currency = get_woocommerce_currency();
492
 
493
+ $data->user = new User();
 
494
  try
495
  {
496
  // Get user first and last name of available
497
  $current_user = wp_get_current_user();
498
+ if ( $current_user->exists() ) {
499
  $data->user->id = $current_user->ID;
500
  $data->user->username = $current_user->user_login;
501
  $data->user->display_name = $current_user->display_name;
506
 
507
  $dp = 2; // decimal point
508
 
509
+ foreach ( $cart_products as $value )
510
  {
511
+ $product = array_key_exists( 'data', $value ) ? $value['data'] : wc_get_product( $value[self::PRODUCT_ID] );
512
  $product_id = $product->get_id();
513
  $product_data = array(
514
  'images' => array()
515
  );
516
  $attachment_ids = $product->get_gallery_image_ids();
517
+ foreach ( $attachment_ids as $attachment_id ) {
518
+ $product_data[ 'images' ][] = wp_get_attachment_url( $attachment_id );
519
  }
520
 
521
+ $product_data[ "on_sale" ] = $product->is_on_sale();
522
+ $product_data[ "sale_price" ] = $product->get_sale_price();
523
+ $product_data[ "regular_price" ] = $product->get_regular_price();
524
  $src = wc_placeholder_img_src();
525
+ if ( $image_id = $product->get_image_id() ) {
526
+ list( $src ) = wp_get_attachment_image_src( $image_id, 'full' );
527
  }
528
 
529
+ $line_subtotal = empty( $value['line_subtotal'] ) ? 0: $value[ 'line_subtotal' ];
530
+ $line_subtotal_tax =empty( $value[ 'line_subtotal_tax' ] ) ? 0: $value[ 'line_subtotal_tax' ];
531
+ $line_total = empty( $value[ 'line_total' ] ) ? 0: $value[ 'line_total' ];
532
+ $line_tax = empty( $value[ 'line_tax' ] ) ? 0: $value[ 'line_tax' ];
533
 
534
  $data->products[] = array(
535
  'name' => $product->get_name(),
537
  'product_image' => $src,
538
  'product_data' => $product_data,
539
  'sku' => is_object($product) ? $product->get_sku() : null,
540
+ 'product_url' => get_the_permalink( $product_id ),
541
+ 'variation_id' => $value[ self::VARIATION_ID ],
542
+ 'subtotal' => wc_format_decimal( $line_subtotal, $dp ),
543
+ 'subtotal_tax' => wc_format_decimal( $line_subtotal_tax, $dp ),
544
+ 'total' => wc_format_decimal( $line_total, $dp ),
545
+ 'total_tax' => wc_format_decimal( $line_tax, $dp ),
546
+ 'price' => wc_format_decimal( $line_subtotal, $dp ),
547
+ 'quantity' => $value[ self::QUANTITY ]
548
  );
549
  }
550
 
551
+ foreach ( $cart_coupons as $coupon_code )
552
  {
553
+ $coupon_id = wc_get_coupon_id_by_code( $coupon_code );
554
+ if ( $coupon_id )
555
  {
556
+ $coupon = new WC_Coupon( $coupon_id );
557
 
558
  $data->coupons[] = array(
559
  'code' => $coupon->get_code(),
567
  }
568
  catch (\Exception $e)
569
  {
570
+ RaygunManager::get_instance()->exception_handler( $e );
571
  }
572
 
573
  return $data;
582
  *
583
  * @return void
584
  */
585
+ public function clear_purchased_data( $order ) {
586
  $checkout_id = WC()->session->get( self::CHECKOUT_UUID );
587
+ if ( empty( $checkout_id ) ) {
588
  return;
589
  }
590
 
591
  $order->update_meta_data( self::META_CHECKOUT_UUID, $checkout_id );
592
 
593
  // get the recovery date if recovered
594
+ $recovery_date = $this->get_checkout_recovery_date( $checkout_id );
595
+ if ( !empty( $recovery_date ) && $recovery_date !== self::DATETIME_ZERO )
596
  {
597
+ $order->update_meta_data( self::META_CHECKOUT_RECOVERED, $recovery_date );
598
  }
599
+ CreativeMail::get_instance()->get_database_manager()->remove_checkout_data( $checkout_id );
600
+ WC()->session->__unset( self::CHECKOUT_UUID );
601
  }
602
 
603
  /**
618
  // Get saved checkout contents.
619
  $checkout_contents = $this->get_checkout_contents( $this->checkout_uuid );
620
 
621
+ if ( empty( $checkout_contents ) ) {
622
  return;
623
  }
624
 
625
  // Mark checkout as recovered
626
+ CreativeMail::get_instance()->get_database_manager()->mark_checkout_recovered( $this->checkout_uuid );
627
 
628
  // Recover saved products.
629
+ $this->recover_products( $checkout_contents[ self::PRODUCTS ] );
630
 
631
  // Apply coupons.
632
+ foreach ( $checkout_contents[ self::COUPONS ] as $coupon ) {
633
  WC()->cart->apply_coupon( $coupon );
634
  }
635
 
646
  }
647
 
648
  public function return_to_shop() {
649
+ wp_safe_redirect( wc_get_page_permalink( 'shop' ) );
650
 
651
  exit();
652
  }
679
  * @since 1.3.0
680
  */
681
  protected function recover_products( $products ) {
682
+ if ( empty( $products ) ) {
683
  return;
684
  }
685
  // Programmatically add each product to cart.
686
  $products_added = [];
687
  foreach ( $products as $product ) {
688
  $added = WC()->cart->add_to_cart(
689
+ $product[ self::PRODUCT_ID ],
690
+ $product[ self::QUANTITY ],
691
+ empty( $product[ self::VARIATION_ID ] ) ? 0 : $product[ self::VARIATION_ID ],
692
+ empty( $product[ self::VARIATION ] ) ? array() : $product[ self::VARIATION ]
693
  );
694
  if ( false !== $added ) {
695
+ $products_added[ ( empty( $product[ self::VARIATION_ID ] ) ? $product[ self::PRODUCT_ID ] : $product[ self::VARIATION_ID ] ) ] = $product[ self::QUANTITY ];
696
  }
697
  }
698
 
717
  }
718
  }
719
 
720
+ private function ce4wp_remote_post( $requestItem, $endpoint ) {
721
  try
722
  {
723
  // check if abandoned cart email is managed by creative mail
724
+ $enabled = CreativeMail::get_instance()->get_email_manager()->is_email_managed( 'cart_abandoned_ce4wp' );
725
+ if( $enabled ) {
726
  wp_remote_post(
727
  $endpoint, array(
728
  'method' => 'POST',
732
  'x-api-key' => OptionsHelper::get_instance_api_key(),
733
  'content-type' => 'application/json'
734
  ),
735
+ 'body' => wp_json_encode( $requestItem )
736
  )
737
  );
738
  }
739
+ } catch ( \Exception $e ) {
740
+ RaygunManager::get_instance()->exception_handler( $e );
741
  }
742
  }
743
 
744
+ private function ce4wp_remote_delete( $endpoint ) {
745
  try {
746
+ wp_remote_request( $endpoint,
747
  array(
748
  'method' => 'DELETE',
749
  'headers' => array(
752
  )
753
  )
754
  );
755
+ } catch ( \Exception $e ) {
756
  // silent
757
  }
758
  }
759
 
760
+ private function get_opt_action_by( $products_detail ) {
761
  return OptActionBy::Visitor;
762
  }
763
 
764
+ private function get_opt_in_checkbox_value( $products_detail ) {
765
+ if ( !empty( $products_detail[ "ce4wp_checkout_consent" ] ) ) {
766
+ return $products_detail[ "ce4wp_checkout_consent" ][ 0 ]; //this value appears to be in array;
767
  }
768
 
769
  return null;
770
  }
771
 
772
+ private function get_opt_in( $products_detail ) {
773
+ $checkbox_value = $this->get_opt_in_checkbox_value( $products_detail );
774
+ if ( $checkbox_value == true )
775
  return true;
776
  return null;
777
  }
778
 
779
+ private function get_opt_out( $products_detail ) {
780
+ $checkbox_value = $this->get_opt_in_checkbox_value( $products_detail );
781
+ if ( $checkbox_value == false )
782
  return true;
783
  return null;
784
  }
785
 
786
  public function add_order_completed_wc_hooks() {
787
+ add_action( 'woocommerce_order_status_completed', array( $this, 'order_completed_trigger_wc_hook' ), 10, 1 );
788
  }
789
 
790
+ public function order_completed_trigger_wc_hook( $order_id ) {
791
+ $order = wc_get_order( $order_id );
792
  if ( empty( $order ) ) {
793
  return;
794
  }
799
  $decimal_point = 2;
800
 
801
  // General Info
802
+ $requestItem = new RequestItem();
803
+ $order_model = new Order();
804
+ $order_billing = new OrderBilling();
805
+
806
  $requestItem->order_id = $order->get_id();
807
  $requestItem->order_number = $order->get_order_number();
808
  $requestItem->date_created = $order->get_date_created() ? $order->get_date_created()->getTimestamp() : 0;
815
  $requestItem->customer_user_agent = $order->get_customer_user_agent();
816
  $requestItem->customer_id = $order->get_user_id();
817
  // Order Billing
818
+ $order_billing->email = $order->get_billing_email();
819
+ $order_billing->opt_action_by = $this->get_opt_action_by( $products_detail );
820
+ $order_billing->opt_in = $this->get_opt_in( $products_detail );
821
+ $order_billing->opt_out = $this->get_opt_out( $products_detail );
822
+
823
+ $order_billing->first_name = $order->get_billing_first_name();
824
+ $order_billing->last_name = $order->get_billing_last_name();
825
+ $order_billing->is_first_time_buyer = count( wc_get_orders( array( 'email' => $order->get_billing_email() ) ) ) <= 1;
826
+ $order_billing->company = $order->get_billing_company();
827
+ $order_billing->address_1 = $order->get_billing_address_1();
828
+ $order_billing->address_2 = $order->get_billing_address_2();
829
+ $order_billing->city = $order->get_billing_city();
830
+ $order_billing->state = $order->get_billing_state();
831
+ $order_billing->postcode = $order->get_billing_postcode();
832
+ $order_billing->country = $order->get_billing_country();
833
+ $order_billing->email = $order->get_billing_email();
834
+ $order_billing->phone = $order->get_billing_phone();
835
+ $order_billing->shipping = array(
 
836
  'first_name' => $order->get_shipping_first_name(),
837
  'last_name' => $order->get_shipping_last_name(),
838
  'company' => $order->get_shipping_company(),
844
  'country' => $order->get_shipping_country(),
845
  'shipping_methods' => $order->get_shipping_method()
846
  );
847
+ $order_billing->payment_details = array(
848
  'method_id' => $order->get_payment_method(),
849
  'method_title' => $order->get_payment_method_title(),
850
  'paid' => !is_null($order->get_date_paid()),
851
  );
852
  // Order Currency and Total Info
853
+ $requestItem->total = wc_format_decimal( $order->get_total(), $decimal_point );
854
+ $requestItem->subtotal = wc_format_decimal( $order->get_subtotal(), $decimal_point );
855
+ $requestItem->total_tax = wc_format_decimal( $order->get_total_tax(), $decimal_point );
856
+ $requestItem->shipping_total = wc_format_decimal( $order->get_shipping_total(), $decimal_point );
857
+ $requestItem->cart_tax = wc_format_decimal( $order->get_cart_tax(), $decimal_point );
858
+ $requestItem->shipping_tax = wc_format_decimal( $order->get_shipping_tax(), $decimal_point );
859
+ $requestItem->discount_total = wc_format_decimal( $order->get_total_discount(), $decimal_point );
860
+ $order_model->currency_symbol = get_woocommerce_currency_symbol();
861
+ $order_model->currency = $order->get_currency();
862
  // Order Products Info
863
+ $order_model->total_line_items_quantity = $order->get_item_count();
864
  // Line Items / Products array for the expected endpoint
865
+ foreach ( $order->get_items() as $itemsKey => $item ) {
866
  $product = $item->get_product();
867
 
868
+ if ( empty( $product ) ) {
869
  continue;
870
  }
871
 
872
  $item_meta = $item->get_formatted_meta_data();
873
 
874
+ foreach ( $item_meta as $key => $values ) {
875
+ $item_meta[ $key ]->label = $values->display_key;
876
+ unset( $item_meta[ $key ]->display_key );
877
+ unset( $item_meta[ $key ]->display_value );
878
  }
879
 
880
  try {
883
  'downloads' => array()
884
  );
885
  $attachment_ids = $product->get_gallery_image_ids();
886
+ foreach ( $attachment_ids as $attachment_id ) {
887
+ $product_data[ 'images' ][] = wp_get_attachment_url( $attachment_id );
888
  }
889
 
890
+ $product_data[ "on_sale" ] = $product->is_on_sale();
891
+ $product_data[ "sale_price" ] = $product->get_sale_price();
892
+ $product_data[ "regular_price" ] = $product->get_regular_price();
893
 
894
+ if ( $product->is_downloadable() ) {
895
  $item_downloads = $item->get_item_downloads();
896
+ foreach ( $item_downloads as $item_download )
897
  {
898
+ $product_data[ "downloads" ][] = array(
899
  'line_item_id' => $item->get_id(),
900
  'product_id' => $item->get_product_id(),
901
+ 'download_url' => $item_download[ "download_url" ],
902
+ 'download_file' => $item_download[ "file" ],
903
+ 'download_name' => $item_download[ "name" ],
904
+ 'download_id' => $item_download[ "id" ],
905
+ 'downloads_remaining' => $item_download[ "downloads_remaining" ],
906
+ 'download_access_expires' => wc_format_datetime( $item_download[ "access_expires" ], 'U' ),
907
  'download_limit' => $product->get_download_limit(),
908
  'download_expiry' => $product->get_download_expiry(),
909
  );
910
  }
911
  }
912
+ } catch ( \Exception $ex ) {
913
+ RaygunManager::get_instance()->exception_handler( $ex );
914
  }
915
 
916
  $src = wc_placeholder_img_src();
917
+ if ( $image_id = $product->get_image_id() ) {
918
+ list( $src ) = wp_get_attachment_image_src( $image_id, 'full' );
919
  }
920
 
921
+ $order_model->line_items[] = array(
922
  'product_id' => $item->get_product_id(),
923
  'item_meta' => $item->get_formatted_meta_data(),
924
+ 'subtotal' => wc_format_decimal($order->get_line_subtotal( $item, false, false), $decimal_point ),
925
+ 'subtotal_tax' => wc_format_decimal( $item->get_subtotal_tax(), $decimal_point ),
926
+ 'total' => wc_format_decimal( $order->get_line_total($item, false, false), $decimal_point ),
927
+ 'total_tax' => wc_format_decimal( $item->get_total_tax(), $decimal_point ),
928
+ 'price' => wc_format_decimal( $order->get_item_total($item, false, false), $decimal_point ),
929
  'quantity' => $item->get_quantity(),
930
  'tax_class' => $item->get_tax_class(),
931
  'name' => $item->get_name(),
932
  'product_image' => $src,
933
  'product_data' => $product_data,
934
+ 'sku' => is_object( $product ) ? $product->get_sku() : null,
935
+ 'meta' => array_values( $item_meta ),
936
+ 'product_url' => get_the_permalink( $item->get_product_id() ),
937
  'variation_id' => $item->get_variation_id()
938
  );
939
  }
940
 
941
+ $order_model->billing = $order_billing;
942
+ $requestItem->order = $order_model;
943
+
944
+ $endpoint = EnvironmentHelper::get_app_gateway_url( 'wordpress' ) . $endpoint;
945
  try
946
  {
947
  wp_remote_post(
953
  'x-api-key' => OptionsHelper::get_instance_api_key(),
954
  'content-type' => 'application/json'
955
  ),
956
+ 'body' => wp_json_encode( $requestItem )
957
  )
958
  );
959
+ } catch ( \Exception $e ) {
960
+ RaygunManager::get_instance()->exception_handler( $e );
961
  }
962
  }
963
  }
src/Managers/EmailManager.php CHANGED
@@ -4,10 +4,15 @@
4
  namespace CreativeMail\Managers;
5
 
6
  use CreativeMail\CreativeMail;
 
 
 
 
 
7
  use CreativeMail\Modules\WooCommerce\Emails\AbandonedCartEmail;
8
  use CreativeMail\Helpers\EnvironmentHelper;
9
  use CreativeMail\Helpers\OptionsHelper;
10
- use stdClass;
11
 
12
  /**
13
  * Class EmailManager
@@ -190,12 +195,12 @@ class EmailManager
190
  /**
191
  * Renders the custom email status column.
192
  *
193
- * @param \WC_Email $email the email
194
  *
195
  * @internal
196
  * @since 1.1.0
197
  */
198
- public function render_email_status_column( \WC_Email $email )
199
  {
200
 
201
  echo '<td class="wc-email-settings-table-status">';
@@ -239,50 +244,50 @@ class EmailManager
239
 
240
  public function ce_email_notification_new_customer_note($array)
241
  {
242
- $data = new stdClass();
243
- $data->order_id = $array['order_id'];
244
- $data->note = $array['customer_note'];
245
- $data->order_url = $this->get_view_order_url($data->order_id, null);
246
 
247
- $this->execute_trigger("customer_note", $data, wc_get_order($data->order_id));
248
  }
249
 
250
- public function ce_email_notification_customer_new_account($customer_id, $new_customer_data, $password_generated)
251
  {
252
- $data = new stdClass();
253
  $data->customer_id = $customer_id;
254
  $data->account_url = $this->get_my_account_url();
255
- $data->customer = $this->get_customer_data($customer_id);
256
 
257
- if ($password_generated && key_exists("user_pass", $new_customer_data)) {
258
  try {
259
- $generated_password = $new_customer_data['user_pass'];
260
- $key = sha1(OptionsHelper::get_instance_api_key() . OptionsHelper::get_instance_uuid());
261
- $salt = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
262
  $salted = '';
263
  $dx = '';
264
- while (strlen($salted) < 48) {
265
- $dx = md5($dx . $key . $salt, true);
266
  $salted .= $dx;
267
  }
268
- $key = substr($salted, 0, 32);
269
- $iv = substr($salted, 32, 16);
270
- $gp = openssl_encrypt($generated_password, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
271
- $data->salt = bin2hex($salt);
272
- $data->generated_password = base64_encode($gp);
273
- } catch (\Exception $ex) {
274
- RaygunManager::get_instance()->exception_handler($ex);
275
  }
276
  }
277
 
278
- $this->execute_trigger("customer_new_account", $data,null, true);
279
  }
280
 
281
- public function ce_email_notification_customer_reset_password($user_login = '', $reset_key = '')
282
  {
283
- if ($user_login && $reset_key ) {
284
- $data = new stdClass();
285
- $user = get_user_by('login', $user_login);
286
  $data->customer_id = $user->ID;
287
  $data->customer = $this->get_customer_data($user->ID);
288
  $data->account_url = $this->get_my_account_url();
@@ -290,106 +295,106 @@ class EmailManager
290
  array(
291
  'key' => $reset_key,
292
  'id' => $data->customer_id
293
- ), wc_get_endpoint_url('lost-password', '', $data->account_url)
294
  );
295
 
296
- $this->execute_trigger("customer_reset_password", $data, null, true);
297
  }
298
  }
299
 
300
  public function ce_email_notification_payment_complete( $order_id )
301
  {
302
- $data = new stdClass();
303
  $data->order_id = $order_id;
304
- $data->order_url = $this->get_view_order_url($order_id, null);
305
 
306
- $this->execute_trigger("payment_received", $data, wc_get_order($order_id));
307
  }
308
 
309
- public function ce_email_notification_failed($order_id, $order)
310
  {
311
- $data = new stdClass();
312
  $data->order_id = $order_id;
313
- $data->order_url = $this->get_view_order_url($order_id, $order);
314
 
315
- $this->execute_trigger("failed_order", $data, $order);
316
  }
317
- public function ce_email_notification_hold($order_id, $order)
318
  {
319
- $data = new stdClass();
320
  $data->order_id = $order_id;
321
- $data->order_url = $this->get_view_order_url($order_id, $order);
322
 
323
- $this->execute_trigger("customer_on_hold_order", $data, $order);
324
  }
325
- public function ce_email_notification_processing($order_id, $order)
326
  {
327
- $data = new stdClass();
328
  $data->order_id = $order_id;
329
- $data->order_url = $this->get_view_order_url($order_id, $order);
330
 
331
- $this->execute_trigger("customer_processing_order", $data, $order);
332
  }
333
- public function ce_email_notification_completed($order_id, $order)
334
  {
335
- $data = new stdClass();
336
  $data->order_id = $order_id;
337
- $data->order_url = $this->get_view_order_url($order_id, $order);
338
 
339
- $this->execute_trigger("customer_completed_order", $data, $order);
340
  }
341
 
342
- public function ce_email_notification_refunded($order_id, $order)
343
  {
344
- $data = new stdClass();
345
  $data->order_id = $order_id;
346
- $data->order_url = $this->get_view_order_url($order_id, $order);
347
 
348
- $this->execute_trigger("customer_refunded_order", $data, $order);
349
  }
350
- public function ce_email_notification_cancelled($order_id, $order)
351
  {
352
- $data = new stdClass();
353
  $data->order_id = $order_id;
354
- $data->order_url = $this->get_view_order_url($order_id, $order);
355
 
356
- $this->execute_trigger("cancelled_order", $data, $order);
357
  }
358
 
359
- public function ce_email_notification_new_order($order_id, $order)
360
  {
361
- $data = new stdClass();
362
  $data->order_id = $order_id;
363
- $data->order_url = $this->get_view_order_url($order_id, $order);
364
 
365
- $this->execute_trigger("new_order", $data, $order);
366
  }
367
 
368
- public function ce_email_notification_invoice($order, $type)
369
  {
370
- if ($type === 'new_order' ) {
371
- $this->ce_email_notification_new_order($order->id, $order);
372
  return;
373
  }
374
 
375
- $data = new stdClass();
376
  $data->order_id = $order->get_id();
377
- $data->order_url = $this->get_view_order_url($order->get_id(), $order);
378
 
379
- $this->execute_trigger("customer_invoice", $data, $order);
380
  }
381
 
382
- public function execute_trigger($type, $data, $order = null, $with_data = false)
383
  {
384
  // if not managed do not trigger
385
- if (!$this->is_email_managed($type)) {
386
  return;
387
  }
388
 
389
- $requestItem = new stdClass();
390
  $requestItem->type = $type;
391
 
392
- if(!is_null($order)) {
393
  try {
394
  $dp = 2; // decimal point
395
  $order_data = array(
@@ -400,15 +405,15 @@ class EmailManager
400
  'date_completed' => $order->get_date_completed() ? $order->get_date_completed()->getTimestamp() : 0,
401
  'status' => $order->get_status(),
402
  'currency' => $order->get_currency(),
403
- 'currency_symbol' => get_woocommerce_currency_symbol($order->get_currency()),
404
- 'total' => wc_format_decimal($order->get_total(), $dp),
405
- 'subtotal' => wc_format_decimal($order->get_subtotal(), $dp),
406
  'total_line_items_quantity' => $order->get_item_count(),
407
- 'total_tax' => wc_format_decimal($order->get_total_tax(), $dp),
408
- 'shipping_total' => wc_format_decimal($order->get_shipping_total(), $dp),
409
- 'cart_tax' => wc_format_decimal($order->get_cart_tax(), $dp),
410
- 'shipping_tax' => wc_format_decimal($order->get_shipping_tax(), $dp),
411
- 'discount_total' => wc_format_decimal($order->get_total_discount(), $dp),
412
  'shipping_methods' => $order->get_shipping_method(),
413
  'payment_details' => array(
414
  'method_id' => $order->get_payment_method(),
@@ -452,14 +457,14 @@ class EmailManager
452
  );
453
 
454
  // add line items
455
- foreach ($order->get_items() as $item_id => $item) {
456
  $product = $item->get_product();
457
  $item_meta = $item->get_formatted_meta_data();
458
 
459
- foreach ($item_meta as $key => $values) {
460
- $item_meta[$key]->label = $values->display_key;
461
- unset($item_meta[$key]->display_key);
462
- unset($item_meta[$key]->display_value);
463
  }
464
 
465
  try {
@@ -469,118 +474,118 @@ class EmailManager
469
  'downloads' => array()
470
  );
471
  $attachment_ids = $product->get_gallery_image_ids();
472
- foreach ($attachment_ids as $attachment_id) {
473
- $product_data['images'][] = wp_get_attachment_url($attachment_id);
474
  }
475
 
476
- $product_data["on_sale"] = $product->is_on_sale();
477
- $product_data["sale_price"] = $product->get_sale_price();
478
- $product_data["regular_price"] = $product->get_regular_price();
479
 
480
- if ($product->is_downloadable()) {
481
  $item_downloads = $item->get_item_downloads();
482
- foreach ($item_downloads as $item_download)
483
  {
484
- $product_data["downloads"][] = array(
485
  'line_item_id' => $item->get_id(),
486
  'product_id' => $item->get_product_id(),
487
- 'download_url' => $item_download["download_url"],
488
- 'download_file' => $item_download["file"],
489
- 'download_name' => $item_download["name"],
490
- 'download_id' => $item_download["id"],
491
- 'downloads_remaining' => $item_download["downloads_remaining"],
492
- 'download_access_expires' => wc_format_datetime($item_download["access_expires"], 'U'),
493
  'download_limit' => $product->get_download_limit(),
494
  'download_expiry' => $product->get_download_expiry(),
495
  );
496
  }
497
  }
498
 
499
- } catch (\Exception $ex)
500
  {
501
- RaygunManager::get_instance()->exception_handler($ex);
502
  }
503
 
504
  $src = wc_placeholder_img_src();
505
- if ($image_id = $product->get_image_id() ) {
506
- list( $src ) = wp_get_attachment_image_src($image_id, 'full');
507
  }
508
 
509
- $order_data['line_items'][] = array(
510
  'id' => $item_id,
511
- 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $dp),
512
- 'subtotal_tax' => wc_format_decimal($item->get_subtotal_tax(), $dp),
513
- 'total' => wc_format_decimal($order->get_line_total($item, false, false), $dp),
514
- 'total_tax' => wc_format_decimal($item->get_total_tax(), $dp),
515
- 'price' => wc_format_decimal($order->get_item_total($item, false, false), $dp),
516
  'quantity' => $item->get_quantity(),
517
  'tax_class' => $item->get_tax_class(),
518
  'name' => $item->get_name(),
519
  'product_id' => $item->get_product_id(),
520
  'product_image' => $src,
521
  'product_data' => $product_data,
522
- 'sku' => is_object($product) ? $product->get_sku() : null,
523
- 'meta' => array_values($item_meta),
524
- 'product_url' => get_the_permalink($item->get_product_id()),
525
  'variation_id' => $item->get_variation_id()
526
  );
527
  }
528
 
529
  // add shipping
530
- foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
531
- $order_data['shipping_lines'][] = array(
532
  'id' => $shipping_item_id,
533
  'method_id' => $shipping_item->get_method_id(),
534
  'method_title' => $shipping_item->get_name(),
535
- 'total' => wc_format_decimal($shipping_item->get_total(), $dp),
536
  );
537
  }
538
 
539
  // add taxes
540
- foreach ($order->get_tax_totals() as $tax_code => $tax) {
541
- $order_data['tax_lines'][] = array(
542
  'id' => $tax->id,
543
  'rate_id' => $tax->rate_id,
544
  'code' => $tax_code,
545
  'title' => $tax->label,
546
  'total' => wc_format_decimal($tax->amount, $dp),
547
- 'compound' => (bool)$tax->is_compound,
548
  );
549
  }
550
 
551
  // add fees
552
- foreach ($order->get_fees() as $fee_item_id => $fee_item) {
553
- $order_data['fee_lines'][] = array(
554
  'id' => $fee_item_id,
555
  'title' => $fee_item->get_name(),
556
  'tax_class' => $fee_item->get_tax_class(),
557
- 'total' => wc_format_decimal($order->get_line_total($fee_item), $dp),
558
- 'total_tax' => wc_format_decimal($order->get_line_tax($fee_item), $dp),
559
  );
560
  }
561
 
562
  // add coupons
563
- foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) {
564
- $order_data['coupon_lines'][] = array(
565
  'id' => $coupon_item_id,
566
  'code' => $coupon_item->get_code(),
567
- 'amount' => wc_format_decimal($coupon_item->get_discount(), $dp),
568
  );
569
  }
570
  $data->order = $order_data;
571
  $with_data = true;
572
  }
573
- catch (\Exception $ex) {
574
- RaygunManager::get_instance()->exception_handler($ex);
575
  $with_data = false;
576
  }
577
  }
578
 
579
- $requestItem->data = wp_json_encode($data);
580
- $endpoint = EnvironmentHelper::get_app_gateway_url('wordpress').'/v1.0/wc/trigger';
581
- if ($with_data)
582
  {
583
- $endpoint = EnvironmentHelper::get_app_gateway_url('wordpress') . '/v1.0/wc/trigger-with-data';
584
  }
585
 
586
  wp_remote_post(
@@ -592,7 +597,7 @@ class EmailManager
592
  'x-api-key' => OptionsHelper::get_instance_api_key(),
593
  'content-type' => 'application/json'
594
  ),
595
- 'body' => wp_json_encode($requestItem)
596
  )
597
  );
598
  }
@@ -606,20 +611,20 @@ class EmailManager
606
  */
607
  public function manage_emails()
608
  {
609
- if (empty($this->managed_email_notifications) || ! is_array($this->managed_email_notifications) ) {
610
  return;
611
  }
612
 
613
  // disable managed emails
614
  foreach ( $this->managed_email_notifications as $notification )
615
  {
616
- if ($this->is_email_managed($notification->name) ) {
617
- add_filter("woocommerce_email_enabled_". $notification->name ."", '__return_false');
618
  }
619
  }
620
 
621
- add_filter('woocommerce_email_title', array( $this, 'override_managed_email_title' ), 10, 2);
622
- add_filter('woocommerce_email_description', array( $this, 'override_managed_email_description' ), 10, 2);
623
  }
624
 
625
 
@@ -627,7 +632,7 @@ class EmailManager
627
  * Overrides email titles for managed emails.
628
  *
629
  * @param string $title the email title
630
- * @param \WC_Email $email the email object
631
  *
632
  * @internal
633
  * @since 1.1.0
@@ -637,9 +642,9 @@ class EmailManager
637
  public function override_managed_email_title( $title, $email )
638
  {
639
 
640
- if (isset($email->id) && $this->is_email_managed($email->id) ) {
641
 
642
- $title .= __(' (Managed by Creative Mail)', 'ce4wp');
643
  }
644
 
645
  return $title;
@@ -650,7 +655,7 @@ class EmailManager
650
  * Overrides email description for managed emails.
651
  *
652
  * @param string $description description text
653
- * @param \WC_Email $email the email object
654
  *
655
  * @internal
656
  * @since 1.1.0
@@ -659,9 +664,9 @@ class EmailManager
659
  public function override_managed_email_description( $description, $email )
660
  {
661
 
662
- if (isset($email->id) && $this->is_email_managed($email->id) ) {
663
 
664
- $description .= __(' This email is being managed and sent by Creative Mail.', 'ce4wp');
665
  }
666
 
667
  return $description;
@@ -670,25 +675,25 @@ class EmailManager
670
  /**
671
  * Redirects the settings page of a managed email to the CreativeMail transactional notification for that email.
672
  *
673
- * @param \WC_Email $email the email object
674
  *
675
  * @since 1.1.0
676
  */
677
  public function redirect_managed_email_settings_to_creative_mail( $email )
678
  {
679
- if ($this->is_email_managed($email->id)) {
680
- $url = CreativeMail::get_instance()->get_admin_manager()->request_single_sign_on_url_internal("66eabdb1-5d55-4bc0-a435-0415c5ada60a", array(
681
  "woocommerceTemplateSlug" => $email->id
682
- ));
683
- wp_redirect($url);
684
  exit;
685
  }
686
 
687
- if ($email->id === 'cart_abandoned_ce4wp') {
688
- $url = CreativeMail::get_instance()->get_admin_manager()->request_single_sign_on_url_internal("1fabdbe2-95ed-4e1e-a2f3-ba0278f5096f", array (
689
  "source" => "woocommerce_emails"
690
  ));
691
- wp_redirect($url);
692
  exit;
693
  }
694
  }
@@ -703,7 +708,7 @@ class EmailManager
703
  */
704
  public function is_email_managed( $email_id )
705
  {
706
- return (bool) $this->get_managed_notification_param($email_id, 'active');
707
  }
708
 
709
  /**
@@ -718,8 +723,8 @@ class EmailManager
718
  */
719
  public function get_managed_notification_param( $email_id, $param )
720
  {
721
- foreach($this->managed_email_notifications as $managed_email_notification) {
722
- if ($email_id == $managed_email_notification->name && property_exists($managed_email_notification, $param)) {
723
  return $managed_email_notification->$param;
724
  }
725
  }
@@ -738,8 +743,8 @@ class EmailManager
738
  public function get_managed_notification( $items, $email_id )
739
  {
740
 
741
- foreach($items as $managed_email_notification) {
742
- if ($email_id == $managed_email_notification->name) {
743
  return $managed_email_notification;
744
  }
745
  }
@@ -757,8 +762,7 @@ class EmailManager
757
  */
758
  public function get_transactional_notification_id( $email_id )
759
  {
760
-
761
- return $this->get_managed_notification_param($email_id, 'transactional_notification_id');
762
  }
763
 
764
  /**
@@ -772,7 +776,7 @@ class EmailManager
772
  public function get_managed_notification_state( $email_id )
773
  {
774
 
775
- return $this->get_managed_notification_param($email_id, 'state');
776
  }
777
 
778
  public function get_valid_email_notification_names()
@@ -780,18 +784,18 @@ class EmailManager
780
  return $this->valid_email_notification_names;
781
  }
782
 
783
- private function get_view_order_url($order_id, $order)
784
  {
785
  try {
786
- if (!isset($order)) {
787
- $order = wc_get_order($order_id);
788
  }
789
 
790
- if (isset($order) && method_exists($order, 'get_view_order_url') ) {
791
  return $order->get_view_order_url();
792
  }
793
  } catch ( \Exception $exception ) {
794
- RaygunManager::get_instance()->exception_handler($exception);
795
  }
796
 
797
  return null;
@@ -800,31 +804,31 @@ class EmailManager
800
  private function get_my_account_url()
801
  {
802
  try {
803
- return wc_get_page_permalink('myaccount');
804
  } catch ( \Exception $exception ) {
805
- RaygunManager::get_instance()->exception_handler($exception);
806
  }
807
 
808
  return null;
809
  }
810
 
811
- private function get_customer_data($customer_id)
812
  {
813
  try {
814
  $customer = new \WC_Customer( $customer_id );
815
 
816
  $data = $customer->get_data();
817
 
818
- if ($data['date_created'] != null) {
819
- $data['date_created'] = $customer->get_date_created()->getTimestamp();
820
  }
821
- if ($data['date_modified'] != null) {
822
- $data['date_modified'] = $customer->get_date_modified()->getTimestamp();
823
  }
824
 
825
  return $data;
826
  } catch ( \Exception $exception ) {
827
- RaygunManager::get_instance()->exception_handler($exception);
828
  }
829
  return null;
830
  }
4
  namespace CreativeMail\Managers;
5
 
6
  use CreativeMail\CreativeMail;
7
+ use CreativeMail\Models\CustomerNewAccount;
8
+ use CreativeMail\Models\CustomerNote;
9
+ use CreativeMail\Models\CustomerResetPassword;
10
+ use CreativeMail\Models\EmailNotification;
11
+ use CreativeMail\Models\TriggerExecution;
12
  use CreativeMail\Modules\WooCommerce\Emails\AbandonedCartEmail;
13
  use CreativeMail\Helpers\EnvironmentHelper;
14
  use CreativeMail\Helpers\OptionsHelper;
15
+ use WC_Email;
16
 
17
  /**
18
  * Class EmailManager
195
  /**
196
  * Renders the custom email status column.
197
  *
198
+ * @param WC_Email $email the email
199
  *
200
  * @internal
201
  * @since 1.1.0
202
  */
203
+ public function render_email_status_column( WC_Email $email )
204
  {
205
 
206
  echo '<td class="wc-email-settings-table-status">';
244
 
245
  public function ce_email_notification_new_customer_note($array)
246
  {
247
+ $data = new CustomerNote();
248
+ $data->order_id = $array[ 'order_id' ];
249
+ $data->note = $array[ 'customer_note' ];
250
+ $data->order_url = $this->get_view_order_url( $data->order_id, null );
251
 
252
+ $this->execute_trigger( "customer_note", $data, wc_get_order( $data->order_id ) );
253
  }
254
 
255
+ public function ce_email_notification_customer_new_account( $customer_id, $new_customer_data, $password_generated )
256
  {
257
+ $data = new CustomerNewAccount();
258
  $data->customer_id = $customer_id;
259
  $data->account_url = $this->get_my_account_url();
260
+ $data->customer = $this->get_customer_data( $customer_id );
261
 
262
+ if ( $password_generated && key_exists( "user_pass", $new_customer_data ) ) {
263
  try {
264
+ $generated_password = $new_customer_data[ 'user_pass' ];
265
+ $key = sha1( OptionsHelper::get_instance_api_key() . OptionsHelper::get_instance_uuid() );
266
+ $salt = openssl_random_pseudo_bytes( openssl_cipher_iv_length( 'aes-256-cbc' ) );
267
  $salted = '';
268
  $dx = '';
269
+ while ( strlen( $salted ) < 48 ) {
270
+ $dx = md5( $dx . $key . $salt, true );
271
  $salted .= $dx;
272
  }
273
+ $key = substr( $salted, 0, 32 );
274
+ $iv = substr( $salted, 32, 16 );
275
+ $gp = openssl_encrypt( $generated_password, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv );
276
+ $data->salt = bin2hex( $salt );
277
+ $data->generated_password = base64_encode( $gp );
278
+ } catch ( \Exception $ex ) {
279
+ RaygunManager::get_instance()->exception_handler( $ex );
280
  }
281
  }
282
 
283
+ $this->execute_trigger( "customer_new_account", $data,null, true ) ;
284
  }
285
 
286
+ public function ce_email_notification_customer_reset_password( $user_login = '', $reset_key = '' )
287
  {
288
+ if ( $user_login && $reset_key ) {
289
+ $data = new CustomerResetPassword();
290
+ $user = get_user_by( 'login', $user_login );
291
  $data->customer_id = $user->ID;
292
  $data->customer = $this->get_customer_data($user->ID);
293
  $data->account_url = $this->get_my_account_url();
295
  array(
296
  'key' => $reset_key,
297
  'id' => $data->customer_id
298
+ ), wc_get_endpoint_url( 'lost-password', '', $data->account_url )
299
  );
300
 
301
+ $this->execute_trigger( "customer_reset_password", $data, null, true );
302
  }
303
  }
304
 
305
  public function ce_email_notification_payment_complete( $order_id )
306
  {
307
+ $data = new EmailNotification();
308
  $data->order_id = $order_id;
309
+ $data->order_url = $this->get_view_order_url( $order_id, null );
310
 
311
+ $this->execute_trigger( "payment_received", $data, wc_get_order( $order_id ) );
312
  }
313
 
314
+ public function ce_email_notification_failed( $order_id, $order )
315
  {
316
+ $data = new EmailNotification();
317
  $data->order_id = $order_id;
318
+ $data->order_url = $this->get_view_order_url( $order_id, $order );
319
 
320
+ $this->execute_trigger( "failed_order", $data, $order );
321
  }
322
+ public function ce_email_notification_hold( $order_id, $order )
323
  {
324
+ $data = new EmailNotification();
325
  $data->order_id = $order_id;
326
+ $data->order_url = $this->get_view_order_url( $order_id, $order );
327
 
328
+ $this->execute_trigger( "customer_on_hold_order", $data, $order );
329
  }
330
+ public function ce_email_notification_processing( $order_id, $order )
331
  {
332
+ $data = new EmailNotification();
333
  $data->order_id = $order_id;
334
+ $data->order_url = $this->get_view_order_url( $order_id, $order );
335
 
336
+ $this->execute_trigger( "customer_processing_order", $data, $order );
337
  }
338
+ public function ce_email_notification_completed( $order_id, $order )
339
  {
340
+ $data = new EmailNotification();
341
  $data->order_id = $order_id;
342
+ $data->order_url = $this->get_view_order_url( $order_id, $order );
343
 
344
+ $this->execute_trigger( "customer_completed_order", $data, $order );
345
  }
346
 
347
+ public function ce_email_notification_refunded( $order_id, $order )
348
  {
349
+ $data = new EmailNotification();
350
  $data->order_id = $order_id;
351
+ $data->order_url = $this->get_view_order_url( $order_id, $order );
352
 
353
+ $this->execute_trigger( "customer_refunded_order", $data, $order );
354
  }
355
+ public function ce_email_notification_cancelled( $order_id, $order )
356
  {
357
+ $data = new EmailNotification();
358
  $data->order_id = $order_id;
359
+ $data->order_url = $this->get_view_order_url( $order_id, $order );
360
 
361
+ $this->execute_trigger( "cancelled_order", $data, $order );
362
  }
363
 
364
+ public function ce_email_notification_new_order( $order_id, $order )
365
  {
366
+ $data = new EmailNotification();
367
  $data->order_id = $order_id;
368
+ $data->order_url = $this->get_view_order_url( $order_id, $order );
369
 
370
+ $this->execute_trigger( "new_order", $data, $order );
371
  }
372
 
373
+ public function ce_email_notification_invoice( $order, $type )
374
  {
375
+ if ( $type === 'new_order' ) {
376
+ $this->ce_email_notification_new_order( $order->id, $order );
377
  return;
378
  }
379
 
380
+ $data = new EmailNotification();
381
  $data->order_id = $order->get_id();
382
+ $data->order_url = $this->get_view_order_url( $order->get_id(), $order );
383
 
384
+ $this->execute_trigger( "customer_invoice", $data, $order );
385
  }
386
 
387
+ public function execute_trigger( $type, $data, $order = null, $with_data = false )
388
  {
389
  // if not managed do not trigger
390
+ if ( !$this->is_email_managed( $type ) ) {
391
  return;
392
  }
393
 
394
+ $requestItem = new TriggerExecution();
395
  $requestItem->type = $type;
396
 
397
+ if( !is_null( $order ) ) {
398
  try {
399
  $dp = 2; // decimal point
400
  $order_data = array(
405
  'date_completed' => $order->get_date_completed() ? $order->get_date_completed()->getTimestamp() : 0,
406
  'status' => $order->get_status(),
407
  'currency' => $order->get_currency(),
408
+ 'currency_symbol' => get_woocommerce_currency_symbol( $order->get_currency()),
409
+ 'total' => wc_format_decimal( $order->get_total(), $dp ),
410
+ 'subtotal' => wc_format_decimal( $order->get_subtotal(), $dp ),
411
  'total_line_items_quantity' => $order->get_item_count(),
412
+ 'total_tax' => wc_format_decimal( $order->get_total_tax(), $dp ),
413
+ 'shipping_total' => wc_format_decimal( $order->get_shipping_total(), $dp ),
414
+ 'cart_tax' => wc_format_decimal( $order->get_cart_tax(), ),
415
+ 'shipping_tax' => wc_format_decimal( $order->get_shipping_tax(), $dp ),
416
+ 'discount_total' => wc_format_decimal( $order->get_total_discount(), $dp ),
417
  'shipping_methods' => $order->get_shipping_method(),
418
  'payment_details' => array(
419
  'method_id' => $order->get_payment_method(),
457
  );
458
 
459
  // add line items
460
+ foreach ( $order->get_items() as $item_id => $item ) {
461
  $product = $item->get_product();
462
  $item_meta = $item->get_formatted_meta_data();
463
 
464
+ foreach ( $item_meta as $key => $values ) {
465
+ $item_meta[ $key ]->label = $values->display_key;
466
+ unset( $item_meta[ $key ]->display_key );
467
+ unset( $item_meta[ $key ]->display_value );
468
  }
469
 
470
  try {
474
  'downloads' => array()
475
  );
476
  $attachment_ids = $product->get_gallery_image_ids();
477
+ foreach ( $attachment_ids as $attachment_id ) {
478
+ $product_data[ 'images' ][] = wp_get_attachment_url( $attachment_id );
479
  }
480
 
481
+ $product_data[ "on_sale" ] = $product->is_on_sale();
482
+ $product_data[ "sale_price" ] = $product->get_sale_price();
483
+ $product_data[ "regular_price" ] = $product->get_regular_price();
484
 
485
+ if ( $product->is_downloadable() ) {
486
  $item_downloads = $item->get_item_downloads();
487
+ foreach ( $item_downloads as $item_download )
488
  {
489
+ $product_data[ "downloads" ][] = array(
490
  'line_item_id' => $item->get_id(),
491
  'product_id' => $item->get_product_id(),
492
+ 'download_url' => $item_download[ "download_url" ],
493
+ 'download_file' => $item_download[ "file" ],
494
+ 'download_name' => $item_download[ "name" ],
495
+ 'download_id' => $item_download[ "id" ],
496
+ 'downloads_remaining' => $item_download[ "downloads_remaining" ],
497
+ 'download_access_expires' => wc_format_datetime($item_download[ "access_expires" ], 'U'),
498
  'download_limit' => $product->get_download_limit(),
499
  'download_expiry' => $product->get_download_expiry(),
500
  );
501
  }
502
  }
503
 
504
+ } catch ( \Exception $ex )
505
  {
506
+ RaygunManager::get_instance()->exception_handler( $ex );
507
  }
508
 
509
  $src = wc_placeholder_img_src();
510
+ if ( $image_id = $product->get_image_id() ) {
511
+ list( $src ) = wp_get_attachment_image_src( $image_id, 'full' );
512
  }
513
 
514
+ $order_data[ 'line_items' ][] = array(
515
  'id' => $item_id,
516
+ 'subtotal' => wc_format_decimal( $order->get_line_subtotal( $item, false, false ), $dp ),
517
+ 'subtotal_tax' => wc_format_decimal( $item->get_subtotal_tax(), $dp ),
518
+ 'total' => wc_format_decimal( $order->get_line_total( $item, false, false ), $dp ),
519
+ 'total_tax' => wc_format_decimal( $item->get_total_tax(), $dp ),
520
+ 'price' => wc_format_decimal( $order->get_item_total( $item, false, false ), $dp ),
521
  'quantity' => $item->get_quantity(),
522
  'tax_class' => $item->get_tax_class(),
523
  'name' => $item->get_name(),
524
  'product_id' => $item->get_product_id(),
525
  'product_image' => $src,
526
  'product_data' => $product_data,
527
+ 'sku' => is_object( $product ) ? $product->get_sku() : null,
528
+ 'meta' => array_values( $item_meta ),
529
+ 'product_url' => get_the_permalink( $item->get_product_id() ),
530
  'variation_id' => $item->get_variation_id()
531
  );
532
  }
533
 
534
  // add shipping
535
+ foreach ( $order->get_shipping_methods() as $shipping_item_id => $shipping_item ) {
536
+ $order_data[ 'shipping_lines' ][] = array(
537
  'id' => $shipping_item_id,
538
  'method_id' => $shipping_item->get_method_id(),
539
  'method_title' => $shipping_item->get_name(),
540
+ 'total' => wc_format_decimal( $shipping_item->get_total(), $dp ),
541
  );
542
  }
543
 
544
  // add taxes
545
+ foreach ( $order->get_tax_totals() as $tax_code => $tax ) {
546
+ $order_data[ 'tax_lines' ][] = array(
547
  'id' => $tax->id,
548
  'rate_id' => $tax->rate_id,
549
  'code' => $tax_code,
550
  'title' => $tax->label,
551
  'total' => wc_format_decimal($tax->amount, $dp),
552
+ 'compound' => ( bool )$tax->is_compound,
553
  );
554
  }
555
 
556
  // add fees
557
+ foreach ( $order->get_fees() as $fee_item_id => $fee_item ) {
558
+ $order_data[ 'fee_lines' ][] = array(
559
  'id' => $fee_item_id,
560
  'title' => $fee_item->get_name(),
561
  'tax_class' => $fee_item->get_tax_class(),
562
+ 'total' => wc_format_decimal( $order->get_line_total( $fee_item ), $dp ),
563
+ 'total_tax' => wc_format_decimal( $order->get_line_tax( $fee_item ), $dp ),
564
  );
565
  }
566
 
567
  // add coupons
568
+ foreach ( $order->get_items( 'coupon' ) as $coupon_item_id => $coupon_item ) {
569
+ $order_data[ 'coupon_lines' ][] = array(
570
  'id' => $coupon_item_id,
571
  'code' => $coupon_item->get_code(),
572
+ 'amount' => wc_format_decimal( $coupon_item->get_discount(), $dp ),
573
  );
574
  }
575
  $data->order = $order_data;
576
  $with_data = true;
577
  }
578
+ catch ( \Exception $ex ) {
579
+ RaygunManager::get_instance()->exception_handler( $ex );
580
  $with_data = false;
581
  }
582
  }
583
 
584
+ $requestItem->data = wp_json_encode( $data );
585
+ $endpoint = EnvironmentHelper::get_app_gateway_url( 'wordpress' ).'/v1.0/wc/trigger';
586
+ if ( $with_data )
587
  {
588
+ $endpoint = EnvironmentHelper::get_app_gateway_url( 'wordpress' ) . '/v1.0/wc/trigger-with-data';
589
  }
590
 
591
  wp_remote_post(
597
  'x-api-key' => OptionsHelper::get_instance_api_key(),
598
  'content-type' => 'application/json'
599
  ),
600
+ 'body' => wp_json_encode( $requestItem )
601
  )
602
  );
603
  }
611
  */
612
  public function manage_emails()
613
  {
614
+ if ( empty( $this->managed_email_notifications ) || ! is_array( $this->managed_email_notifications) ) {
615
  return;
616
  }
617
 
618
  // disable managed emails
619
  foreach ( $this->managed_email_notifications as $notification )
620
  {
621
+ if ( $this->is_email_managed( $notification->name ) ) {
622
+ add_filter( "woocommerce_email_enabled_". $notification->name ."", '__return_false');
623
  }
624
  }
625
 
626
+ add_filter( 'woocommerce_email_title', array( $this, 'override_managed_email_title' ), 10, 2 );
627
+ add_filter( 'woocommerce_email_description', array( $this, 'override_managed_email_description' ), 10, 2 );
628
  }
629
 
630
 
632
  * Overrides email titles for managed emails.
633
  *
634
  * @param string $title the email title
635
+ * @param WC_Email $email the email object
636
  *
637
  * @internal
638
  * @since 1.1.0
642
  public function override_managed_email_title( $title, $email )
643
  {
644
 
645
+ if ( isset( $email->id ) && $this->is_email_managed( $email->id ) ) {
646
 
647
+ $title .= __( ' (Managed by Creative Mail)', 'ce4wp' );
648
  }
649
 
650
  return $title;
655
  * Overrides email description for managed emails.
656
  *
657
  * @param string $description description text
658
+ * @param WC_Email $email the email object
659
  *
660
  * @internal
661
  * @since 1.1.0
664
  public function override_managed_email_description( $description, $email )
665
  {
666
 
667
+ if ( isset( $email->id ) && $this->is_email_managed( $email->id ) ) {
668
 
669
+ $description .= __( ' This email is being managed and sent by Creative Mail.', 'ce4wp' );
670
  }
671
 
672
  return $description;
675
  /**
676
  * Redirects the settings page of a managed email to the CreativeMail transactional notification for that email.
677
  *
678
+ * @param WC_Email $email the email object
679
  *
680
  * @since 1.1.0
681
  */
682
  public function redirect_managed_email_settings_to_creative_mail( $email )
683
  {
684
+ if ( $this->is_email_managed( $email->id ) ) {
685
+ $url = CreativeMail::get_instance()->get_admin_manager()->request_single_sign_on_url_internal( "66eabdb1-5d55-4bc0-a435-0415c5ada60a", array(
686
  "woocommerceTemplateSlug" => $email->id
687
+ ) );
688
+ wp_redirect( $url );
689
  exit;
690
  }
691
 
692
+ if ( $email->id === 'cart_abandoned_ce4wp' ) {
693
+ $url = CreativeMail::get_instance()->get_admin_manager()->request_single_sign_on_url_internal( "1fabdbe2-95ed-4e1e-a2f3-ba0278f5096f", array (
694
  "source" => "woocommerce_emails"
695
  ));
696
+ wp_redirect( $url );
697
  exit;
698
  }
699
  }
708
  */
709
  public function is_email_managed( $email_id )
710
  {
711
+ return ( bool ) $this->get_managed_notification_param( $email_id, 'active' );
712
  }
713
 
714
  /**
723
  */
724
  public function get_managed_notification_param( $email_id, $param )
725
  {
726
+ foreach( $this->managed_email_notifications as $managed_email_notification ) {
727
+ if ( $email_id == $managed_email_notification->name && property_exists( $managed_email_notification, $param ) ) {
728
  return $managed_email_notification->$param;
729
  }
730
  }
743
  public function get_managed_notification( $items, $email_id )
744
  {
745
 
746
+ foreach( $items as $managed_email_notification ) {
747
+ if ( $email_id == $managed_email_notification->name ) {
748
  return $managed_email_notification;
749
  }
750
  }
762
  */
763
  public function get_transactional_notification_id( $email_id )
764
  {
765
+ return $this->get_managed_notification_param( $email_id, 'transactional_notification_id' );
 
766
  }
767
 
768
  /**
776
  public function get_managed_notification_state( $email_id )
777
  {
778
 
779
+ return $this->get_managed_notification_param( $email_id, 'state' );
780
  }
781
 
782
  public function get_valid_email_notification_names()
784
  return $this->valid_email_notification_names;
785
  }
786
 
787
+ private function get_view_order_url( $order_id, $order )
788
  {
789
  try {
790
+ if (!isset( $order )) {
791
+ $order = wc_get_order( $order_id );
792
  }
793
 
794
+ if (isset( $order ) && method_exists( $order, 'get_view_order_url' ) ) {
795
  return $order->get_view_order_url();
796
  }
797
  } catch ( \Exception $exception ) {
798
+ RaygunManager::get_instance()->exception_handler( $exception );
799
  }
800
 
801
  return null;
804
  private function get_my_account_url()
805
  {
806
  try {
807
+ return wc_get_page_permalink( 'myaccount' );
808
  } catch ( \Exception $exception ) {
809
+ RaygunManager::get_instance()->exception_handler( $exception );
810
  }
811
 
812
  return null;
813
  }
814
 
815
+ private function get_customer_data( $customer_id )
816
  {
817
  try {
818
  $customer = new \WC_Customer( $customer_id );
819
 
820
  $data = $customer->get_data();
821
 
822
+ if ($data[ 'date_created' ] != null) {
823
+ $data[ 'date_created' ] = $customer->get_date_created()->getTimestamp();
824
  }
825
+ if ($data[ 'date_modified' ] != null) {
826
+ $data[ 'date_modified' ] = $customer->get_date_modified()->getTimestamp();
827
  }
828
 
829
  return $data;
830
  } catch ( \Exception $exception ) {
831
+ RaygunManager::get_instance()->exception_handler( $exception );
832
  }
833
  return null;
834
  }
src/Models/ApiSchema.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ class ApiSchema
6
+ {
7
+ /**
8
+ * Key used to identify the consumer
9
+ *
10
+ * @var string
11
+ */
12
+ public $consumer_key;
13
+ /**
14
+ * Secret used for the consumer
15
+ *
16
+ * @var string
17
+ */
18
+ public $consumer_secret;
19
+ /**
20
+ * ID of the key
21
+ *
22
+ * @var int
23
+ */
24
+ public $key_id;
25
+ /**
26
+ * ID of the user
27
+ *
28
+ * @var int
29
+ */
30
+ public $user_id;
31
+ }
src/Models/Campaign.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ class Campaign
6
+ {
7
+ /**
8
+ * ID of the campaign
9
+ *
10
+ * @var string
11
+ */
12
+ public $id;
13
+ /**
14
+ * Whether the campaign is active or not
15
+ *
16
+ * @var bool
17
+ */
18
+ public $is_draft;
19
+ /**
20
+ * Name of the campaign
21
+ *
22
+ * @var string
23
+ */
24
+ public $name;
25
+ /**
26
+ * Amount of money the campaign is set to raise
27
+ *
28
+ * @var float
29
+ */
30
+ public $open_rate;
31
+ /**
32
+ * The campaign's status
33
+ *
34
+ * @var string
35
+ */
36
+ public $status;
37
+ }
src/Models/CartData.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ class CartData
6
+ {
7
+ /**
8
+ * Coupons array
9
+ *
10
+ * @var array
11
+ */
12
+ public $coupons;
13
+ /**
14
+ * Coupons currency
15
+ *
16
+ * @var string
17
+ */
18
+ public $currency;
19
+ /**
20
+ * Coupons currency symbol
21
+ *
22
+ * @var string
23
+ */
24
+ public $currency_symbol;
25
+ /**
26
+ * Cart items
27
+ *
28
+ * @var array
29
+ */
30
+ public $products;
31
+ /**
32
+ * User data
33
+ *
34
+ * @var User
35
+ */
36
+ public $user;
37
+ }
src/Models/Checkout.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ class Checkout
6
+ {
7
+ /**
8
+ * Order currency
9
+ *
10
+ * @var string
11
+ */
12
+ public $order_currency;
13
+ /**
14
+ * Order Identifier
15
+ *
16
+ * @var int
17
+ */
18
+ public $order_id;
19
+ /**
20
+ * Order total
21
+ *
22
+ * @var float
23
+ */
24
+ public $order_total;
25
+ /**
26
+ * Recovery time
27
+ *
28
+ * @var string
29
+ */
30
+ public $recovery_date;
31
+ /**
32
+ * Universal Identifier
33
+ *
34
+ * @var string
35
+ */
36
+ public $uuid;
37
+ }
src/Models/CheckoutSave.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ class CheckoutSave
6
+ {
7
+ /**
8
+ * Billing email address
9
+ *
10
+ * @var string
11
+ */
12
+ public $billing_email;
13
+ /**
14
+ * Checkout data
15
+ *
16
+ * @var string
17
+ */
18
+ public $data;
19
+ /**
20
+ * Date timestamp
21
+ *
22
+ * @var string
23
+ */
24
+ public $timestamp;
25
+ /**
26
+ * User ID
27
+ *
28
+ * @var int
29
+ */
30
+ public $user_id;
31
+ /**
32
+ * Universal Identifier
33
+ *
34
+ * @var string
35
+ */
36
+ public $uuid;
37
+ }
src/Models/CustomerNewAccount.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ use WC_Customer;
6
+
7
+ class CustomerNewAccount
8
+ {
9
+ /**
10
+ * Account URL string
11
+ *
12
+ * @var string
13
+ */
14
+ public $account_url;
15
+ /**
16
+ * Customer object
17
+ *
18
+ * @var WC_Customer
19
+ */
20
+ public $customer;
21
+ /**
22
+ * Customer ID
23
+ *
24
+ * @var int
25
+ */
26
+ public $customer_id;
27
+ /**
28
+ * Customer Password
29
+ *
30
+ * @var string
31
+ */
32
+ public $generated_password;
33
+ /**
34
+ * Salt created for the customer password
35
+ *
36
+ * @var string
37
+ */
38
+ public $salt;
39
+ }
src/Models/CustomerNote.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ class CustomerNote
6
+ {
7
+ /**
8
+ * Customer notes
9
+ *
10
+ * @var string
11
+ */
12
+ public $note;
13
+ /**
14
+ * Order ID
15
+ *
16
+ * @var int
17
+ */
18
+ public $order_id;
19
+ /**
20
+ * Order URL string
21
+ *
22
+ * @var string
23
+ */
24
+ public $order_url;
25
+ }
src/Models/CustomerResetPassword.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ use WC_Customer;
6
+
7
+ class CustomerResetPassword
8
+ {
9
+ /**
10
+ * Account URL string
11
+ *
12
+ * @var string
13
+ */
14
+ public $account_url;
15
+ /**
16
+ * Customer object
17
+ *
18
+ * @var WC_Customer
19
+ */
20
+ public $customer;
21
+ /**
22
+ * Customer ID
23
+ *
24
+ * @var int
25
+ */
26
+ public $customer_id;
27
+ /**
28
+ * Reset password URL string
29
+ *
30
+ * @var string
31
+ */
32
+ public $reset_url;
33
+ }
src/Models/EmailNotification.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ class EmailNotification
6
+ {
7
+ /**
8
+ * Order ID
9
+ *
10
+ * @var int
11
+ */
12
+ public $order_id;
13
+ /**
14
+ * Order URL to view the order
15
+ *
16
+ * @var string
17
+ */
18
+ public $order_url;
19
+ }
src/Models/HashSchema.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ class HashSchema
6
+ {
7
+ /**
8
+ * Hash key string
9
+ *
10
+ * @var string
11
+ */
12
+ public $key;
13
+ /**
14
+ * Hash salt string
15
+ *
16
+ * @var string
17
+ */
18
+ public $salt;
19
+ /**
20
+ * Hash secret string
21
+ *
22
+ * @var string
23
+ */
24
+ public $secret;
25
+ /**
26
+ * Hash version
27
+ *
28
+ * @var string
29
+ */
30
+ public $version;
31
+ }
src/Models/OptionsSchema.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ class OptionsSchema
6
+ {
7
+ /**
8
+ * Option activation
9
+ *
10
+ * @var bool
11
+ */
12
+ public $active;
13
+ /**
14
+ * Option name
15
+ *
16
+ * @var string
17
+ */
18
+ public $name;
19
+ }
src/Models/Order.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ class Order
6
+ {
7
+ /**
8
+ * Order billing information
9
+ *
10
+ * @var OrderBilling
11
+ */
12
+ public $billing;
13
+ /**
14
+ * Currency string
15
+ *
16
+ * @var string
17
+ */
18
+ public $currency;
19
+ /**
20
+ * Currency symbol
21
+ *
22
+ * @var string
23
+ */
24
+ public $currency_symbol;
25
+ /**
26
+ * Order items
27
+ *
28
+ * @var array
29
+ */
30
+ public $line_items;
31
+ /**
32
+ * Total of items in the order
33
+ *
34
+ * @var int|string
35
+ */
36
+ public $total_line_items_quantity;
37
+ }
src/Models/OrderBilling.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ use CreativeMail\Modules\Contacts\Models\OptActionBy;
6
+
7
+ class OrderBilling
8
+ {
9
+ /**
10
+ * Order Address Number 1
11
+ *
12
+ * @var string
13
+ */
14
+ public $address_1;
15
+ /**
16
+ * Order Address Number 2
17
+ *
18
+ * @var string
19
+ */
20
+ public $address_2;
21
+ /**
22
+ * Order city
23
+ *
24
+ * @var string
25
+ */
26
+ public $city;
27
+ /**
28
+ * Order company
29
+ *
30
+ * @var string
31
+ */
32
+ public $company;
33
+ /**
34
+ * Order country
35
+ *
36
+ * @var string
37
+ */
38
+ public $country;
39
+ /**
40
+ * Order email address
41
+ *
42
+ * @var string
43
+ */
44
+ public $email;
45
+ /**
46
+ * Order customer first name
47
+ *
48
+ * @var string
49
+ */
50
+ public $first_name;
51
+ /**
52
+ * Variable to check is customer is first buyer
53
+ *
54
+ * @var bool
55
+ */
56
+ public $is_first_time_buyer;
57
+ /**
58
+ * Order customer last name
59
+ *
60
+ * @var string
61
+ */
62
+ public $last_name;
63
+ /**
64
+ * Order customer opt action by
65
+ *
66
+ * @var OptActionBy
67
+ */
68
+ public $opt_action_by;
69
+ /**
70
+ * Order customer opt action by
71
+ *
72
+ * @var bool|null
73
+ */
74
+ public $opt_in;
75
+ /**
76
+ * Order customer opt action by
77
+ *
78
+ * @var bool|null
79
+ */
80
+ public $opt_out;
81
+ /**
82
+ * Order payments details
83
+ *
84
+ * @var array
85
+ */
86
+ public $payment_details;
87
+ /**
88
+ * Order phone number
89
+ *
90
+ * @var string
91
+ */
92
+ public $phone;
93
+ /**
94
+ * Order shipping postcode
95
+ *
96
+ * @var string
97
+ */
98
+ public $postcode;
99
+ /**
100
+ * Order shipping details
101
+ *
102
+ * @var array
103
+ */
104
+ public $shipping;
105
+ /**
106
+ * Order Shipping state
107
+ *
108
+ * @var string
109
+ */
110
+ public $state;
111
+ }
src/Models/RequestItem.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ use WC_DateTime;
6
+
7
+ class RequestItem
8
+ {
9
+ /**
10
+ * Cart tax
11
+ *
12
+ * @var float
13
+ */
14
+ public $cart_tax;
15
+ /**
16
+ * Customer ID
17
+ *
18
+ * @var int
19
+ */
20
+ public $customer_id;
21
+ /**
22
+ * Customer IP address
23
+ *
24
+ * @var string
25
+ */
26
+ public $customer_ip;
27
+ /**
28
+ * Customer user agent
29
+ *
30
+ * @var string
31
+ */
32
+ public $customer_user_agent;
33
+ /**
34
+ * Date completed
35
+ *
36
+ * @var WC_DateTime|NULL
37
+ */
38
+ public $date_completed;
39
+ /**
40
+ * Date created
41
+ *
42
+ * @var WC_DateTime|NULL
43
+ */
44
+ public $date_created;
45
+ /**
46
+ * Date modified
47
+ *
48
+ * @var WC_DateTime|NULL
49
+ */
50
+ public $date_modified;
51
+ /**
52
+ * Discount total
53
+ *
54
+ * @var string
55
+ */
56
+ public $discount_total;
57
+ /**
58
+ * Notes
59
+ *
60
+ * @var string
61
+ */
62
+ public $note;
63
+ /**
64
+ * Order object
65
+ *
66
+ * @var Order
67
+ */
68
+ public $order;
69
+ /**
70
+ * Order ID
71
+ *
72
+ * @var int
73
+ */
74
+ public $order_id;
75
+ /**
76
+ * Order number
77
+ *
78
+ * @var string
79
+ */
80
+ public $order_number;
81
+ /**
82
+ * Order URL string
83
+ *
84
+ * @var string
85
+ */
86
+ public $order_url;
87
+ /**
88
+ * Shipping tax value
89
+ *
90
+ * @var string
91
+ */
92
+ public $shipping_tax;
93
+ /**
94
+ * Shipping total
95
+ *
96
+ * @var string
97
+ */
98
+ public $shipping_total;
99
+ /**
100
+ * Request status
101
+ *
102
+ * @var string
103
+ */
104
+ public $status;
105
+ /**
106
+ * Subtotal
107
+ *
108
+ * @var string
109
+ */
110
+ public $subtotal;
111
+ /**
112
+ * Total
113
+ *
114
+ * @var string
115
+ */
116
+ public $total;
117
+ /**
118
+ * Total tax
119
+ *
120
+ * @var string
121
+ */
122
+ public $total_tax;
123
+ }
src/Models/Response.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ class Response
6
+ {
7
+ /**
8
+ * Response URL string
9
+ *
10
+ * @var string
11
+ */
12
+ public $url;
13
+ }
src/Models/TriggerExecution.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ class TriggerExecution
6
+ {
7
+ /**
8
+ * Data for the execution of the trigger.
9
+ *
10
+ * @var string
11
+ */
12
+ public $data;
13
+ /**
14
+ * Type of the trigger.
15
+ *
16
+ * @var string
17
+ */
18
+ public $type;
19
+ }
src/Models/User.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Models;
4
+
5
+ class User
6
+ {
7
+ /**
8
+ * User display name
9
+ *
10
+ * @var string
11
+ */
12
+ public $display_name;
13
+ /**
14
+ * User email address
15
+ *
16
+ * @var string
17
+ */
18
+ public $email;
19
+ /**
20
+ * User first name
21
+ *
22
+ * @var string
23
+ */
24
+ public $first_name;
25
+ /**
26
+ * User ID
27
+ *
28
+ * @var int
29
+ */
30
+ public $id;
31
+ /**
32
+ * User last name
33
+ *
34
+ * @var string
35
+ */
36
+ public $last_name;
37
+ /**
38
+ * User login username
39
+ *
40
+ * @var string
41
+ */
42
+ public $username;
43
+ }
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInit8d22ccb6673585e204258acc03bcb64b::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInitee46db4f3fa7780cf9da57748b865cb0::getLoader();
vendor/composer/autoload_classmap.php CHANGED
@@ -27,6 +27,23 @@ return array(
27
  'CreativeMail\\Managers\\InstanceManager' => $baseDir . '/src/Managers/InstanceManager.php',
28
  'CreativeMail\\Managers\\IntegrationManager' => $baseDir . '/src/Managers/IntegrationManager.php',
29
  'CreativeMail\\Managers\\RaygunManager' => $baseDir . '/src/Managers/RaygunManager.php',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  'CreativeMail\\Modules\\Api\\Models\\ApiRequestItem' => $baseDir . '/src/Modules/Api/Models/ApiRequestItem.php',
31
  'CreativeMail\\Modules\\Api\\Processes\\ApiBackgroundProcess' => $baseDir . '/src/Modules/Api/Processes/ApiBackgroundProcess.php',
32
  'CreativeMail\\Modules\\Blog\\Models\\BlogAttachment' => $baseDir . '/src/Modules/Blog/Models/BlogAttachment.php',
@@ -78,6 +95,7 @@ return array(
78
  'Firebase\\JWT\\ExpiredException' => $vendorDir . '/firebase/php-jwt/src/ExpiredException.php',
79
  'Firebase\\JWT\\JWK' => $vendorDir . '/firebase/php-jwt/src/JWK.php',
80
  'Firebase\\JWT\\JWT' => $vendorDir . '/firebase/php-jwt/src/JWT.php',
 
81
  'Firebase\\JWT\\SignatureInvalidException' => $vendorDir . '/firebase/php-jwt/src/SignatureInvalidException.php',
82
  'Raygun4php\\Raygun4PhpException' => $vendorDir . '/mindscape/raygun4php/src/Raygun4php/Raygun4PhpException.php',
83
  'Raygun4php\\RaygunClient' => $vendorDir . '/mindscape/raygun4php/src/Raygun4php/RaygunClient.php',
27
  'CreativeMail\\Managers\\InstanceManager' => $baseDir . '/src/Managers/InstanceManager.php',
28
  'CreativeMail\\Managers\\IntegrationManager' => $baseDir . '/src/Managers/IntegrationManager.php',
29
  'CreativeMail\\Managers\\RaygunManager' => $baseDir . '/src/Managers/RaygunManager.php',
30
+ 'CreativeMail\\Models\\ApiSchema' => $baseDir . '/src/Models/ApiSchema.php',
31
+ 'CreativeMail\\Models\\Campaign' => $baseDir . '/src/Models/Campaign.php',
32
+ 'CreativeMail\\Models\\CartData' => $baseDir . '/src/Models/CartData.php',
33
+ 'CreativeMail\\Models\\Checkout' => $baseDir . '/src/Models/Checkout.php',
34
+ 'CreativeMail\\Models\\CheckoutSave' => $baseDir . '/src/Models/CheckoutSave.php',
35
+ 'CreativeMail\\Models\\CustomerNewAccount' => $baseDir . '/src/Models/CustomerNewAccount.php',
36
+ 'CreativeMail\\Models\\CustomerNote' => $baseDir . '/src/Models/CustomerNote.php',
37
+ 'CreativeMail\\Models\\CustomerResetPassword' => $baseDir . '/src/Models/CustomerResetPassword.php',
38
+ 'CreativeMail\\Models\\EmailNotification' => $baseDir . '/src/Models/EmailNotification.php',
39
+ 'CreativeMail\\Models\\HashSchema' => $baseDir . '/src/Models/HashSchema.php',
40
+ 'CreativeMail\\Models\\OptionsSchema' => $baseDir . '/src/Models/OptionsSchema.php',
41
+ 'CreativeMail\\Models\\Order' => $baseDir . '/src/Models/Order.php',
42
+ 'CreativeMail\\Models\\OrderBilling' => $baseDir . '/src/Models/OrderBilling.php',
43
+ 'CreativeMail\\Models\\RequestItem' => $baseDir . '/src/Models/RequestItem.php',
44
+ 'CreativeMail\\Models\\Response' => $baseDir . '/src/Models/Response.php',
45
+ 'CreativeMail\\Models\\TriggerExecution' => $baseDir . '/src/Models/TriggerExecution.php',
46
+ 'CreativeMail\\Models\\User' => $baseDir . '/src/Models/User.php',
47
  'CreativeMail\\Modules\\Api\\Models\\ApiRequestItem' => $baseDir . '/src/Modules/Api/Models/ApiRequestItem.php',
48
  'CreativeMail\\Modules\\Api\\Processes\\ApiBackgroundProcess' => $baseDir . '/src/Modules/Api/Processes/ApiBackgroundProcess.php',
49
  'CreativeMail\\Modules\\Blog\\Models\\BlogAttachment' => $baseDir . '/src/Modules/Blog/Models/BlogAttachment.php',
95
  'Firebase\\JWT\\ExpiredException' => $vendorDir . '/firebase/php-jwt/src/ExpiredException.php',
96
  'Firebase\\JWT\\JWK' => $vendorDir . '/firebase/php-jwt/src/JWK.php',
97
  'Firebase\\JWT\\JWT' => $vendorDir . '/firebase/php-jwt/src/JWT.php',
98
+ 'Firebase\\JWT\\Key' => $vendorDir . '/firebase/php-jwt/src/Key.php',
99
  'Firebase\\JWT\\SignatureInvalidException' => $vendorDir . '/firebase/php-jwt/src/SignatureInvalidException.php',
100
  'Raygun4php\\Raygun4PhpException' => $vendorDir . '/mindscape/raygun4php/src/Raygun4php/Raygun4PhpException.php',
101
  'Raygun4php\\RaygunClient' => $vendorDir . '/mindscape/raygun4php/src/Raygun4php/RaygunClient.php',
vendor/composer/autoload_psr4.php CHANGED
@@ -9,6 +9,7 @@ return array(
9
  'Firebase\\JWT\\' => array($vendorDir . '/firebase/php-jwt/src'),
10
  'Defuse\\Crypto\\' => array($vendorDir . '/defuse/php-encryption/src'),
11
  'CreativeMail\\Modules\\' => array($baseDir . '/src/modules'),
 
12
  'CreativeMail\\Managers\\' => array($baseDir . '/src/managers'),
13
  'CreativeMail\\Integrations\\' => array($baseDir . '/src/integrations'),
14
  'CreativeMail\\Helpers\\' => array($baseDir . '/src/helpers'),
9
  'Firebase\\JWT\\' => array($vendorDir . '/firebase/php-jwt/src'),
10
  'Defuse\\Crypto\\' => array($vendorDir . '/defuse/php-encryption/src'),
11
  'CreativeMail\\Modules\\' => array($baseDir . '/src/modules'),
12
+ 'CreativeMail\\Models\\' => array($baseDir . '/src/models'),
13
  'CreativeMail\\Managers\\' => array($baseDir . '/src/managers'),
14
  'CreativeMail\\Integrations\\' => array($baseDir . '/src/integrations'),
15
  'CreativeMail\\Helpers\\' => array($baseDir . '/src/helpers'),
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInit8d22ccb6673585e204258acc03bcb64b
6
  {
7
  private static $loader;
8
 
@@ -22,15 +22,15 @@ class ComposerAutoloaderInit8d22ccb6673585e204258acc03bcb64b
22
  return self::$loader;
23
  }
24
 
25
- spl_autoload_register(array('ComposerAutoloaderInit8d22ccb6673585e204258acc03bcb64b', 'loadClassLoader'), true, true);
26
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
27
- spl_autoload_unregister(array('ComposerAutoloaderInit8d22ccb6673585e204258acc03bcb64b', 'loadClassLoader'));
28
 
29
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
30
  if ($useStaticLoader) {
31
  require_once __DIR__ . '/autoload_static.php';
32
 
33
- call_user_func(\Composer\Autoload\ComposerStaticInit8d22ccb6673585e204258acc03bcb64b::getInitializer($loader));
34
  } else {
35
  $map = require __DIR__ . '/autoload_namespaces.php';
36
  foreach ($map as $namespace => $path) {
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInitee46db4f3fa7780cf9da57748b865cb0
6
  {
7
  private static $loader;
8
 
22
  return self::$loader;
23
  }
24
 
25
+ spl_autoload_register(array('ComposerAutoloaderInitee46db4f3fa7780cf9da57748b865cb0', 'loadClassLoader'), true, true);
26
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
27
+ spl_autoload_unregister(array('ComposerAutoloaderInitee46db4f3fa7780cf9da57748b865cb0', 'loadClassLoader'));
28
 
29
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
30
  if ($useStaticLoader) {
31
  require_once __DIR__ . '/autoload_static.php';
32
 
33
+ call_user_func(\Composer\Autoload\ComposerStaticInitee46db4f3fa7780cf9da57748b865cb0::getInitializer($loader));
34
  } else {
35
  $map = require __DIR__ . '/autoload_namespaces.php';
36
  foreach ($map as $namespace => $path) {
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInit8d22ccb6673585e204258acc03bcb64b
8
  {
9
  public static $prefixLengthsPsr4 = array (
10
  'F' =>
@@ -18,6 +18,7 @@ class ComposerStaticInit8d22ccb6673585e204258acc03bcb64b
18
  'C' =>
19
  array (
20
  'CreativeMail\\Modules\\' => 21,
 
21
  'CreativeMail\\Managers\\' => 22,
22
  'CreativeMail\\Integrations\\' => 26,
23
  'CreativeMail\\Helpers\\' => 21,
@@ -40,6 +41,10 @@ class ComposerStaticInit8d22ccb6673585e204258acc03bcb64b
40
  array (
41
  0 => __DIR__ . '/../..' . '/src/modules',
42
  ),
 
 
 
 
43
  'CreativeMail\\Managers\\' =>
44
  array (
45
  0 => __DIR__ . '/../..' . '/src/managers',
@@ -98,6 +103,23 @@ class ComposerStaticInit8d22ccb6673585e204258acc03bcb64b
98
  'CreativeMail\\Managers\\InstanceManager' => __DIR__ . '/../..' . '/src/Managers/InstanceManager.php',
99
  'CreativeMail\\Managers\\IntegrationManager' => __DIR__ . '/../..' . '/src/Managers/IntegrationManager.php',
100
  'CreativeMail\\Managers\\RaygunManager' => __DIR__ . '/../..' . '/src/Managers/RaygunManager.php',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  'CreativeMail\\Modules\\Api\\Models\\ApiRequestItem' => __DIR__ . '/../..' . '/src/Modules/Api/Models/ApiRequestItem.php',
102
  'CreativeMail\\Modules\\Api\\Processes\\ApiBackgroundProcess' => __DIR__ . '/../..' . '/src/Modules/Api/Processes/ApiBackgroundProcess.php',
103
  'CreativeMail\\Modules\\Blog\\Models\\BlogAttachment' => __DIR__ . '/../..' . '/src/Modules/Blog/Models/BlogAttachment.php',
@@ -149,6 +171,7 @@ class ComposerStaticInit8d22ccb6673585e204258acc03bcb64b
149
  'Firebase\\JWT\\ExpiredException' => __DIR__ . '/..' . '/firebase/php-jwt/src/ExpiredException.php',
150
  'Firebase\\JWT\\JWK' => __DIR__ . '/..' . '/firebase/php-jwt/src/JWK.php',
151
  'Firebase\\JWT\\JWT' => __DIR__ . '/..' . '/firebase/php-jwt/src/JWT.php',
 
152
  'Firebase\\JWT\\SignatureInvalidException' => __DIR__ . '/..' . '/firebase/php-jwt/src/SignatureInvalidException.php',
153
  'Raygun4php\\Raygun4PhpException' => __DIR__ . '/..' . '/mindscape/raygun4php/src/Raygun4php/Raygun4PhpException.php',
154
  'Raygun4php\\RaygunClient' => __DIR__ . '/..' . '/mindscape/raygun4php/src/Raygun4php/RaygunClient.php',
@@ -167,10 +190,10 @@ class ComposerStaticInit8d22ccb6673585e204258acc03bcb64b
167
  public static function getInitializer(ClassLoader $loader)
168
  {
169
  return \Closure::bind(function () use ($loader) {
170
- $loader->prefixLengthsPsr4 = ComposerStaticInit8d22ccb6673585e204258acc03bcb64b::$prefixLengthsPsr4;
171
- $loader->prefixDirsPsr4 = ComposerStaticInit8d22ccb6673585e204258acc03bcb64b::$prefixDirsPsr4;
172
- $loader->prefixesPsr0 = ComposerStaticInit8d22ccb6673585e204258acc03bcb64b::$prefixesPsr0;
173
- $loader->classMap = ComposerStaticInit8d22ccb6673585e204258acc03bcb64b::$classMap;
174
 
175
  }, null, ClassLoader::class);
176
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInitee46db4f3fa7780cf9da57748b865cb0
8
  {
9
  public static $prefixLengthsPsr4 = array (
10
  'F' =>
18
  'C' =>
19
  array (
20
  'CreativeMail\\Modules\\' => 21,
21
+ 'CreativeMail\\Models\\' => 20,
22
  'CreativeMail\\Managers\\' => 22,
23
  'CreativeMail\\Integrations\\' => 26,
24
  'CreativeMail\\Helpers\\' => 21,
41
  array (
42
  0 => __DIR__ . '/../..' . '/src/modules',
43
  ),
44
+ 'CreativeMail\\Models\\' =>
45
+ array (
46
+ 0 => __DIR__ . '/../..' . '/src/models',
47
+ ),
48
  'CreativeMail\\Managers\\' =>
49
  array (
50
  0 => __DIR__ . '/../..' . '/src/managers',
103
  'CreativeMail\\Managers\\InstanceManager' => __DIR__ . '/../..' . '/src/Managers/InstanceManager.php',
104
  'CreativeMail\\Managers\\IntegrationManager' => __DIR__ . '/../..' . '/src/Managers/IntegrationManager.php',
105
  'CreativeMail\\Managers\\RaygunManager' => __DIR__ . '/../..' . '/src/Managers/RaygunManager.php',
106
+ 'CreativeMail\\Models\\ApiSchema' => __DIR__ . '/../..' . '/src/Models/ApiSchema.php',
107
+ 'CreativeMail\\Models\\Campaign' => __DIR__ . '/../..' . '/src/Models/Campaign.php',
108
+ 'CreativeMail\\Models\\CartData' => __DIR__ . '/../..' . '/src/Models/CartData.php',
109
+ 'CreativeMail\\Models\\Checkout' => __DIR__ . '/../..' . '/src/Models/Checkout.php',
110
+ 'CreativeMail\\Models\\CheckoutSave' => __DIR__ . '/../..' . '/src/Models/CheckoutSave.php',
111
+ 'CreativeMail\\Models\\CustomerNewAccount' => __DIR__ . '/../..' . '/src/Models/CustomerNewAccount.php',
112
+ 'CreativeMail\\Models\\CustomerNote' => __DIR__ . '/../..' . '/src/Models/CustomerNote.php',
113
+ 'CreativeMail\\Models\\CustomerResetPassword' => __DIR__ . '/../..' . '/src/Models/CustomerResetPassword.php',
114
+ 'CreativeMail\\Models\\EmailNotification' => __DIR__ . '/../..' . '/src/Models/EmailNotification.php',
115
+ 'CreativeMail\\Models\\HashSchema' => __DIR__ . '/../..' . '/src/Models/HashSchema.php',
116
+ 'CreativeMail\\Models\\OptionsSchema' => __DIR__ . '/../..' . '/src/Models/OptionsSchema.php',
117
+ 'CreativeMail\\Models\\Order' => __DIR__ . '/../..' . '/src/Models/Order.php',
118
+ 'CreativeMail\\Models\\OrderBilling' => __DIR__ . '/../..' . '/src/Models/OrderBilling.php',
119
+ 'CreativeMail\\Models\\RequestItem' => __DIR__ . '/../..' . '/src/Models/RequestItem.php',
120
+ 'CreativeMail\\Models\\Response' => __DIR__ . '/../..' . '/src/Models/Response.php',
121
+ 'CreativeMail\\Models\\TriggerExecution' => __DIR__ . '/../..' . '/src/Models/TriggerExecution.php',
122
+ 'CreativeMail\\Models\\User' => __DIR__ . '/../..' . '/src/Models/User.php',
123
  'CreativeMail\\Modules\\Api\\Models\\ApiRequestItem' => __DIR__ . '/../..' . '/src/Modules/Api/Models/ApiRequestItem.php',
124
  'CreativeMail\\Modules\\Api\\Processes\\ApiBackgroundProcess' => __DIR__ . '/../..' . '/src/Modules/Api/Processes/ApiBackgroundProcess.php',
125
  'CreativeMail\\Modules\\Blog\\Models\\BlogAttachment' => __DIR__ . '/../..' . '/src/Modules/Blog/Models/BlogAttachment.php',
171
  'Firebase\\JWT\\ExpiredException' => __DIR__ . '/..' . '/firebase/php-jwt/src/ExpiredException.php',
172
  'Firebase\\JWT\\JWK' => __DIR__ . '/..' . '/firebase/php-jwt/src/JWK.php',
173
  'Firebase\\JWT\\JWT' => __DIR__ . '/..' . '/firebase/php-jwt/src/JWT.php',
174
+ 'Firebase\\JWT\\Key' => __DIR__ . '/..' . '/firebase/php-jwt/src/Key.php',
175
  'Firebase\\JWT\\SignatureInvalidException' => __DIR__ . '/..' . '/firebase/php-jwt/src/SignatureInvalidException.php',
176
  'Raygun4php\\Raygun4PhpException' => __DIR__ . '/..' . '/mindscape/raygun4php/src/Raygun4php/Raygun4PhpException.php',
177
  'Raygun4php\\RaygunClient' => __DIR__ . '/..' . '/mindscape/raygun4php/src/Raygun4php/RaygunClient.php',
190
  public static function getInitializer(ClassLoader $loader)
191
  {
192
  return \Closure::bind(function () use ($loader) {
193
+ $loader->prefixLengthsPsr4 = ComposerStaticInitee46db4f3fa7780cf9da57748b865cb0::$prefixLengthsPsr4;
194
+ $loader->prefixDirsPsr4 = ComposerStaticInitee46db4f3fa7780cf9da57748b865cb0::$prefixDirsPsr4;
195
+ $loader->prefixesPsr0 = ComposerStaticInitee46db4f3fa7780cf9da57748b865cb0::$prefixesPsr0;
196
+ $loader->classMap = ComposerStaticInitee46db4f3fa7780cf9da57748b865cb0::$classMap;
197
 
198
  }, null, ClassLoader::class);
199
  }
vendor/composer/installed.json CHANGED
@@ -114,17 +114,17 @@
114
  },
115
  {
116
  "name": "firebase/php-jwt",
117
- "version": "v5.3.0",
118
- "version_normalized": "5.3.0.0",
119
  "source": {
120
  "type": "git",
121
  "url": "https://github.com/firebase/php-jwt.git",
122
- "reference": "3c2d70f2e64e2922345e89f2ceae47d2463faae1"
123
  },
124
  "dist": {
125
  "type": "zip",
126
- "url": "https://api.github.com/repos/firebase/php-jwt/zipball/3c2d70f2e64e2922345e89f2ceae47d2463faae1",
127
- "reference": "3c2d70f2e64e2922345e89f2ceae47d2463faae1",
128
  "shasum": ""
129
  },
130
  "require": {
@@ -133,7 +133,10 @@
133
  "require-dev": {
134
  "phpunit/phpunit": ">=4.8 <=9"
135
  },
136
- "time": "2021-05-20T17:37:02+00:00",
 
 
 
137
  "type": "library",
138
  "installation-source": "dist",
139
  "autoload": {
@@ -165,7 +168,7 @@
165
  ],
166
  "support": {
167
  "issues": "https://github.com/firebase/php-jwt/issues",
168
- "source": "https://github.com/firebase/php-jwt/tree/v5.3.0"
169
  }
170
  },
171
  {
@@ -342,17 +345,17 @@
342
  },
343
  {
344
  "name": "squizlabs/php_codesniffer",
345
- "version": "3.6.0",
346
- "version_normalized": "3.6.0.0",
347
  "source": {
348
  "type": "git",
349
  "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
350
- "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625"
351
  },
352
  "dist": {
353
  "type": "zip",
354
- "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ffced0d2c8fa8e6cdc4d695a743271fab6c38625",
355
- "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625",
356
  "shasum": ""
357
  },
358
  "require": {
@@ -364,7 +367,7 @@
364
  "require-dev": {
365
  "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
366
  },
367
- "time": "2021-04-09T00:54:41+00:00",
368
  "bin": [
369
  "bin/phpcs",
370
  "bin/phpcbf"
114
  },
115
  {
116
  "name": "firebase/php-jwt",
117
+ "version": "v5.5.1",
118
+ "version_normalized": "5.5.1.0",
119
  "source": {
120
  "type": "git",
121
  "url": "https://github.com/firebase/php-jwt.git",
122
+ "reference": "83b609028194aa042ea33b5af2d41a7427de80e6"
123
  },
124
  "dist": {
125
  "type": "zip",
126
+ "url": "https://api.github.com/repos/firebase/php-jwt/zipball/83b609028194aa042ea33b5af2d41a7427de80e6",
127
+ "reference": "83b609028194aa042ea33b5af2d41a7427de80e6",
128
  "shasum": ""
129
  },
130
  "require": {
133
  "require-dev": {
134
  "phpunit/phpunit": ">=4.8 <=9"
135
  },
136
+ "suggest": {
137
+ "paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present"
138
+ },
139
+ "time": "2021-11-08T20:18:51+00:00",
140
  "type": "library",
141
  "installation-source": "dist",
142
  "autoload": {
168
  ],
169
  "support": {
170
  "issues": "https://github.com/firebase/php-jwt/issues",
171
+ "source": "https://github.com/firebase/php-jwt/tree/v5.5.1"
172
  }
173
  },
174
  {
345
  },
346
  {
347
  "name": "squizlabs/php_codesniffer",
348
+ "version": "3.6.2",
349
+ "version_normalized": "3.6.2.0",
350
  "source": {
351
  "type": "git",
352
  "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
353
+ "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a"
354
  },
355
  "dist": {
356
  "type": "zip",
357
+ "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a",
358
+ "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a",
359
  "shasum": ""
360
  },
361
  "require": {
367
  "require-dev": {
368
  "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
369
  },
370
+ "time": "2021-12-12T21:44:58+00:00",
371
  "bin": [
372
  "bin/phpcs",
373
  "bin/phpcbf"
vendor/firebase/php-jwt/README.md CHANGED
@@ -16,10 +16,18 @@ Use composer to manage your dependencies and download PHP-JWT:
16
  composer require firebase/php-jwt
17
  ```
18
 
 
 
 
 
 
 
 
19
  Example
20
  -------
21
  ```php
22
  use Firebase\JWT\JWT;
 
23
 
24
  $key = "example_key";
25
  $payload = array(
@@ -35,8 +43,8 @@ $payload = array(
35
  * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40
36
  * for a list of spec-compliant algorithms.
37
  */
38
- $jwt = JWT::encode($payload, $key);
39
- $decoded = JWT::decode($jwt, $key, array('HS256'));
40
 
41
  print_r($decoded);
42
 
@@ -55,12 +63,13 @@ $decoded_array = (array) $decoded;
55
  * Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef
56
  */
57
  JWT::$leeway = 60; // $leeway in seconds
58
- $decoded = JWT::decode($jwt, $key, array('HS256'));
59
  ```
60
  Example with RS256 (openssl)
61
  ----------------------------
62
  ```php
63
  use Firebase\JWT\JWT;
 
64
 
65
  $privateKey = <<<EOD
66
  -----BEGIN RSA PRIVATE KEY-----
@@ -99,7 +108,7 @@ $payload = array(
99
  $jwt = JWT::encode($payload, $privateKey, 'RS256');
100
  echo "Encode:\n" . print_r($jwt, true) . "\n";
101
 
102
- $decoded = JWT::decode($jwt, $publicKey, array('RS256'));
103
 
104
  /*
105
  NOTE: This will now be an object instead of an associative array. To get
@@ -114,6 +123,9 @@ Example with a passphrase
114
  -------------------------
115
 
116
  ```php
 
 
 
117
  // Your passphrase
118
  $passphrase = '[YOUR_PASSPHRASE]';
119
 
@@ -140,10 +152,41 @@ echo "Encode:\n" . print_r($jwt, true) . "\n";
140
  // Get public key from the private key, or pull from from a file.
141
  $publicKey = openssl_pkey_get_details($privateKey)['key'];
142
 
143
- $decoded = JWT::decode($jwt, $publicKey, array('RS256'));
144
  echo "Decode:\n" . print_r((array) $decoded, true) . "\n";
145
  ```
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  Using JWKs
148
  ----------
149
 
@@ -157,6 +200,7 @@ $jwks = ['keys' => []];
157
 
158
  // JWK::parseKeySet($jwks) returns an associative array of **kid** to private
159
  // key. Pass this as the second parameter to JWT::decode.
 
160
  JWT::decode($payload, JWK::parseKeySet($jwks), $supportedAlgorithm);
161
  ```
162
 
16
  composer require firebase/php-jwt
17
  ```
18
 
19
+ Optionally, install the `paragonie/sodium_compat` package from composer if your
20
+ php is < 7.2 or does not have libsodium installed:
21
+
22
+ ```bash
23
+ composer require paragonie/sodium_compat
24
+ ```
25
+
26
  Example
27
  -------
28
  ```php
29
  use Firebase\JWT\JWT;
30
+ use Firebase\JWT\Key;
31
 
32
  $key = "example_key";
33
  $payload = array(
43
  * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40
44
  * for a list of spec-compliant algorithms.
45
  */
46
+ $jwt = JWT::encode($payload, $key, 'HS256');
47
+ $decoded = JWT::decode($jwt, new Key($key, 'HS256'));
48
 
49
  print_r($decoded);
50
 
63
  * Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef
64
  */
65
  JWT::$leeway = 60; // $leeway in seconds
66
+ $decoded = JWT::decode($jwt, new Key($key, 'HS256'));
67
  ```
68
  Example with RS256 (openssl)
69
  ----------------------------
70
  ```php
71
  use Firebase\JWT\JWT;
72
+ use Firebase\JWT\Key;
73
 
74
  $privateKey = <<<EOD
75
  -----BEGIN RSA PRIVATE KEY-----
108
  $jwt = JWT::encode($payload, $privateKey, 'RS256');
109
  echo "Encode:\n" . print_r($jwt, true) . "\n";
110
 
111
+ $decoded = JWT::decode($jwt, new Key($publicKey, 'RS256'));
112
 
113
  /*
114
  NOTE: This will now be an object instead of an associative array. To get
123
  -------------------------
124
 
125
  ```php
126
+ use Firebase\JWT\JWT;
127
+ use Firebase\JWT\Key;
128
+
129
  // Your passphrase
130
  $passphrase = '[YOUR_PASSPHRASE]';
131
 
152
  // Get public key from the private key, or pull from from a file.
153
  $publicKey = openssl_pkey_get_details($privateKey)['key'];
154
 
155
+ $decoded = JWT::decode($jwt, new Key($publicKey, 'RS256'));
156
  echo "Decode:\n" . print_r((array) $decoded, true) . "\n";
157
  ```
158
 
159
+ Example with EdDSA (libsodium and Ed25519 signature)
160
+ ----------------------------
161
+ ```php
162
+ use Firebase\JWT\JWT;
163
+ use Firebase\JWT\Key;
164
+
165
+ // Public and private keys are expected to be Base64 encoded. The last
166
+ // non-empty line is used so that keys can be generated with
167
+ // sodium_crypto_sign_keypair(). The secret keys generated by other tools may
168
+ // need to be adjusted to match the input expected by libsodium.
169
+
170
+ $keyPair = sodium_crypto_sign_keypair();
171
+
172
+ $privateKey = base64_encode(sodium_crypto_sign_secretkey($keyPair));
173
+
174
+ $publicKey = base64_encode(sodium_crypto_sign_publickey($keyPair));
175
+
176
+ $payload = array(
177
+ "iss" => "example.org",
178
+ "aud" => "example.com",
179
+ "iat" => 1356999524,
180
+ "nbf" => 1357000000
181
+ );
182
+
183
+ $jwt = JWT::encode($payload, $privateKey, 'EdDSA');
184
+ echo "Encode:\n" . print_r($jwt, true) . "\n";
185
+
186
+ $decoded = JWT::decode($jwt, new Key($publicKey, 'EdDSA'));
187
+ echo "Decode:\n" . print_r((array) $decoded, true) . "\n";
188
+ ````
189
+
190
  Using JWKs
191
  ----------
192
 
200
 
201
  // JWK::parseKeySet($jwks) returns an associative array of **kid** to private
202
  // key. Pass this as the second parameter to JWT::decode.
203
+ // NOTE: The deprecated $supportedAlgorithm must be supplied when parsing from JWK.
204
  JWT::decode($payload, JWK::parseKeySet($jwks), $supportedAlgorithm);
205
  ```
206
 
vendor/firebase/php-jwt/composer.json CHANGED
@@ -22,6 +22,9 @@
22
  "require": {
23
  "php": ">=5.3.0"
24
  },
 
 
 
25
  "autoload": {
26
  "psr-4": {
27
  "Firebase\\JWT\\": "src"
22
  "require": {
23
  "php": ">=5.3.0"
24
  },
25
+ "suggest": {
26
+ "paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present"
27
+ },
28
  "autoload": {
29
  "psr-4": {
30
  "Firebase\\JWT\\": "src"
vendor/firebase/php-jwt/src/JWK.php CHANGED
@@ -71,7 +71,7 @@ class JWK
71
  *
72
  * @uses createPemFromModulusAndExponent
73
  */
74
- private static function parseKey(array $jwk)
75
  {
76
  if (empty($jwk)) {
77
  throw new InvalidArgumentException('JWK must not be empty');
71
  *
72
  * @uses createPemFromModulusAndExponent
73
  */
74
+ public static function parseKey(array $jwk)
75
  {
76
  if (empty($jwk)) {
77
  throw new InvalidArgumentException('JWK must not be empty');
vendor/firebase/php-jwt/src/JWT.php CHANGED
@@ -2,8 +2,11 @@
2
 
3
  namespace Firebase\JWT;
4
 
 
5
  use DomainException;
 
6
  use InvalidArgumentException;
 
7
  use UnexpectedValueException;
8
  use DateTime;
9
 
@@ -50,17 +53,20 @@ class JWT
50
  'RS256' => array('openssl', 'SHA256'),
51
  'RS384' => array('openssl', 'SHA384'),
52
  'RS512' => array('openssl', 'SHA512'),
 
53
  );
54
 
55
  /**
56
  * Decodes a JWT string into a PHP object.
57
  *
58
  * @param string $jwt The JWT
59
- * @param string|array|resource $key The key, or map of keys.
60
  * If the algorithm used is asymmetric, this is the public key
61
- * @param array $allowed_algs List of supported verification algorithms
62
  * Supported algorithms are 'ES384','ES256', 'HS256', 'HS384',
63
  * 'HS512', 'RS256', 'RS384', and 'RS512'
 
 
64
  *
65
  * @return object The JWT's payload as a PHP object
66
  *
@@ -74,11 +80,11 @@ class JWT
74
  * @uses jsonDecode
75
  * @uses urlsafeB64Decode
76
  */
77
- public static function decode($jwt, $key, array $allowed_algs = array())
78
  {
79
  $timestamp = \is_null(static::$timestamp) ? \time() : static::$timestamp;
80
 
81
- if (empty($key)) {
82
  throw new InvalidArgumentException('Key may not be empty');
83
  }
84
  $tks = \explode('.', $jwt);
@@ -101,27 +107,32 @@ class JWT
101
  if (empty(static::$supported_algs[$header->alg])) {
102
  throw new UnexpectedValueException('Algorithm not supported');
103
  }
104
- if (!\in_array($header->alg, $allowed_algs)) {
105
- throw new UnexpectedValueException('Algorithm not allowed');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  }
107
  if ($header->alg === 'ES256' || $header->alg === 'ES384') {
108
  // OpenSSL expects an ASN.1 DER sequence for ES256/ES384 signatures
109
  $sig = self::signatureToDER($sig);
110
  }
111
 
112
- if (\is_array($key) || $key instanceof \ArrayAccess) {
113
- if (isset($header->kid)) {
114
- if (!isset($key[$header->kid])) {
115
- throw new UnexpectedValueException('"kid" invalid, unable to lookup correct key');
116
- }
117
- $key = $key[$header->kid];
118
- } else {
119
- throw new UnexpectedValueException('"kid" empty, unable to lookup correct key');
120
- }
121
- }
122
-
123
- // Check the signature
124
- if (!static::verify("$headb64.$bodyb64", $sig, $key, $header->alg)) {
125
  throw new SignatureInvalidException('Signature verification failed');
126
  }
127
 
@@ -198,7 +209,7 @@ class JWT
198
  *
199
  * @return string An encrypted message
200
  *
201
- * @throws DomainException Unsupported algorithm was specified
202
  */
203
  public static function sign($msg, $key, $alg = 'HS256')
204
  {
@@ -214,14 +225,24 @@ class JWT
214
  $success = \openssl_sign($msg, $signature, $key, $algorithm);
215
  if (!$success) {
216
  throw new DomainException("OpenSSL unable to sign data");
217
- } else {
218
- if ($alg === 'ES256') {
219
- $signature = self::signatureFromDER($signature, 256);
220
- }
221
- if ($alg === 'ES384') {
222
- $signature = self::signatureFromDER($signature, 384);
223
- }
224
- return $signature;
 
 
 
 
 
 
 
 
 
 
225
  }
226
  }
227
  }
@@ -237,7 +258,7 @@ class JWT
237
  *
238
  * @return bool
239
  *
240
- * @throws DomainException Invalid Algorithm or OpenSSL failure
241
  */
242
  private static function verify($msg, $signature, $key, $alg)
243
  {
@@ -258,21 +279,22 @@ class JWT
258
  throw new DomainException(
259
  'OpenSSL error: ' . \openssl_error_string()
260
  );
 
 
 
 
 
 
 
 
 
 
 
 
261
  case 'hash_hmac':
262
  default:
263
  $hash = \hash_hmac($algorithm, $msg, $key, true);
264
- if (\function_exists('hash_equals')) {
265
- return \hash_equals($signature, $hash);
266
- }
267
- $len = \min(static::safeStrlen($signature), static::safeStrlen($hash));
268
-
269
- $status = 0;
270
- for ($i = 0; $i < $len; $i++) {
271
- $status |= (\ord($signature[$i]) ^ \ord($hash[$i]));
272
- }
273
- $status |= (static::safeStrlen($signature) ^ static::safeStrlen($hash));
274
-
275
- return ($status === 0);
276
  }
277
  }
278
 
@@ -360,6 +382,75 @@ class JWT
360
  return \str_replace('=', '', \strtr(\base64_encode($input), '+/', '-_'));
361
  }
362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
  /**
364
  * Helper method to create a JSON error.
365
  *
2
 
3
  namespace Firebase\JWT;
4
 
5
+ use ArrayAccess;
6
  use DomainException;
7
+ use Exception;
8
  use InvalidArgumentException;
9
+ use OpenSSLAsymmetricKey;
10
  use UnexpectedValueException;
11
  use DateTime;
12
 
53
  'RS256' => array('openssl', 'SHA256'),
54
  'RS384' => array('openssl', 'SHA384'),
55
  'RS512' => array('openssl', 'SHA512'),
56
+ 'EdDSA' => array('sodium_crypto', 'EdDSA'),
57
  );
58
 
59
  /**
60
  * Decodes a JWT string into a PHP object.
61
  *
62
  * @param string $jwt The JWT
63
+ * @param Key|array<Key>|mixed $keyOrKeyArray The Key or array of Key objects.
64
  * If the algorithm used is asymmetric, this is the public key
65
+ * Each Key object contains an algorithm and matching key.
66
  * Supported algorithms are 'ES384','ES256', 'HS256', 'HS384',
67
  * 'HS512', 'RS256', 'RS384', and 'RS512'
68
+ * @param array $allowed_algs [DEPRECATED] List of supported verification algorithms. Only
69
+ * should be used for backwards compatibility.
70
  *
71
  * @return object The JWT's payload as a PHP object
72
  *
80
  * @uses jsonDecode
81
  * @uses urlsafeB64Decode
82
  */
83
+ public static function decode($jwt, $keyOrKeyArray, array $allowed_algs = array())
84
  {
85
  $timestamp = \is_null(static::$timestamp) ? \time() : static::$timestamp;
86
 
87
+ if (empty($keyOrKeyArray)) {
88
  throw new InvalidArgumentException('Key may not be empty');
89
  }
90
  $tks = \explode('.', $jwt);
107
  if (empty(static::$supported_algs[$header->alg])) {
108
  throw new UnexpectedValueException('Algorithm not supported');
109
  }
110
+
111
+ list($keyMaterial, $algorithm) = self::getKeyMaterialAndAlgorithm(
112
+ $keyOrKeyArray,
113
+ empty($header->kid) ? null : $header->kid
114
+ );
115
+
116
+ if (empty($algorithm)) {
117
+ // Use deprecated "allowed_algs" to determine if the algorithm is supported.
118
+ // This opens up the possibility of an attack in some implementations.
119
+ // @see https://github.com/firebase/php-jwt/issues/351
120
+ if (!\in_array($header->alg, $allowed_algs)) {
121
+ throw new UnexpectedValueException('Algorithm not allowed');
122
+ }
123
+ } else {
124
+ // Check the algorithm
125
+ if (!self::constantTimeEquals($algorithm, $header->alg)) {
126
+ // See issue #351
127
+ throw new UnexpectedValueException('Incorrect key for this algorithm');
128
+ }
129
  }
130
  if ($header->alg === 'ES256' || $header->alg === 'ES384') {
131
  // OpenSSL expects an ASN.1 DER sequence for ES256/ES384 signatures
132
  $sig = self::signatureToDER($sig);
133
  }
134
 
135
+ if (!static::verify("$headb64.$bodyb64", $sig, $keyMaterial, $header->alg)) {
 
 
 
 
 
 
 
 
 
 
 
 
136
  throw new SignatureInvalidException('Signature verification failed');
137
  }
138
 
209
  *
210
  * @return string An encrypted message
211
  *
212
+ * @throws DomainException Unsupported algorithm or bad key was specified
213
  */
214
  public static function sign($msg, $key, $alg = 'HS256')
215
  {
225
  $success = \openssl_sign($msg, $signature, $key, $algorithm);
226
  if (!$success) {
227
  throw new DomainException("OpenSSL unable to sign data");
228
+ }
229
+ if ($alg === 'ES256') {
230
+ $signature = self::signatureFromDER($signature, 256);
231
+ } elseif ($alg === 'ES384') {
232
+ $signature = self::signatureFromDER($signature, 384);
233
+ }
234
+ return $signature;
235
+ case 'sodium_crypto':
236
+ if (!function_exists('sodium_crypto_sign_detached')) {
237
+ throw new DomainException('libsodium is not available');
238
+ }
239
+ try {
240
+ // The last non-empty line is used as the key.
241
+ $lines = array_filter(explode("\n", $key));
242
+ $key = base64_decode(end($lines));
243
+ return sodium_crypto_sign_detached($msg, $key);
244
+ } catch (Exception $e) {
245
+ throw new DomainException($e->getMessage(), 0, $e);
246
  }
247
  }
248
  }
258
  *
259
  * @return bool
260
  *
261
+ * @throws DomainException Invalid Algorithm, bad key, or OpenSSL failure
262
  */
263
  private static function verify($msg, $signature, $key, $alg)
264
  {
279
  throw new DomainException(
280
  'OpenSSL error: ' . \openssl_error_string()
281
  );
282
+ case 'sodium_crypto':
283
+ if (!function_exists('sodium_crypto_sign_verify_detached')) {
284
+ throw new DomainException('libsodium is not available');
285
+ }
286
+ try {
287
+ // The last non-empty line is used as the key.
288
+ $lines = array_filter(explode("\n", $key));
289
+ $key = base64_decode(end($lines));
290
+ return sodium_crypto_sign_verify_detached($signature, $msg, $key);
291
+ } catch (Exception $e) {
292
+ throw new DomainException($e->getMessage(), 0, $e);
293
+ }
294
  case 'hash_hmac':
295
  default:
296
  $hash = \hash_hmac($algorithm, $msg, $key, true);
297
+ return self::constantTimeEquals($signature, $hash);
 
 
 
 
 
 
 
 
 
 
 
298
  }
299
  }
300
 
382
  return \str_replace('=', '', \strtr(\base64_encode($input), '+/', '-_'));
383
  }
384
 
385
+
386
+ /**
387
+ * Determine if an algorithm has been provided for each Key
388
+ *
389
+ * @param Key|array<Key>|mixed $keyOrKeyArray
390
+ * @param string|null $kid
391
+ *
392
+ * @throws UnexpectedValueException
393
+ *
394
+ * @return array containing the keyMaterial and algorithm
395
+ */
396
+ private static function getKeyMaterialAndAlgorithm($keyOrKeyArray, $kid = null)
397
+ {
398
+ if (
399
+ is_string($keyOrKeyArray)
400
+ || is_resource($keyOrKeyArray)
401
+ || $keyOrKeyArray instanceof OpenSSLAsymmetricKey
402
+ ) {
403
+ return array($keyOrKeyArray, null);
404
+ }
405
+
406
+ if ($keyOrKeyArray instanceof Key) {
407
+ return array($keyOrKeyArray->getKeyMaterial(), $keyOrKeyArray->getAlgorithm());
408
+ }
409
+
410
+ if (is_array($keyOrKeyArray) || $keyOrKeyArray instanceof ArrayAccess) {
411
+ if (!isset($kid)) {
412
+ throw new UnexpectedValueException('"kid" empty, unable to lookup correct key');
413
+ }
414
+ if (!isset($keyOrKeyArray[$kid])) {
415
+ throw new UnexpectedValueException('"kid" invalid, unable to lookup correct key');
416
+ }
417
+
418
+ $key = $keyOrKeyArray[$kid];
419
+
420
+ if ($key instanceof Key) {
421
+ return array($key->getKeyMaterial(), $key->getAlgorithm());
422
+ }
423
+
424
+ return array($key, null);
425
+ }
426
+
427
+ throw new UnexpectedValueException(
428
+ '$keyOrKeyArray must be a string|resource key, an array of string|resource keys, '
429
+ . 'an instance of Firebase\JWT\Key key or an array of Firebase\JWT\Key keys'
430
+ );
431
+ }
432
+
433
+ /**
434
+ * @param string $left
435
+ * @param string $right
436
+ * @return bool
437
+ */
438
+ public static function constantTimeEquals($left, $right)
439
+ {
440
+ if (\function_exists('hash_equals')) {
441
+ return \hash_equals($left, $right);
442
+ }
443
+ $len = \min(static::safeStrlen($left), static::safeStrlen($right));
444
+
445
+ $status = 0;
446
+ for ($i = 0; $i < $len; $i++) {
447
+ $status |= (\ord($left[$i]) ^ \ord($right[$i]));
448
+ }
449
+ $status |= (static::safeStrlen($left) ^ static::safeStrlen($right));
450
+
451
+ return ($status === 0);
452
+ }
453
+
454
  /**
455
  * Helper method to create a JSON error.
456
  *
vendor/firebase/php-jwt/src/Key.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Firebase\JWT;
4
+
5
+ use InvalidArgumentException;
6
+ use OpenSSLAsymmetricKey;
7
+
8
+ class Key
9
+ {
10
+ /** @var string $algorithm */
11
+ private $algorithm;
12
+
13
+ /** @var string|resource|OpenSSLAsymmetricKey $keyMaterial */
14
+ private $keyMaterial;
15
+
16
+ /**
17
+ * @param string|resource|OpenSSLAsymmetricKey $keyMaterial
18
+ * @param string $algorithm
19
+ */
20
+ public function __construct($keyMaterial, $algorithm)
21
+ {
22
+ if (
23
+ !is_string($keyMaterial)
24
+ && !is_resource($keyMaterial)
25
+ && !$keyMaterial instanceof OpenSSLAsymmetricKey
26
+ ) {
27
+ throw new InvalidArgumentException('Type error: $keyMaterial must be a string, resource, or OpenSSLAsymmetricKey');
28
+ }
29
+
30
+ if (empty($keyMaterial)) {
31
+ throw new InvalidArgumentException('Type error: $keyMaterial must not be empty');
32
+ }
33
+
34
+ if (!is_string($algorithm)|| empty($keyMaterial)) {
35
+ throw new InvalidArgumentException('Type error: $algorithm must be a string');
36
+ }
37
+
38
+ $this->keyMaterial = $keyMaterial;
39
+ $this->algorithm = $algorithm;
40
+ }
41
+
42
+ /**
43
+ * Return the algorithm valid for this key
44
+ *
45
+ * @return string
46
+ */
47
+ public function getAlgorithm()
48
+ {
49
+ return $this->algorithm;
50
+ }
51
+
52
+ /**
53
+ * @return string|resource|OpenSSLAsymmetricKey
54
+ */
55
+ public function getKeyMaterial()
56
+ {
57
+ return $this->keyMaterial;
58
+ }
59
+ }