| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JFB_Modules\Active_Campaign\Methods; |
| 5 |
|
| 6 |
use Jet_Form_Builder\Actions\Methods\Abstract_Modifier; |
| 7 |
use Jet_Form_Builder\Actions\Methods\Base_Object_Property; |
| 8 |
use Jet_Form_Builder\Exceptions\Action_Exception; |
| 9 |
use Jet_Form_Builder\Exceptions\Gateway_Exception; |
| 10 |
use Jet_Form_Builder\Exceptions\Silence_Exception; |
| 11 |
use JFB_Modules\Active_Campaign\Api\Update_List_Status; |
| 12 |
|
| 13 |
// If this file is called directly, abort. |
| 14 |
if ( ! defined( 'WPINC' ) ) { |
| 15 |
die; |
| 16 |
} |
| 17 |
|
| 18 |
class List_Contact_Property extends Base_Object_Property { |
| 19 |
|
| 20 |
// It can be empty |
| 21 |
// in action we use dynamic fetching properties |
| 22 |
public function get_label(): string { |
| 23 |
return ''; |
| 24 |
} |
| 25 |
|
| 26 |
public function get_id(): string { |
| 27 |
return '#list'; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* @param Abstract_Modifier|Contact_Modifier $modifier |
| 32 |
* |
| 33 |
* @throws Action_Exception |
| 34 |
*/ |
| 35 |
public function do_after( Abstract_Modifier $modifier ) { |
| 36 |
if ( ! is_numeric( $this->value ) ) { |
| 37 |
return; |
| 38 |
} |
| 39 |
/** @var Sync_Contact_Action $action */ |
| 40 |
$action = $modifier->get_action(); |
| 41 |
|
| 42 |
/** @var Update_List_Status $api */ |
| 43 |
$api = ( new Update_List_Status() ) |
| 44 |
->set_token( $modifier->token ) |
| 45 |
->set_base( $modifier->url ); |
| 46 |
|
| 47 |
$api->set_list( (int) $this->value ) |
| 48 |
->set_contact( $action->contact_id ); |
| 49 |
|
| 50 |
try { |
| 51 |
$api->send_request(); |
| 52 |
} catch ( Gateway_Exception $exception ) { |
| 53 |
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 54 |
throw new Action_Exception( 'internal_error', $api->get_request_args() ); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
public function get_value( Abstract_Modifier $modifier ) { |
| 59 |
throw new Silence_Exception(); |
| 60 |
} |
| 61 |
} |
| 62 |
|