PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.1
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / admin / modules / setup-wizard / class-wpfnl-create-contact.php

class-wpfnl-create-contact.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.12.1, at admin/modules/setup-wizard/class-wpfnl-create-contact.php

231 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPFunnels\Admin\SetupWizard;
3
4 /**
5 * Create Contact to MailMint and Appsero
6 *
7 * @since 3.3.1
8 */
9 class CreateContact {
10
11 protected $webHookUrl = [
12 'https://useraccount.getwpfunnels.com/?mailmint=1&route=webhook&topic=contact&hash=4ac0c970-adcb-42da-a64d-17620b35baa7',
13 ];
14
15 /**
16 * Email
17 *
18 * @var string
19 * @since 3.3.1
20 */
21 protected $email = '';
22
23 /**
24 * Name
25 *
26 * @var string
27 * @since 3.3.1
28 */
29 protected $name = '';
30
31 /**
32 * Appsero URL
33 *
34 * @var string
35 * @since 3.3.1
36 */
37 protected $appsero_url = 'https://api.appsero.com/';
38
39 /**
40 * API Key
41 *
42 * @var string
43 * @since 3.3.1
44 */
45 protected $appsero_api_key = '6fb1e340-8276-4337-bca6-28a7cd186f06';
46
47
48 /**
49 * Plugin Name
50 *
51 * @var string
52 * @since 3.3.1
53 */
54 protected $plugin_name = WPFNL_NAME;
55
56
57 /**
58 * Plugin Slug
59 *
60 * @var string
61 * @since 3.3.1
62 */
63 protected $plugin_slug = WPFNL_SLUG;
64
65
66 /**
67 * Plugin File
68 *
69 * @var string
70 * @since 3.3.1
71 */
72 protected $plugin_file = WPFNL_FILE;
73
74
75 /**
76 * Source
77 *
78 * @var string
79 * @since 3.3.1
80 */
81 protected $source = 'setup-wizard';
82
83 /**
84 * Constructor
85 *
86 * @param string $email
87 * @param string $name
88 * @since 3.3.1
89 */
90 public function __construct( $email, $name ){
91 $this->email = $email;
92 $this->name = $name;
93 if( 'setup-wizard' == $this->source ){
94 add_filter($this->plugin_slug.'_tracker_data',[$this,'modify_contact_data'], 10);
95 }
96 }
97
98
99 /**
100 * Create contact to MailMint via webhook
101 *
102 * @return array
103 * @since 3.3.1
104 */
105 public function create_contact_via_webhook(){
106
107 if( !$this->email ){
108 return [
109 'suceess' => false,
110 ];
111 }
112
113 $response = [
114 'suceess' => true,
115 ];
116
117 $json_body_data = json_encode([
118 'email' => $this->email,
119 'first_name' => $this->name,
120 ]);
121
122 try{
123 if( !empty($this->webHookUrl ) ){
124 foreach( $this->webHookUrl as $url ){
125 $response = wp_remote_request($url, [
126 'method' => 'POST',
127 'headers' => [
128 'Content-Type' => 'application/json',
129 ],
130 'body' => $json_body_data
131 ]);
132 }
133 }
134 }catch(\Exception $e){
135 $response = [
136 'suceess' => false,
137 ];
138 }
139
140 return $response;
141 }
142
143
144 /**
145 * Send contact to Appsero
146 *
147 * @return void
148 * @since 3.3.1
149 */
150 public function send_contact_to_appsero(){
151 $client = new \Appsero\Client( $this->appsero_api_key, $this->plugin_name, $this->plugin_file );
152 $client->insights()->send_tracking_data(true);
153 update_option( $this->plugin_slug.'_allow_tracking', 'yes');
154 update_option( $this->plugin_slug.'_tracking_notice', ' hide');
155 do_action('wpfunnels_after_accept_consent');
156 }
157
158
159 /**
160 * Modify contact data before sending to appsero
161 *
162 * @param array $data
163 * @return array
164 * @since 3.3.1
165 */
166 public function modify_contact_data($data){
167 $data['admin_email'] = $this->email;
168 $data['first_name'] = $this->name;
169 return $data;
170 }
171
172 public function update_contact_via_webhook($funnel_data) {
173 if( !$this->email ){
174 return false;
175 }
176
177 $json_body_data = json_encode([
178 'email' => $this->email,
179 'wpfunnel_id' => $funnel_data['funnel_id'],
180 'wpfunnel_title' => $funnel_data['funnel_title'],
181 'wpfunnel_status' => $funnel_data['funnel_status'],
182 'wpfunnel_created_at' => $funnel_data['created_date'],
183 ]);
184
185 try{
186 $response = wp_remote_request('https://useraccount.getwpfunnels.com/?mailmint=1&route=webhook&topic=contact&hash=227a9d2a-10e0-47ba-a729-ddbb0c9b87c3', [
187 'method' => 'POST',
188 'headers' => [
189 'Content-Type' => 'application/json',
190 ],
191 'body' => $json_body_data
192 ]);
193 }catch(\Exception $e){
194 $response = [
195 'suceess' => false,
196 ];
197 }
198
199 return $response;
200 }
201
202 public function update_contact_order_via_webhook($order_data) {
203 if( !$this->email ){
204 return false;
205 }
206
207 $json_body_data = json_encode([
208 'email' => $this->email,
209 'wpfunnel_total_orders' => $order_data['total_orders'],
210 'wpfunnel_total_revenue' => $order_data['total_revenue'],
211 'wpfunnel_last_order_date' => $order_data['last_order_date'],
212 ]);
213
214 try{
215 $response = wp_remote_request('https://useraccount.getwpfunnels.com/?mailmint=1&route=webhook&topic=contact&hash=3bdd62ee-05a2-4ab3-9d24-48b6e74b2c06', [
216 'method' => 'POST',
217 'headers' => [
218 'Content-Type' => 'application/json',
219 ],
220 'body' => $json_body_data
221 ]);
222 }catch(\Exception $e){
223 $response = [
224 'suceess' => false,
225 ];
226 }
227
228 return $response;
229 }
230 }
231 ?>