add_delayed_payment_support( array( 'option_label' => esc_html__( 'Subscribe contact to Bento only when payment is received.', 'gf-bento-addon' ) ) ); } public function process_feed( $feed, $entry, $form ) { $feedName = $feed['meta']['feed_name']; $tags = $feed['meta']['feed_tags']; $field_map = $this->get_field_map_fields( $feed, 'mapped_fields' ); $merge_vars = array(); foreach ( $field_map as $name => $field_id ) { $merge_vars[ $name ] = $this->get_field_value( $form, $entry, $field_id ); } $email = $merge_vars['email']; $first_name = $merge_vars['first_name']; $last_name = $merge_vars['last_name']; $response = $this->subscribe( '$subscribe', $email, $first_name, $last_name, $tags ); if( $response != 200 ) { $this->add_feed_error( 'Bento subscription failed. Response code ' . $response, $feed, $entry, $form ); } else { $this->add_note( $entry['id'], 'Subscribed to Bento via ' . $feedName ); } } private function subscribe( $event, $email, $first_name, $last_name, $tags ) { $settings = $this->get_plugin_settings(); $site_key = rgar( $settings, 'bento_site_key' ); $pub_key = rgar( $settings, 'bento_pub_key' ); $sec_key = rgar( $settings, 'bento_sec_key' ); $events = array( array( 'email' => $email, 'type' => '$subscribe', 'fields' => array( 'first_name' => $first_name, 'last_name' => $last_name ) ) ); if( $tags ) { $tags = explode( ',', $tags ); foreach( $tags as $tag ) { $events[] = array( 'email' => $email, 'type' => '$tag', 'details' => array( 'tag' => $tag ) ); } } $data = [ 'site_uuid' => $site_key, 'events' => $events ]; $data = apply_filters( 'gf_bento_event_data', $data ); $args = array( 'body' => json_encode( $data ), 'data_format' => 'body', 'timeout' => '5', 'redirection' => '5', 'httpversion' => '1.0', 'blocking' => true, 'headers' => array( 'Authorization' => 'Basic ' . base64_encode( $pub_key . ':' . $sec_key ), 'Content-Type' => 'application/json' ), ); $response = wp_remote_post( $this->_apiurl, $args ); return $response['response']['code']; } public function plugin_settings_fields() { return array( array( 'title' => esc_html__( 'Bento Add-On Settings', 'gf-rejoiner-addon' ), 'fields' => array( array( 'name' => 'bento_site_key', 'tooltip' => esc_html__( 'Site key from Bento control panel', 'gf-bento-addon' ), 'label' => esc_html__( 'Site Key', 'gf-bento-addon' ), 'type' => 'text', 'class' => 'small', ), array( 'name' => 'bento_pub_key', 'tooltip' => esc_html__( 'Publishable key from Bento control panel', 'gf-bento-addon' ), 'label' => esc_html__( 'Publishable Key', 'gf-bento-addon' ), 'type' => 'text', 'class' => 'small', ), array( 'name' => 'bento_sec_key', 'tooltip' => esc_html__( 'Secret key from Bento control panel', 'gf-bento-addon' ), 'label' => esc_html__( 'Secret Key', 'gf-bento-addon' ), 'type' => 'text', 'class' => 'small', ) ), ), ); } public function feed_settings_fields() { return array( array( 'title' => esc_html__( 'Bento Feed Settings', 'gf-bento-addon' ), 'fields' => array( array( 'label' => esc_html__( 'Feed name', 'gf-bento-addon' ), 'type' => 'text', 'name' => 'feed_name', 'tooltip' => esc_html__( 'This is the name of the feed', 'gf-bento-addon' ), 'class' => 'small', ), array( 'label' => esc_html__( 'Tags', 'gf-bento-addon' ), 'type' => 'text', 'name' => 'feed_tags', 'tooltip' => esc_html__( 'Comma separated list of tags for this feed', 'gf-bento-addon' ), ), array( 'name' => 'mapped_fields', 'label' => esc_html__( 'Map Fields', 'gf-bento-addon' ), 'type' => 'field_map', 'field_map' => array( array( 'name' => 'email', 'label' => esc_html__( 'Email', 'gf-bento-addon' ), 'required' => 1, 'field_type' => array( 'email', 'hidden' ), ), array( 'name' => 'first_name', 'label' => esc_html__( 'First Name', 'gf-bento-addon' ), 'required' => 0, ), array( 'name' => 'last_name', 'label' => esc_html__( 'Last Name', 'gf-bento-addon' ), 'required' => 0, ), ), ), array( 'name' => 'condition', 'label' => esc_html__( 'Condition', 'gf-bento-addon' ), 'type' => 'feed_condition', 'checkbox_label' => esc_html__( 'Enable Condition', 'gf-bento-addon' ), 'instructions' => esc_html__( 'Process this feed if', 'gf-bento-addon' ), ), ), ), ); } public function feed_list_columns() { return array( 'feed_name' => esc_html__( 'Name', 'gf-bento-addon' ), 'feed_tags' => esc_html__( 'Tags', 'gf-bento-addon' ) ); } public function can_create_feed() { $settings = $this->get_plugin_settings(); $site_key = rgar( $settings, 'bento_site_key' ); $pub_key = rgar( $settings, 'bento_pub_key' ); $sec_key = rgar( $settings, 'bento_sec_key' ); if( $site_key && $pub_key && $sec_key ) return true; else return false; } }