| 1 |
<?php |
| 2 |
/** |
| 3 |
* Create Contact to MailMint |
| 4 |
* |
| 5 |
* @since 8.4.10 |
| 6 |
*/ |
| 7 |
class WPVR_Create_Contact { |
| 8 |
|
| 9 |
protected $webHookUrl = [WPVR_WEBHOOK_URL]; |
| 10 |
|
| 11 |
/** |
| 12 |
* Email |
| 13 |
* |
| 14 |
* @var string |
| 15 |
* @since 8.4.10 |
| 16 |
*/ |
| 17 |
protected $email = ''; |
| 18 |
|
| 19 |
/** |
| 20 |
* Name |
| 21 |
* |
| 22 |
* @var string |
| 23 |
* @since 8.4.10 |
| 24 |
*/ |
| 25 |
protected $name = ''; |
| 26 |
|
| 27 |
|
| 28 |
/** |
| 29 |
* Industry |
| 30 |
* |
| 31 |
* @var string |
| 32 |
* @since 8.4.10 |
| 33 |
*/ |
| 34 |
protected $industry = ''; |
| 35 |
|
| 36 |
|
| 37 |
/** |
| 38 |
* Constructor |
| 39 |
* |
| 40 |
* @param string $email |
| 41 |
* @param string $name |
| 42 |
* @since 8.4.10 |
| 43 |
*/ |
| 44 |
public function __construct( $email, $name, $industry ){ |
| 45 |
$this->email = $email; |
| 46 |
$this->name = $name; |
| 47 |
$this->industry = $industry; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
/** |
| 52 |
* Create contact to MailMint via webhook |
| 53 |
* |
| 54 |
* @return array |
| 55 |
* @since 8.4.10 |
| 56 |
*/ |
| 57 |
public function create_contact_via_webhook(){ |
| 58 |
if( !$this->email ){ |
| 59 |
return [ |
| 60 |
'suceess' => false, |
| 61 |
]; |
| 62 |
} |
| 63 |
|
| 64 |
$response = [ |
| 65 |
'suceess' => true, |
| 66 |
]; |
| 67 |
|
| 68 |
$industry_name = !empty( get_option('wpvr_industry_name') ) ? get_option('wpvr_industry_name') : ''; |
| 69 |
$json_body_data = json_encode([ |
| 70 |
'email' => $this->email, |
| 71 |
'first_name' => $this->name, |
| 72 |
'meta_fields' => [ |
| 73 |
'industry' => $this->industry, |
| 74 |
], |
| 75 |
]); |
| 76 |
|
| 77 |
try{ |
| 78 |
if( !empty($this->webHookUrl ) ){ |
| 79 |
foreach( $this->webHookUrl as $url ){ |
| 80 |
$response = wp_remote_request($url, [ |
| 81 |
'method' => 'POST', |
| 82 |
'headers' => [ |
| 83 |
'Content-Type' => 'application/json', |
| 84 |
], |
| 85 |
'body' => $json_body_data |
| 86 |
]); |
| 87 |
} |
| 88 |
} |
| 89 |
}catch(\Exception $e){ |
| 90 |
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
| 91 |
error_log('Error sending contact data to MailMint'); |
| 92 |
} |
| 93 |
$response = [ |
| 94 |
'suceess' => false, |
| 95 |
]; |
| 96 |
} |
| 97 |
|
| 98 |
return $response; |
| 99 |
} |
| 100 |
} |
| 101 |
?> |