action_name = __( 'Send Data To Zapier', 'wp-marketing-automations-pro' ); $this->action_desc = __( 'This action sends key/ value pair data to the Zapier', 'wp-marketing-automations-pro' ); $this->support_v2 = true; } public static function get_instance() { if ( null === self::$ins ) { self::$ins = new self(); } return self::$ins; } /** * Show the html fields for the current action. */ public function get_view() { $unique_slug = $this->get_slug(); ?> $field_id ) { $custom_fields[ $field_id ] = BWFAN_Common::decode_merge_tags( $fields_value[ $key1 ] ); } $data_to_set['custom_fields'] = $custom_fields; return $data_to_set; } public function make_v2_data( $automation_data, $step_data ) { $data_to_set = array(); $data_to_set['email'] = $automation_data['global']['email']; $data_to_set['url'] = BWFAN_Common::decode_merge_tags( $step_data['url'] ); $fields = $step_data['custom_fields']; $custom_fields = array(); foreach ( $fields as $field ) { $custom_fields[ $field['field'] ] = BWFAN_Common::decode_merge_tags( $field['field_value'] ); } $data_to_set['custom_fields'] = $custom_fields; return $data_to_set; } /** * Execute the current action. * Return 3 for successful execution , 4 for permanent failure. * * @param $action_data * * @return array */ public function execute_action( $action_data ) { $this->set_data( $action_data['processed_data'] ); $result = $this->process(); $int_obj = BWFAN_Core()->integration->get_integration( 'zapier' ); $result = $int_obj->handle_response( $result, $this->connector, $this->call ); return $result; } /** * Process and do the actual processing for the current action. * This function is present in every action class. */ public function process() { $is_required_fields_present = $this->check_fields( $this->data, $this->required_fields ); if ( false === $is_required_fields_present ) { return $this->show_fields_error(); } $endpoint_url = $this->data['url']; $params_data = $this->data['custom_fields']; $result = $this->make_wp_requests( $endpoint_url, $params_data, array(), BWF_CO::$POST ); return $result; } public function process_v2() { $endpoint_url = $this->data['url']; $params_data = $this->data['custom_fields']; $this->make_wp_requests( $endpoint_url, $params_data, array(), BWF_CO::$POST ); return $this->success_message( __( 'Data sent successfully.', 'wp-marketing-automations-pro' ) ); } public function get_fields_schema() { return [ [ 'id' => 'url', 'type' => 'textarea', 'label' => __( 'Enter URL', 'wp-marketing-automations-pro' ), 'placeholder' => __( 'Webhook URL', 'wp-marketing-automations-pro' ), 'tip' => __( "Enter a URL where data will be sent.", 'wp-marketing-automations-pro' ), "description" => "", "required" => true, ], [ 'id' => 'custom_fields', 'type' => 'repeater', 'label' => __( 'Data', 'wp-marketing-automations-pro' ), "fields" => [ [ 'id' => 'field', 'label' => "", 'type' => 'text', 'placeholder' => __( 'Key', 'wp-marketing-automations-pro' ), "class" => 'bwfan-input-wrapper', 'tip' => "", "description" => "", "required" => false, ], [ "id" => 'field_value', "label" => "", "type" => 'text', 'placeholder' => __( 'Value', 'wp-marketing-automations-pro' ), "class" => 'bwfan-input-wrapper', "description" => "", "required" => false, ] ] ], [ 'id' => 'send_test_data', 'type' => 'send_data', 'label' => __( 'Send test data via Zapier', 'wp-marketing-automations-pro' ), 'send_action' => 'bwf_test_zap', 'send_field' => [ 'url' => 'url', 'http_method' => 'http_method', 'headers' => 'headers', 'custom_fields' => 'custom_fields', ], "hint" => __( "This will POST the key value pairs with dummy data to Zapier Webhook URL", 'wp-marketing-automations-pro' ) ], ]; } } return 'BWFAN_ZA_Send_Data';