PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.5.2
JetFormBuilder — Dynamic Blocks Form Builder v3.4.5.2
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / actions-v2 / get-response / get-response-action.php
jetformbuilder / modules / actions-v2 / get-response Last commit date
api 1 year ago assets 1 year ago rest-api 1 year ago get-response-action.php 1 year ago get-response-tab-handler.php 1 year ago get-response.php 1 year ago
get-response-action.php
98 lines
1 <?php
2
3 namespace JFB_Modules\Actions_V2\Get_Response;
4
5 use Jet_Form_Builder\Actions\Action_Handler;
6 use Jet_Form_Builder\Actions\Types\Base;
7 use Jet_Form_Builder\Exceptions\Action_Exception;
8 use Jet_Form_Builder\Exceptions\Gateway_Exception;
9 use JFB_Modules\Actions_V2\Get_Response\Api\Action_Factory;
10 use JFB_Modules\Actions_V2\Get_Response\Api\Create_Contact_Action;
11
12 class Get_Response_Action extends Base {
13
14 public $option_name = 'get-response-tab';
15
16 public function get_name() {
17 return __( 'Getresponse', 'jet-form-builder' );
18 }
19
20 public function get_id() {
21 return 'getresponse';
22 }
23
24 /**
25 * Run a hook notification
26 *
27 * @param array $request
28 * @param Action_Handler $handler
29 *
30 * @return void
31 * @throws Action_Exception
32 */
33 public function do_action( array $request, Action_Handler $handler ) {
34 $api = $this->global_settings(
35 array(
36 'api_key' => '',
37 )
38 );
39
40 if ( empty( $api['api_key'] ) || empty( $this->settings['list_id'] ) ) {
41 throw new Action_Exception( 'invalid_api_key' );
42 }
43
44 $factory = new Action_Factory();
45 $factory->set_api_key( $api['api_key'] );
46
47 /** @var Create_Contact_Action $contact */
48 $contact = $factory->create( Create_Contact_Action::class );
49 $contact->set_list_id( $this->settings['list_id'] );
50 $contact->set_email( $this->get_property_value( 'email' ) );
51 $contact->set_name( $this->get_property_value( 'name' ) );
52 $contact->set_day_of_cycle( $this->settings['day_of_cycle'] ?? '' );
53
54 $fields_map = $this->settings['fields_map'] ?? array();
55
56 foreach ( $fields_map as $param => $field ) {
57 if ( ! $field || empty( $request[ $field ] ) ) {
58 continue;
59 }
60 if ( 'name' !== $param && 'email' !== $param ) {
61 $contact->add_custom_field( $param, $request[ $field ] );
62 }
63 }
64
65 try {
66 $contact->request();
67 $contact->check_response_code();
68 } catch ( Gateway_Exception $exception ) {
69 // phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped
70 throw new Action_Exception(
71 'internal_error',
72 $exception->getMessage(),
73 ...$exception->get_additional()
74 );
75 // phpcs:enable WordPress.Security.EscapeOutput.ExceptionNotEscaped
76 }
77 }
78
79 public function editor_labels() {
80 return array(
81 'api_key' => __( 'API Key:', 'jet-form-builder' ),
82 'validate_api_key' => __( 'Validate API Key', 'jet-form-builder' ),
83 'list_id' => __( 'List Id:', 'jet-form-builder' ),
84 'update_list_ids' => __( 'Update List', 'jet-form-builder' ),
85 'day_of_cycle' => __( 'Day Of Cycle:', 'jet-form-builder' ),
86 'fields_map' => __( 'Fields Map:', 'jet-form-builder' ),
87 'use_global' => __( 'Use Global Settings', 'jet-form-builder' ),
88 );
89 }
90
91 private function get_property_value( string $property ) {
92 return jet_fb_context()->get_value(
93 (string) ( $this->settings['fields_map'][ $property ] ?? '' )
94 );
95 }
96
97 }
98