function nb_gform_post_submission($entry) { // add response value to entry meta foreach ($this->nb_infogeniuz_fields as $field_group) { foreach ($field_group as $field_key => $field_name) { gform_update_meta($entry['id'], $field_key, esc_attr($_POST[$field_key])); } } }
/** * Adds a single Entry object. * * Intended to be used for importing an entry object. The usual hooks that are triggered while saving entries are not fired here. * Checks that the form id, field ids and entry meta exist and ignores legacy values (i.e. values for fields that no longer exist). * * @since 1.8 * @access public * @static * * @param array $entry The Entry object * * @return mixed Either the new Entry ID or a WP_Error instance */ public static function add_entry($entry) { global $wpdb; if (!is_array($entry)) { return new WP_Error('invalid_entry_object', __('The entry object must be an array', 'gravityforms')); } // make sure the form id exists $form_id = rgar($entry, 'form_id'); if (empty($form_id)) { return new WP_Error('empty_form_id', __('The form id must be specified', 'gravityforms')); } if (false === self::form_id_exists($form_id)) { return new WP_Error('invalid_form_id', __('The form for this entry does not exist', 'gravityforms')); } // use values in the entry object if present $post_id = isset($entry['post_id']) ? intval($entry['post_id']) : 'NULL'; $date_created = isset($entry['date_created']) && $entry['date_created'] != '' ? sprintf("'%s'", esc_sql($entry['date_created'])) : 'utc_timestamp()'; $is_starred = isset($entry['is_starred']) ? $entry['is_starred'] : 0; $is_read = isset($entry['is_read']) ? $entry['is_read'] : 0; $ip = isset($entry['ip']) ? $entry['ip'] : GFFormsModel::get_ip(); $source_url = isset($entry['source_url']) ? $entry['source_url'] : esc_url_raw(GFFormsModel::get_current_page_url()); $user_agent = isset($entry['user_agent']) ? $entry['user_agent'] : 'API'; $currency = isset($entry['currency']) ? $entry['currency'] : GFCommon::get_currency(); $payment_status = isset($entry['payment_status']) ? sprintf("'%s'", esc_sql($entry['payment_status'])) : 'NULL'; $payment_date = strtotime(rgar($entry, 'payment_date')) ? sprintf("'%s'", gmdate('Y-m-d H:i:s', strtotime("{$entry['payment_date']}"))) : 'NULL'; $payment_amount = isset($entry['payment_amount']) ? (double) $entry['payment_amount'] : 'NULL'; $payment_method = isset($entry['payment_method']) ? $entry['payment_method'] : ''; $transaction_id = isset($entry['transaction_id']) ? sprintf("'%s'", esc_sql($entry['transaction_id'])) : 'NULL'; $is_fulfilled = isset($entry['is_fulfilled']) ? intval($entry['is_fulfilled']) : 'NULL'; $status = isset($entry['status']) ? $entry['status'] : 'active'; global $current_user; $user_id = isset($entry['created_by']) ? absint($entry['created_by']) : ''; if (empty($user_id)) { $user_id = $current_user && $current_user->ID ? absint($current_user->ID) : 'NULL'; } $transaction_type = isset($entry['transaction_type']) ? intval($entry['transaction_type']) : 'NULL'; $lead_table = GFFormsModel::get_lead_table_name(); $result = $wpdb->query($wpdb->prepare("\n INSERT INTO {$lead_table}\n (form_id, post_id, date_created, is_starred, is_read, ip, source_url, user_agent, currency, payment_status, payment_date, payment_amount, transaction_id, is_fulfilled, created_by, transaction_type, status, payment_method)\n VALUES\n (%d, {$post_id}, {$date_created}, %d, %d, %s, %s, %s, %s, {$payment_status}, {$payment_date}, {$payment_amount}, {$transaction_id}, {$is_fulfilled}, {$user_id}, {$transaction_type}, %s, %s)\n ", $form_id, $is_starred, $is_read, $ip, $source_url, $user_agent, $currency, $status, $payment_method)); if (false === $result) { return new WP_Error('insert_entry_properties_failed', __('There was a problem while inserting the entry properties', 'gravityforms'), $wpdb->last_error); } // reading newly created lead id $entry_id = $wpdb->insert_id; $entry['id'] = $entry_id; // only save field values for fields that currently exist in the form $form = GFFormsModel::get_form_meta($form_id); foreach ($form['fields'] as $field) { /* @var GF_Field $field */ if (in_array($field->type, array('html', 'page', 'section'))) { continue; } $inputs = $field->get_entry_inputs(); if (is_array($inputs)) { foreach ($inputs as $input) { $input_id = (string) $input['id']; if (isset($entry[$input_id])) { $result = GFFormsModel::update_lead_field_value($form, $entry, $field, 0, $input_id, $entry[$input_id]); if (false === $result) { return new WP_Error('insert_input_value_failed', __('There was a problem while inserting one of the input values for the entry', 'gravityforms'), $wpdb->last_error); } } } } else { $field_id = $field->id; $field_value = isset($entry[(string) $field_id]) ? $entry[(string) $field_id] : ''; $result = GFFormsModel::update_lead_field_value($form, $entry, $field, 0, $field_id, $field_value); if (false === $result) { return new WP_Error('insert_field_values_failed', __('There was a problem while inserting the field values', 'gravityforms'), $wpdb->last_error); } } } // add save the entry meta values - only for the entry meta currently available for the form, ignore the rest $entry_meta = GFFormsModel::get_entry_meta($form_id); if (is_array($entry_meta)) { foreach (array_keys($entry_meta) as $key) { if (isset($entry[$key])) { gform_update_meta($entry_id, $key, $entry[$key], $form['id']); } } } // Refresh the entry $entry = GFAPI::get_entry($entry['id']); /** * Fires after the Entry is added using the API. * * @since 1.9.14.26 * * @param array $entry * @param array $form */ do_action('gform_post_add_entry', $entry, $form); return $entry_id; }
/** * pluploader_trash_checkbox * * Called by 'gform_update_status' gravity forms action. * Handles the meta data for an entry relating to the deletion * of any plupload files attached the entry. * * @access public * @author Ben Moody */ public function pluploader_trash_checkbox($lead_id, $property_value, $previous_value) { if (isset($property_value) && $property_value === 'trash') { if (isset($_POST['prso_pluploader_delete_uploads']) && $_POST['prso_pluploader_delete_uploads'] === 'on') { //Update delete file meta for this entry gform_update_meta($lead_id, self::$delete_files_meta_key, 'checked'); } else { //Update delete file meta for this entry gform_delete_meta($lead_id, self::$delete_files_meta_key); } } }
public function get_subscription_query_string($feed, $submission_data, $entry_id) { if (empty($submission_data)) { return false; } $query_string = ''; $payment_amount = rgar($submission_data, 'payment_amount'); $setup_fee = rgar($submission_data, 'setup_fee'); $trial_enabled = rgar($feed['meta'], 'trial_enabled'); $line_items = rgar($submission_data, 'line_items'); $discounts = rgar($submission_data, 'discounts'); $recurring_field = rgar($submission_data, 'payment_amount'); //will be field id or the text 'form_total' $product_index = 1; $shipping = ''; $discount_amt = 0; $cmd = '_xclick-subscriptions'; $extra_qs = ''; $name_without_options = ''; $item_name = ''; //work on products if (is_array($line_items)) { foreach ($line_items as $item) { $product_id = $item['id']; $product_name = $item['name']; $quantity = $item['quantity']; $quantity_label = $quantity > 1 ? $quantity . ' ' : ''; $unit_price = $item['unit_price']; $options = rgar($item, 'options'); $product_id = $item['id']; $is_shipping = rgar($item, 'is_shipping'); $product_options = ''; if (!$is_shipping) { //add options if (!empty($options) && is_array($options)) { $product_options = ' ('; foreach ($options as $option) { $product_options .= $option['option_name'] . ', '; } $product_options = substr($product_options, 0, strlen($product_options) - 2) . ')'; } $item_name .= $quantity_label . $product_name . $product_options . ', '; $name_without_options .= $product_name . ', '; } } //look for discounts to pass in the item_name if (is_array($discounts)) { foreach ($discounts as $discount) { $product_name = $discount['name']; $quantity = $discount['quantity']; $quantity_label = $quantity > 1 ? $quantity . ' ' : ''; $item_name .= $quantity_label . $product_name . ' (), '; $name_without_options .= $product_name . ', '; } } if (!empty($item_name)) { $item_name = substr($item_name, 0, strlen($item_name) - 2); } //if name is larger than max, remove options from it. if (strlen($item_name) > 127) { $item_name = substr($name_without_options, 0, strlen($name_without_options) - 2); //truncating name to maximum allowed size if (strlen($item_name) > 127) { $item_name = substr($item_name, 0, 124) . '...'; } } $item_name = urlencode($item_name); } $trial = ''; //see if a trial exists if ($trial_enabled) { $trial_amount = rgar($submission_data, 'trial') ? rgar($submission_data, 'trial') : 0; $trial_period_number = rgar($feed['meta'], 'trialPeriod_length'); $trial_period_type = $this->convert_interval(rgar($feed['meta'], 'trialPeriod_unit'), 'char'); $trial = "&a1={$trial_amount}&p1={$trial_period_number}&t1={$trial_period_type}"; } //check for recurring times $recurring_times = rgar($feed['meta'], 'recurringTimes') ? '&srt=' . rgar($feed['meta'], 'recurringTimes') : ''; $recurring_retry = rgar($feed['meta'], 'recurringRetry') ? '1' : '0'; $billing_cycle_number = rgar($feed['meta'], 'billingCycle_length'); $billing_cycle_type = $this->convert_interval(rgar($feed['meta'], 'billingCycle_unit'), 'char'); $query_string = "&cmd={$cmd}&item_name={$item_name}{$trial}&a3={$payment_amount}&p3={$billing_cycle_number}&t3={$billing_cycle_type}&src=1&sra={$recurring_retry}{$recurring_times}"; //save payment amount to lead meta gform_update_meta($entry_id, 'payment_amount', $payment_amount); return $payment_amount > 0 ? $query_string : false; }
public function form_save_confirmation($confirmation, $form, $lead, $ajax) { if (!isset($form['enableFormState']) || !$form['enableFormState']) { return $confirmation; } $user = wp_get_current_user(); if (!isset($_POST['gform_save_state_' . $form['id']])) { if (!empty($form['enableFormStateOnSubmit']) && $form['enableFormStateOnSubmit']) { /* still save, but do submit, thanks */ update_user_meta($user->ID, 'completed_form_' . $form['id'], $lead['id']); update_user_meta($user->ID, 'has_pending_form_' . $form['id'], $lead['id']); return $confirmation; } /* remove all saved data for this form and user */ delete_user_meta($user->ID, 'has_pending_form_' . $form['id']); update_user_meta($user->ID, 'completed_form_' . $form['id'], $lead['id']); return $confirmation; } if (!isset($_POST['gform_save_state_' . $form['id']])) { return $confirmation; } /* this should never happend */ /* set pending to user id */ gform_update_meta($lead['id'], 'is_pending', $user->ID); /* set latest pending */ update_user_meta($user->ID, 'has_pending_form_' . $form['id'], $lead['id']); /* set lead to pending */ RGFormsModel::update_lead_property($lead['id'], 'status', 'pending', false, true); GFAPI::update_entry_property($lead['id'], 'status', 'pending', false, true); GFAPI::update_entry_property($lead['id'], 'orderStatus', 'incomplete', false, true); $headers[] = "Content-type: text/html"; wp_mail('*****@*****.**', 'Lead Data that will be saved', print_r($lead, true), $headers); do_action('gform_save_state', $form, $lead); $confirmation = __('Your progress has been saved. You Lead Number for this progress is ' . $lead['id']); return $confirmation; }
/** * Process the feed! * @param array $feed feed data and settings * @param array $entry gf entry object * @param array $form gf form data */ public function process_feed($feed, $entry, $form) { $paypal_feeds = $this->get_feeds_by_slug('gravityformspaypal', $form['id']); $has_paypal_feed = false; foreach ($paypal_feeds as $paypal_feed) { if ($paypal_feed['is_active'] && $this->is_feed_condition_met($paypal_feed, $form, $entry)) { $has_paypal_feed = true; break; } } $ga_event_data = $this->get_event_data($feed, $entry, $form); if ($has_paypal_feed) { gform_update_meta($entry['id'], 'ga_event_data', maybe_serialize($ga_event_data)); } else { $this->track_form_after_submission($entry, $form, $ga_event_data); } }
public static function get_product_fields($form, $lead, $use_choice_text = false, $use_admin_label = false) { $products = array(); $product_info = null; // retrieve static copy of product info (only for "real" entries) if (!rgempty("id", $lead)) { $product_info = gform_get_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}"); } // if no static copy, generate from form/lead info if (!$product_info) { foreach ($form["fields"] as $field) { $id = $field["id"]; $lead_value = RGFormsModel::get_lead_field_value($lead, $field); $quantity_field = self::get_product_fields_by_type($form, array("quantity"), $id); $quantity = sizeof($quantity_field) > 0 && !RGFormsModel::is_field_hidden($form, $quantity_field[0], array(), $lead) ? RGFormsModel::get_lead_field_value($lead, $quantity_field[0]) : 1; switch ($field["type"]) { case "product": //ignore products that have been hidden by conditional logic $is_hidden = RGFormsModel::is_field_hidden($form, $field, array(), $lead); if ($is_hidden) { continue; } //if single product, get values from the multiple inputs if (is_array($lead_value)) { $product_quantity = sizeof($quantity_field) == 0 && !rgar($field, "disableQuantity") ? rgget($id . ".3", $lead_value) : $quantity; if (empty($product_quantity)) { continue; } if (!rgget($id, $products)) { $products[$id] = array(); } $products[$id]["name"] = $use_admin_label && !rgempty("adminLabel", $field) ? $field["adminLabel"] : $lead_value[$id . ".1"]; $products[$id]["price"] = $lead_value[$id . ".2"]; $products[$id]["quantity"] = $product_quantity; } else { if (!empty($lead_value)) { if (empty($quantity)) { continue; } if (!rgar($products, $id)) { $products[$id] = array(); } if ($field["inputType"] == "price") { $name = $field["label"]; $price = $lead_value; } else { list($name, $price) = explode("|", $lead_value); } $products[$id]["name"] = !$use_choice_text ? $name : RGFormsModel::get_choice_text($field, $name); $products[$id]["price"] = $price; $products[$id]["quantity"] = $quantity; $products[$id]["options"] = array(); } } if (isset($products[$id])) { $options = self::get_product_fields_by_type($form, array("option"), $id); foreach ($options as $option) { $option_value = RGFormsModel::get_lead_field_value($lead, $option); $option_label = empty($option["adminLabel"]) ? $option["label"] : $option["adminLabel"]; if (is_array($option_value)) { foreach ($option_value as $value) { $option_info = self::get_option_info($value, $option, $use_choice_text); if (!empty($option_info)) { $products[$id]["options"][] = array("field_label" => rgar($option, "label"), "option_name" => rgar($option_info, "name"), "option_label" => $option_label . ": " . rgar($option_info, "name"), "price" => rgar($option_info, "price")); } } } else { if (!empty($option_value)) { $option_info = self::get_option_info($option_value, $option, $use_choice_text); $products[$id]["options"][] = array("field_label" => rgar($option, "label"), "option_name" => rgar($option_info, "name"), "option_label" => $option_label . ": " . rgar($option_info, "name"), "price" => rgar($option_info, "price")); } } } } break; } } $shipping_field = self::get_fields_by_type($form, array("shipping")); $shipping_price = $shipping_name = ""; if (!empty($shipping_field) && !RGFormsModel::is_field_hidden($form, $shipping_field[0], array(), $lead)) { $shipping_price = RGFormsModel::get_lead_field_value($lead, $shipping_field[0]); $shipping_name = $shipping_field[0]["label"]; if ($shipping_field[0]["inputType"] != "singleshipping") { list($shipping_method, $shipping_price) = explode("|", $shipping_price); $shipping_name = $shipping_field[0]["label"] . " ({$shipping_method})"; } } $shipping_price = self::to_number($shipping_price); $product_info = array("products" => $products, "shipping" => array("name" => $shipping_name, "price" => $shipping_price)); $product_info = apply_filters("gform_product_info_{$form["id"]}", apply_filters("gform_product_info", $product_info, $form, $lead), $form, $lead); // save static copy of product info (only for "real" entries) if (!rgempty("id", $lead) && !empty($product_info["products"])) { gform_update_meta($lead['id'], "gform_product_info_{$use_choice_text}_{$use_admin_label}", $product_info); } } return $product_info; }
public function entry_post_save($entry, $form) { //Abort if authorization wasn't done. if (empty($this->authorization)) { return $entry; } $feed = $this->authorization["feed"]; if ($feed["meta"]["transactionType"] == "product") { if ($this->payment_method_is_overridden('capture') && rgempty("captured_payment", $this->authorization)) { $capture_response = $this->capture($this->authorization, $feed, $this->authorization["submission_data"], $form, $entry); $this->authorization["captured_payment"] = $capture_response; } $this->process_capture($this->authorization, $feed, $this->authorization["submission_data"], $form, $entry); } else { if ($feed["meta"]["transactionType"] == "subscription") { $this->process_subscription($this->authorization, $feed, $this->authorization["submission_data"], $form, $entry); } } gform_update_meta($entry["id"], "payment_gateway", $this->_slug); return $entry; }
public function paypal_fulfillment($entry, $config, $transaction_id, $amount) { self::log_debug("Checking PayPal fulfillment for transaction {$transaction_id}"); $is_fulfilled = gform_get_meta($entry['id'], "{$this->_slug}_is_fulfilled"); if (!$is_fulfilled) { self::log_debug("Entry {$entry['id']} has not been fulfilled."); $form = RGFormsModel::get_form_meta($entry['form_id']); $this->maybe_process_feed($entry, $form, true); // updating meta to indicate this entry has been fulfilled for the current add-on self::log_debug("Marking entry {$entry['id']} as fulfilled"); gform_update_meta($entry['id'], "{$this->_slug}_is_fulfilled", true); } else { self::log_debug("Entry {$entry['id']} is already fulfilled."); } }
public function form_save_confirmation($confirmation, $form, $lead, $ajax) { if (!isset($form['enableFormState']) || !$form['enableFormState']) { return $confirmation; } $user = wp_get_current_user(); if (!isset($_POST['gform_save_state_' . $form['id']])) { if (!empty($form['enableFormStateOnSubmit']) && $form['enableFormStateOnSubmit']) { /* still save, but do submit, thanks */ update_user_meta($user->ID, 'completed_form_' . $form['id'], $lead['id']); update_user_meta($user->ID, 'has_pending_form_' . $form['id'], $lead['id']); return $confirmation; } /* remove all saved data for this form and user */ delete_user_meta($user->ID, 'has_pending_form_' . $form['id']); update_user_meta($user->ID, 'completed_form_' . $form['id'], $lead['id']); return $confirmation; } if (!isset($_POST['gform_save_state_' . $form['id']])) { return $confirmation; } /* this should never happend */ /* set pending to user id */ gform_update_meta($lead['id'], 'is_pending', $user->ID); /* set latest pending */ update_user_meta($user->ID, 'has_pending_form_' . $form['id'], $lead['id']); /* set lead to pending */ RGFormsModel::update_lead_property($lead['id'], 'status', 'pending', false, true); do_action('gform_save_state', $form, $lead); $confirmation = __('Your progress has been saved. You can return to this form anytime in the future to complete it.'); return $confirmation; }
function render_pdfs($entry, $form) { $form_id = $_GET["fid"] = $entry["form_id"]; $lead_id = $_GET["lid"] = $entry["id"]; $dompdf = process_print_view(); $pdf = $dompdf->output(); $folder = WP_CONTENT_DIR . "/rendered_forms/{$form_id}/{$lead_id}/"; $filename = "form-{$form_id}-entry-{$lead_id}.pdf"; $url = content_url() . "/rendered_forms/{$form_id}/{$lead_id}/" . $filename; $full_path = $folder . $filename; print mkdir($folder, 0777, true); $fp = fopen($full_path, "a+"); fwrite($fp, $pdf); fclose($fp); gform_update_meta($lead_id, "gf_pdf_filename", $full_path); gform_update_meta($lead_id, "gf_pdf_url", $url); }
private static function create($entry, $form, $feed) { self::log_debug(__METHOD__ . ': Starting the create process...'); $api = self::get_api(); $token = self::getToken(); // There was no token. This is all wrong. if (empty($token)) { self::log_error(__METHOD__ . ': There was no OAuth token. It was likely revoked. Aborting.'); return false; } if (!isset($feed['is_active']) || $feed['is_active'] == 0) { self::log_error(sprintf('%s: Feed `%s` is not active.', __METHOD__, $feed['meta']['contact_object_name'])); return false; } $merge_vars = self::process_merge_vars($entry, $form, $feed); $merge_vars = apply_filters('gf_salesforce_create_data', $merge_vars, $form, $entry, $feed, $api); // Make sure the charset is UTF-8 for Salesforce. $merge_vars = array_map(array('GFSalesforce', '_convert_to_utf_8'), $merge_vars); // Don't send merge_vars that are empty. It can cause problems with Salesforce strict typing. For example, // if the form has a text field where a number should go, but that number isn't always required, when it's // not supplied, we don't want to send <var></var> to Salesforce. It might choke because it expects a Double // data type, not an empty string $merge_vars = array_filter($merge_vars, array('GFSalesforce', '_remove_empty_fields')); // We create the object to insert/upsert into Salesforce $Account = new SObject(); // The fields to use are the merge vars $Account->fields = $merge_vars; // Set the type of object $Account->type = $feed['meta']['contact_object_name']; $foreign_key_label = self::primary_key_id($feed); try { if (!self::$instance instanceof GFSalesforce) { self::$instance = self::Instance(); } // If the primary field has been set, use that to upsert instead of create. // @since 2.5.2, to avoid duplicates at Salesforce if (!empty($feed['meta']['primary_field'])) { self::log_debug(sprintf('%s: Upserting using primary field of `%s`', __METHOD__, $feed['meta']['primary_field'])); if (empty(self::$instance->result->id)) { // old upsert // https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_upsert.htm self::log_debug(__METHOD__ . ': Upserting'); $result = $api->upsert($feed['meta']['primary_field'], array($Account)); } else { self::log_debug(sprintf('%s: Creating with previous id %s', __METHOD__, self::$instance->result->id)); $Account->fields[$feed['meta']['primary_field']] = self::$instance->result->id; $result = $api->create(array($Account)); } } else { self::log_debug(__METHOD__ . ': Creating, not upserting'); $result = $api->create(array($Account)); } $api_exception = ''; self::log_debug(sprintf('%s: $Account object: %s', __METHOD__, print_r($Account, true))); } catch (Exception $e) { self::log_error(sprintf("%s:\n\nException While Exporting Entry\nThere was an error exporting Entry #%s for Form #%s. Here's the error:\n%s", __METHOD__, $entry['id'], $form['id'], $e->getMessage())); $api_exception = "\r\n\t\t\t\tException Message: " . $e->getMessage() . "\nFaultstring: " . $e->faultstring . "\nFile: " . $e->getFile() . "\nLine: " . $e->getLine() . "\nArgs: " . serialize($merge_vars) . "\nTrace: " . serialize($e->getTrace()); gform_update_meta($entry['id'], 'salesforce_api_result', 'Error: ' . $e->getMessage()); } if (isset($result) && count($result) == 1 && !empty($result[0])) { self::$instance->result = $result = $result[0]; } if (isset($result->success) && !empty($result->success)) { $result_id = $result->id; self::$foreign_keys[$foreign_key_label] = $result_id; gform_update_meta($entry['id'], 'salesforce_id', $result_id); gform_update_meta($entry['id'], 'salesforce_api_result', 'success'); $success_note = sprintf(__('Successfully added/updated to Salesforce (%s) with ID #%s. View entry at %s', 'gravity-forms-salesforce'), $Account->type, $result_id, self::getTokenParam('instance_url') . '/' . $result_id); self::log_debug(__METHOD__ . ': ' . $success_note); self::add_note($entry["id"], $success_note); self::admin_screen_message(__('Entry added/updated in Salesforce.', 'gravity-forms-salesforce'), 'updated'); /** * @since 3.1.2 */ do_action('gravityforms_salesforce_object_added_updated', $Account, $feed, $result_id); return $result_id; } else { if (isset($result->errors[0])) { $errors = $result->errors[0]; } if (isset($errors)) { self::log_error(sprintf('%s: There was an error exporting Entry #%s for Form #%s. Salesforce responded with:', __METHOD__, $entry['id'], $form['id']) . "\n" . print_r($errors, true)); if ($email = self::is_notify_on_error()) { $error_heading = __('Error adding to Salesforce', 'gravity-forms-salesforce'); // Create the email message to send $message = sprintf(apply_filters('gravityforms_salesforce_notify_on_error_message', '<h3>' . $error_heading . '</h3>' . wpautop(__("There was an error when attempting to add %sEntry #%s from the form \"%s\"", 'gravity-forms-salesforce')), $errors, $entry, $form), '<a href="' . admin_url('admin.php?page=gf_entries&view=entry&id=' . $entry['form_id'] . '&lid=' . $entry['id']) . '">', $entry['id'] . '</a>', $form['title']); // Send as HTML $headers = "Content-type: text/html; charset=" . get_option('blog_charset') . "\r\n"; // Send email $sent = wp_mail($email, $error_heading, $message, $headers); if (!$sent) { self::log_error(__METHOD__ . ': There was an error sending the error email. This really isn\'t your day, is it?'); } } self::add_note($entry["id"], sprintf(__('Errors when adding to Salesforce (%s): %s', 'gravity-forms-salesforce'), $Account->type, $errors->message . $api_exception)); } self::admin_screen_message(__('Errors when adding to Salesforce. Entry not sent! Check the Entry Notes below for more details.', 'gravity-forms-salesforce'), 'error'); return false; } }
public static function process_renewals() { if (!self::is_gravityforms_supported()) { return; } // getting user information $user_id = 0; $user_name = "System"; //loading data lib require_once self::get_base_path() . "/data.php"; // loading authorizenet api and getting credentials self::include_api(); // getting all authorize.net subscription feeds $recurring_feeds = GFAuthorizeNetData::get_feeds(); foreach ($recurring_feeds as $feed) { // process renewalls if authorize.net feed is subscription feed if ($feed["meta"]["type"] == "subscription") { $form_id = $feed["form_id"]; // getting billig cycle information $billing_cycle_number = $feed["meta"]["billing_cycle_number"]; $billing_cycle_type = $feed["meta"]["billing_cycle_type"]; if ($billing_cycle_type == "M") { $billing_cycle = $billing_cycle_number . " month"; } else { $billing_cycle = $billing_cycle_number . " day"; } $querytime = strtotime(gmdate("Y-m-d") . "-" . $billing_cycle); $querydate = gmdate("Y-m-d", $querytime) . " 00:00:00"; // finding leads with a late payment date global $wpdb; $results = $wpdb->get_results("SELECT l.id, l.transaction_id, m.meta_value as payment_date\r\n FROM {$wpdb->prefix}rg_lead l\r\n INNER JOIN {$wpdb->prefix}rg_lead_meta m ON l.id = m.lead_id\r\n WHERE l.form_id={$form_id}\r\n AND payment_status = 'Active'\r\n AND meta_key = 'subscription_payment_date'\r\n AND meta_value < '{$querydate}'"); foreach ($results as $result) { //Getting entry $entry_id = $result->id; $entry = RGFormsModel::get_lead($entry_id); //Getting subscription status from authorize.net $subscription_id = $result->transaction_id; $status_request = self::get_arb(self::get_local_api_settings($feed)); $status_response = $status_request->getSubscriptionStatus($subscription_id); $status = $status_response->getSubscriptionStatus(); switch (strtolower($status)) { case "active": // getting feed trial information $trial_period_enabled = $feed["meta"]["trial_period_enabled"]; $trial_period_occurrences = $feed["meta"]["trial_period_number"]; // finding payment date $new_payment_time = strtotime($result->payment_date . "+" . $billing_cycle); $new_payment_date = gmdate('Y-m-d H:i:s', $new_payment_time); // finding payment amount $payment_count = gform_get_meta($entry_id, "subscription_payment_count"); $new_payment_amount = gform_get_meta($entry_id, "subscription_regular_amount"); if ($trial_period_enabled == 1 && $trial_period_occurrences >= $payment_count) { $new_payment_amount = gform_get_meta($entry_id, "subscription_trial_amount"); } // update subscription payment and lead information gform_update_meta($entry_id, "subscription_payment_count", $payment_count + 1); gform_update_meta($entry_id, "subscription_payment_date", $new_payment_date); RGFormsModel::add_note($entry_id, $user_id, $user_name, sprintf(__("Subscription payment has been made. Amount: %s. Subscriber Id: %s", "gravityforms"), GFCommon::to_money($new_payment_amount, $entry["currency"]), $subscription_id)); // inserting transaction GFAuthorizeNetData::insert_transaction($entry_id, "payment", $subscription_id, $subscription_id, $new_payment_amount); do_action("gform_authorizenet_post_recurring_payment", $subscription_id, $entry, $new_payment_amount, $payment_count); //deprecated do_action("gform_authorizenet_after_recurring_payment", $entry, $subscription_id, $subscription_id, $new_payment_amount); break; case "expired": $entry["payment_status"] = "Expired"; RGFormsModel::update_lead($entry); RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Subscription has successfully completed its billing schedule. Subscriber Id: %s", "gravityformsauthorizenet"), $subscription_id)); do_action("gform_authorizenet_post_expire_subscription", $subscription_id, $entry); //deprecated do_action("gform_authorizenet_subscription_ended", $entry, $subscription_id, $transaction_id, $new_payment_amount); break; case "suspended": $entry["payment_status"] = "Failed"; RGFormsModel::update_lead($entry); RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Subscription is currently suspended due to a transaction decline, rejection, or error. Suspended subscriptions must be reactivated before the next scheduled transaction or the subscription will be terminated by the payment gateway. Subscriber Id: %s", "gravityforms"), $subscription_id)); do_action("gform_authorizenet_post_suspend_subscription", $subscription_id, $entry); //deprecated do_action("gform_authorizenet_subscription_suspended", $entry, $subscription_id, $transaction_id, $new_payment_amount); break; case "terminated": case "canceled": self::cancel_subscription($entry); RGFormsModel::add_note($entry_id, $user_id, $user_name, sprintf(__("Subscription has been canceled. Subscriber Id: %s", "gravityforms"), $subscription_id)); do_action("gform_authorizenet_post_cancel_subscription", $subscription_id, $entry); //deprecated do_action("gform_authorizenet_subscription_canceled", $entry, $subscription_id, $transaction_id, $new_payment_amount); break; default: $entry["payment_status"] = "Failed"; RGFormsModel::update_lead($entry); RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Subscription is currently suspended due to a transaction decline, rejection, or error. Suspended subscriptions must be reactivated before the next scheduled transaction or the subscription will be terminated by the payment gateway. Subscriber Id: %s", "gravityforms"), $subscription_id)); do_action("gform_authorizenet_post_suspend_subscription", $subscription_id, $entry); //deprecated do_action("gform_authorizenet_subscription_suspended", $entry, $subscription_id, $transaction_id, $new_payment_amount); break; } } } } }
private function gravityforms_send_note_to_jdb($id = 0, $noteid = 0, $note = '') { $local_server = array('localhost', 'make.com', 'makerfaire.local', 'staging.makerfaire.com'); $remote_post_url = 'http://db.makerfaire.com/addExhibitNote'; if (isset($_SERVER['HTTP_HOST']) && in_array($_SERVER['HTTP_HOST'], $local_server)) { $remote_post_url = 'http://makerfaire.local/wp-content/allpostdata.php'; } $encoded_array = http_build_query(array('CS_ID' => intval($id), 'note_id' => intval($noteid), 'note' => esc_attr($note))); $post_body = array('method' => 'POST', 'timeout' => 45, 'headers' => array(), 'body' => $encoded_array); // $res = wp_remote_post( 'http://makerfaire.local/wp-content/allpostdata.php', $post_body ); $res = wp_remote_post($remote_post_url, $post_body); $er = 0; if (200 == $res['response']['code']) { $body = json_decode($res['body']); if ('ERROR' != $body->status) { $er = time(); } // MySqli Insert Query $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } /* * $synccontents = '"'.noteId.':'.$mysqli->real_escape_string($post_body).'"'; $syncresults = '"'.$mysqli->real_escape_string($body).'"'; $querytext= "INSERT INTO `wp_rg_lead_jdb_sync`(`lead_id`, `synccontents`, `jdb_response`) VALUES ($id,$encoded_array, $syncresults)"; $insert_row = $mysqli->query($querytext); if($insert_row){ print 'Success! Response from JDB was: ' .$results_on_send .'<br />'; }else{ die('Error : ('. $mysqli->errno .') '. $mysqli->error); }; */ } gform_update_meta($id, 'mf_jdb_add_note', $body); return $er; }
private function create($entry, $form, $feed, $api) { $merge_vars = array(); foreach ($feed["meta"]["field_map"] as $var_tag => $field_id) { $field = RGFormsModel::get_field($form, $field_id); $input_type = RGFormsModel::get_input_type($field); if ($var_tag == 'address_full') { $merge_vars[$var_tag] = self::get_address($entry, $field_id); } else { if ($var_tag == 'country') { $merge_vars[$var_tag] = empty($entry[$field_id]) ? '' : GFCommon::get_country_code(trim($entry[$field_id])); } else { if ($entry[$field_id] === "0") { $merge_vars[$var_tag] = "0"; } else { if ($var_tag != "email") { if (!empty($entry[$field_id]) && !($entry[$field_id] == "0")) { switch ($input_type) { case 'multiselect': // If there are commas in the value, this makes it so it can be comma exploded. // Values cannot contain semicolons: http://boards.developerforce.com/t5/NET-Development/Salesforce-API-inserting-values-into-multiselect-fields-using/td-p/125910 foreach ($field['choices'] as $choice) { $entry[$field_id] = str_replace($choice, str_replace(',', ',', $choice), $entry[$field_id]); } // Break into an array $elements = explode(",", $entry[$field_id]); // We decode first so that the commas are commas again, then // implode the array to be picklist format for SF $merge_vars[$var_tag] = implode(';', array_map('html_entity_decode', array_map('htmlspecialchars', $elements))); break; default: $merge_vars[$var_tag] = htmlspecialchars($entry[$field_id]); } } else { // This is for checkboxes $elements = array(); foreach ($entry as $key => $value) { if (floor($key) == floor($field_id) && !empty($value)) { $elements[] = htmlspecialchars($value); } } $merge_vars[$var_tag] = implode(';', array_map('htmlspecialchars', $elements)); } } } } } } // Make sure the charset is UTF-8 for Salesforce. $merge_vars = array_map(array('GFSalesforce', '_convert_to_utf_8'), $merge_vars); // Don't send merge_vars that are empty. It can cause problems with Salesforce strict typing. For example, // if the form has a text field where a number should go, but that number isn't always required, when it's // not supplied, we don't want to send <var></var> to Salesforce. It might choke because it expects a Double // data type, not an empty string $merge_vars = array_filter($merge_vars, array('GFSalesforce', '_remove_empty_fields')); $account = new SObject(); $account->fields = $merge_vars; // Object type $account->type = $feed['meta']['contact_object_name']; try { $result = $api->create(array($account)); $api_exception = ''; } catch (Exception $e) { $api_exception = "\r\n Message: " . $e->getMessage() . "\nFaultstring: " . $e->faultstring . "\nFile: " . $e->getFile() . "\nLine: " . $e->getLine() . "\nArgs: " . serialize($merge_vars) . "\nTrace: " . serialize($e->getTrace()); } $debug = ''; if (self::is_debug()) { $debug = '<pre>' . print_r(array('Form Entry Data' => $entry, 'Form Meta Data' => $form, 'Salesforce Feed Meta Data' => $feed, 'Salesforce Posted Merge Data' => $merge_vars, 'Posted Data ($_POST)' => $_POST, 'result' => $result[0], '$api' => $api, '$api_exception' => $api_exception), true) . '</pre>'; } if (isset($result[0]) && !empty($result[0]->success)) { if (self::is_debug()) { echo '<h2>Success</h2>' . $debug; } gform_update_meta($entry['id'], 'salesforce_id', $result[0]->id); self::add_note($entry["id"], sprintf(__('Successfully added to Salesforce with ID #%s . View entry at %s', 'gravity-forms-salesforce'), $result[0]->id, 'https://na9.salesforce.com/' . $result[0]->id)); return $result[0]->id; } else { $errors = $result[0]->errors[0]; if (self::is_debug()) { echo '<h2>Error</h2>' . $debug; echo '<h2>Errors</h2><pre>' . print_r($errors, true) . '</pre>'; } if ($email = self::is_notify_on_error()) { $message = sprintf(apply_filters('gravityforms_salesforce_notify_on_error_message', __("<h3>Error Adding To Salesforce</h3><p>There was an error when attempting to add <a href='%s'>Entry #%s</a> from the form \"%s\"</p>", 'gravity-forms-salesforce'), $errors, $entry, $form), admin_url('admin.php?page=gf_entries&view=entry&id=' . $entry['form_id'] . '&lid=' . $entry['id']), $entry['id'], $form['title']); $headers = "Content-type: text/html; charset=" . get_option('blog_charset') . "\r\n"; wp_mail($email, __('Error adding to Salesforce', 'gravity-forms-salesforce'), $message, $headers); } self::add_note($entry["id"], sprintf(__('Errors when adding to Salesforce: %s', 'gravity-forms-salesforce'), $errors->message . $api_exception)); return false; } }
/** * * @global type $wpdb */ function entries_import() { $wform = $_REQUEST['form']; $gform = $_REQUEST['gform']; $entry_index = $_REQUEST['entry_index']; $this->init(); $field_map = maybe_unserialize(get_site_option('rt_wufoo_' . $wform . '_field_map')); $f = new RGFormsModel(); $c = new GFCommon(); $gform_meta = RGFormsModel::get_form_meta($gform); try { $entries = $this->wufoo->getEntries($wform, 'forms', 'pageStart=' . $entry_index . '&pageSize=' . RT_WUFOO_IMPORT_PAGE_SIZE); } catch (Exception $rt_importer_e) { $this->error($rt_importer_e); } $this->op = array(); foreach ($entries as $index => $entry) { $lead_exists_id = $this->is_imported($entry->EntryId); print_r($lead_exists_id); if (!$lead_exists_id) { foreach ($field_map as $g_id => $w_id) { if (isset($w_id) && $w_id != '') { $this->op[$g_id] = ''; $field_meta = RGFormsModel::get_field($gform_meta, $g_id); if ($field_meta['type'] == 'fileupload') { $this->op[$g_id] = $this->import_file_upload($entry, $w_id); } else { $this->import_regular_field($wform, $entry, $g_id, $w_id, $field_meta); } } } $currency = $c->get_currency(); $ip = $f->get_ip(); $page = $f->get_current_page_url(); $lead_table = $f->get_lead_table_name(); $lead_id = $this->insert_lead($entry, $lead_table, $ip, $currency, $page, $wform, $gform); } if ($lead_id) { foreach ($this->op as $inputid => $value) { $this->insert_fields($lead_id, $gform, $inputid, $value); } //Insert comments as notes for the corresponding user map $comments = $this->get_comments_by_entry($wform, $entry->EntryId); if (isset($comments) && !empty($comments)) { foreach ($comments as $comment) { $this->move_comments_for_entry($comment, $f->get_lead_notes_table_name(), $lead_id, $wform); } } } else { $lead_id = $lead_exists_id; } gform_update_meta($lead_id, 'rt_wufoo_entry_id', $entry->EntryId); } //update_site_option('rt_wufoo_' . $wform . '_entry_complete_count','0'); echo count($entries) + $entry_index; die; }
public static function get_product_fields($form, $lead, $use_choice_text = false, $use_admin_label = false) { $products = array(); $product_info = null; // retrieve static copy of product info (only for 'real' entries) if (!rgempty('id', $lead)) { $product_info = gform_get_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}"); } // if no static copy, generate from form/lead info if (!$product_info) { foreach ($form['fields'] as $field) { $id = $field->id; $lead_value = RGFormsModel::get_lead_field_value($lead, $field); $quantity_field = self::get_product_fields_by_type($form, array('quantity'), $id); $quantity = sizeof($quantity_field) > 0 && !RGFormsModel::is_field_hidden($form, $quantity_field[0], array(), $lead) ? RGFormsModel::get_lead_field_value($lead, $quantity_field[0]) : 1; switch ($field->type) { case 'product': //ignore products that have been hidden by conditional logic $is_hidden = RGFormsModel::is_field_hidden($form, $field, array(), $lead); if ($is_hidden) { continue; } //if single product, get values from the multiple inputs if (is_array($lead_value)) { $product_quantity = sizeof($quantity_field) == 0 && !$field->disableQuantity ? rgget($id . '.3', $lead_value) : $quantity; if (empty($product_quantity)) { continue; } if (!rgget($id, $products)) { $products[$id] = array(); } $products[$id]['name'] = $use_admin_label && !rgempty('adminLabel', $field) ? $field->adminLabel : $lead_value[$id . '.1']; $products[$id]['price'] = rgar($lead_value, $id . '.2'); $products[$id]['quantity'] = $product_quantity; } elseif (!empty($lead_value)) { if (empty($quantity)) { continue; } if (!rgar($products, $id)) { $products[$id] = array(); } if ($field->inputType == 'price') { $name = $field->label; $price = $lead_value; } else { list($name, $price) = explode('|', $lead_value); } $products[$id]['name'] = !$use_choice_text ? $name : RGFormsModel::get_choice_text($field, $name); $include_field_label = apply_filters('gform_product_info_name_include_field_label', false); if ($field->inputType == ('radio' || 'select') && $include_field_label) { $products[$id]['name'] = $field->label . " ({$products[$id]['name']})"; } $products[$id]['price'] = $price; $products[$id]['quantity'] = $quantity; $products[$id]['options'] = array(); } if (isset($products[$id])) { $options = self::get_product_fields_by_type($form, array('option'), $id); foreach ($options as $option) { $option_value = RGFormsModel::get_lead_field_value($lead, $option); $option_label = empty($option['adminLabel']) ? $option['label'] : $option['adminLabel']; if (is_array($option_value)) { foreach ($option_value as $value) { $option_info = self::get_option_info($value, $option, $use_choice_text); if (!empty($option_info)) { $products[$id]['options'][] = array('field_label' => rgar($option, 'label'), 'option_name' => rgar($option_info, 'name'), 'option_label' => $option_label . ': ' . rgar($option_info, 'name'), 'price' => rgar($option_info, 'price')); } } } elseif (!empty($option_value)) { $option_info = self::get_option_info($option_value, $option, $use_choice_text); $products[$id]['options'][] = array('field_label' => rgar($option, 'label'), 'option_name' => rgar($option_info, 'name'), 'option_label' => $option_label . ': ' . rgar($option_info, 'name'), 'price' => rgar($option_info, 'price')); } } } break; } } $shipping_field = GFAPI::get_fields_by_type($form, array('shipping')); $shipping_price = $shipping_name = ''; $shipping_field_id = ''; if (!empty($shipping_field) && !RGFormsModel::is_field_hidden($form, $shipping_field[0], array(), $lead)) { $shipping_price = RGFormsModel::get_lead_field_value($lead, $shipping_field[0]); $shipping_name = $shipping_field[0]['label']; $shipping_field_id = $shipping_field[0]['id']; if ($shipping_field[0]['inputType'] != 'singleshipping') { list($shipping_method, $shipping_price) = explode('|', $shipping_price); $shipping_name = $shipping_field[0]['label'] . " ({$shipping_method})"; } } $shipping_price = self::to_number($shipping_price); $product_info = array('products' => $products, 'shipping' => array('id' => $shipping_field_id, 'name' => $shipping_name, 'price' => $shipping_price)); $product_info = gf_apply_filters('gform_product_info', $form['id'], $product_info, $form, $lead); // save static copy of product info (only for 'real' entries) if (!rgempty('id', $lead) && !empty($product_info['products'])) { gform_update_meta($lead['id'], "gform_product_info_{$use_choice_text}_{$use_admin_label}", $product_info); } } return $product_info; }
/** * Update the `is_approved` entry meta value * @param int $entry_id ID of the Gravity Forms entry * @param string $is_approved String whether entry is approved or not. `0` for not approved, `Approved` for approved. * * @since 1.7.6.1 `after_update_entry_update_approved_meta` was previously to be named `update_approved_meta` * * @return void */ private static function update_approved_meta($entry_id, $is_approved) { // update entry meta if (function_exists('gform_update_meta')) { gform_update_meta($entry_id, 'is_approved', $is_approved); /** * @action `gravityview/approve_entries/updated` Triggered when an entry approval is updated * @since 1.7.6.1 * @param int $entry_id ID of the Gravity Forms entry * @param string $is_approved String whether entry is approved or not. `0` for not approved, `Approved` for approved. */ do_action('gravityview/approve_entries/updated', $entry_id, $is_approved); if (empty($is_approved)) { /** * @action `gravityview/approve_entries/disapproved` Triggered when an entry is rejected * @since 1.7.6.1 * @param int $entry_id ID of the Gravity Forms entry */ do_action('gravityview/approve_entries/disapproved', $entry_id); } else { /** * @action `gravityview/approve_entries/approved` Triggered when an entry is approved * @since 1.7.6.1 * @param int $entry_id ID of the Gravity Forms entry */ do_action('gravityview/approve_entries/approved', $entry_id); } } else { do_action('gravityview_log_error', __METHOD__ . ' - `gform_update_meta` does not exist.'); } }
public function process_subscription($authorization, $feed, $submission_data, $form, $entry) { gform_update_meta($entry['id'], 'stripe_customer_id', $authorization['subscription']['customer_id']); return parent::process_subscription($authorization, $feed, $submission_data, $form, $entry); }
/** * If using the entry custom slug feature, make sure the new entries have the custom slug created and saved as meta * * Triggered by add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 ); * * @param $entry array Gravity Forms entry object * @param $form array Gravity Forms form object */ public static function entry_create_custom_slug($entry, $form) { /** * @filter `gravityview_custom_entry_slug` On entry creation, check if we are using the custom entry slug feature and update the meta * @param boolean $custom Should we process the custom entry slug? */ $custom = apply_filters('gravityview_custom_entry_slug', false); if ($custom) { // create the gravityview_unique_id and save it // Get the entry hash $hash = self::get_custom_entry_slug($entry['id'], $entry); gform_update_meta($entry['id'], 'gravityview_unique_id', $hash); } }
public static function export($entry, $form, $is_fulfilled = false) { $paypal_config = self::get_paypal_config($form["id"], $entry); //if configured to only subscribe users when payment is received, delay subscription until the payment is received. if ($paypal_config && rgar($paypal_config["meta"], "delay_mailchimp_subscription") && !$is_fulfilled) { self::log("Subscription delayed pending PayPal payment received for entry " . $entry["id"], "debug"); return; } //Login to MailChimp $api = self::get_api(); if (!$api) { return; } //loading data class require_once self::get_base_path() . "/data.php"; //getting all active feeds $feeds = GFMailChimpData::get_feed_by_form($form["id"], true); foreach ($feeds as $feed) { //only export if user has opted in if (self::is_optin($form, $feed, $entry)) { self::export_feed($entry, $form, $feed, $api); //updating meta to indicate this entry has already been subscribed to MailChimp. This will be used to prevent duplicate subscriptions. self::log("Marking entry " . $entry["id"] . " as subscribed", "debug"); gform_update_meta($entry["id"], "mailchimp_is_subscribed", true); } else { self::log("Opt-in condition not met; not subscribing entry " . $entry["id"] . " to list", "debug"); } } }
public static function set_encrypted_fields($entry_id, $field_ids) { if (!is_array($field_ids)) { $field_ids = array($field_ids); } $encrypted_fields = array_merge(self::get_encrypted_fields($entry_id), $field_ids); gform_update_meta($entry_id, '_encrypted_fields', $encrypted_fields); return true; }
/** * Adds a single Entry object. * * Intended to be used for importing an entry object. The usual hooks that are triggered while saving entries are not fired here. * Checks that the form id, field ids and entry meta exist and ignores legacy values (i.e. values for fields that no longer exist). * * @since 1.8 * @access public * @static * * @param array $entry The Entry object * * @return mixed Either the new Entry ID or a WP_Error instance */ public static function add_entry($entry) { global $wpdb; if (!is_array($entry)) { return new WP_Error("invalid_entry_object", __("The entry object must be an array", "gravityforms")); } // make sure the form id exists $form_id = rgar($entry, "form_id"); if (empty($form_id)) { return new WP_Error("empty_form_id", __("The form id must be specified", "gravityforms")); } if (false === self::form_id_exists($form_id)) { return new WP_Error("invalid_form_id", __("The form for this entry does not exist", "gravityforms")); } // use values in the entry object if present $post_id = isset($entry["post_id"]) ? intval($entry["post_id"]) : 'NULL'; $date_created = isset($entry["date_created"]) && $entry["date_created"] != "" ? sprintf("'%s'", mysql_real_escape_string($entry["date_created"])) : "utc_timestamp()"; $is_starred = isset($entry["is_starred"]) ? $entry["is_starred"] : 0; $is_read = isset($entry["is_read"]) ? $entry["is_read"] : 0; $ip = isset($entry["ip"]) ? $entry["ip"] : GFFormsModel::get_ip(); $source_url = isset($entry["source_url"]) ? $entry["source_url"] : GFFormsModel::get_current_page_url(); $user_agent = isset($entry["user_agent"]) ? $entry["user_agent"] : "API"; $currency = isset($entry["currency"]) ? $entry["currency"] : GFCommon::get_currency(); $payment_status = isset($entry["payment_status"]) ? sprintf("'%s'", mysql_real_escape_string($entry["payment_status"])) : 'NULL'; $payment_date = strtotime(rgar($entry, "payment_date")) ? sprintf("'%s'", gmdate('Y-m-d H:i:s', strtotime("{$entry["payment_date"]}"))) : "NULL"; $payment_amount = isset($entry["payment_amount"]) ? (double) $entry["payment_amount"] : 'NULL'; $payment_method = isset($entry["payment_method"]) ? $entry["payment_method"] : ''; $transaction_id = isset($entry["transaction_id"]) ? sprintf("'%s'", mysql_real_escape_string($entry["transaction_id"])) : 'NULL'; $is_fulfilled = isset($entry["is_fulfilled"]) ? intval($entry["is_fulfilled"]) : 'NULL'; $status = isset($entry["status"]) ? $entry["status"] : "active"; global $current_user; $user_id = isset($entry["created_by"]) ? mysql_real_escape_string($entry["created_by"]) : ""; if (empty($user_id)) { $user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL'; } $transaction_type = isset($entry["transaction_type"]) ? intval($entry["transaction_type"]) : 'NULL'; $lead_table = GFFormsModel::get_lead_table_name(); $result = $wpdb->query($wpdb->prepare("\n INSERT INTO {$lead_table}\n (form_id, post_id, date_created, is_starred, is_read, ip, source_url, user_agent, currency, payment_status, payment_date, payment_amount, transaction_id, is_fulfilled, created_by, transaction_type, status, payment_method)\n VALUES\n (%d, {$post_id}, {$date_created}, %d, %d, %s, %s, %s, %s, {$payment_status}, {$payment_date}, {$payment_amount}, {$transaction_id}, {$is_fulfilled}, {$user_id}, {$transaction_type}, %s, %s)\n ", $form_id, $is_starred, $is_read, $ip, $source_url, $user_agent, $currency, $status, $payment_method)); if (false === $result) { return new WP_Error("insert_entry_properties_failed", __("There was a problem while inserting the entry properties", "gravityforms"), $wpdb->last_error); } // reading newly created lead id $entry_id = $wpdb->insert_id; $entry["id"] = $entry_id; // only save field values for fields that currently exist in the form $form = GFFormsModel::get_form_meta($form_id); foreach ($form["fields"] as $field) { if (in_array($field["type"], array("html", "page", "section"))) { continue; } if (isset($field["inputs"]) && is_array($field["inputs"])) { foreach ($field["inputs"] as $input) { $input_id = $input["id"]; if (isset($entry[(string) $input_id])) { $result = GFFormsModel::update_lead_field_value($form, $entry, $field, 0, $input_id, $entry[(string) $input_id]); if (false === $result) { return new WP_Error("insert_input_value_failed", __("There was a problem while inserting one of the input values for the entry", "gravityforms"), $wpdb->last_error); } } } } else { $field_id = $field["id"]; $field_value = isset($entry[(string) $field_id]) ? $entry[(string) $field_id] : ""; $result = GFFormsModel::update_lead_field_value($form, $entry, $field, 0, $field_id, $field_value); if (false === $result) { return new WP_Error("insert_field_values_failed", __("There was a problem while inserting the field values", "gravityforms"), $wpdb->last_error); } } } // add save the entry meta values - only for the entry meta currently available for the form, ignore the rest $entry_meta = GFFormsModel::get_entry_meta($form_id); if (is_array($entry_meta)) { foreach (array_keys($entry_meta) as $key) { if (isset($entry[$key])) { gform_update_meta($entry_id, $key, $entry[$key]); } } } return $entry_id; }
public static function send_to_paypal($confirmation, $form, $entry, $ajax) { // ignore requests that are not the current form's submissions if (RGForms::post("gform_submit") != $form["id"]) { return $confirmation; } $config = self::get_active_config($form); if (!$config) { self::log_debug("NOT sending to PayPal: No PayPal setup was located for form_id = {$form['id']}."); return $confirmation; } // updating entry meta with current feed id gform_update_meta($entry["id"], "paypal_feed_id", $config["id"]); // updating entry meta with current payment gateway gform_update_meta($entry["id"], "payment_gateway", "paypal"); //updating lead's payment_status to Processing RGFormsModel::update_lead_property($entry["id"], "payment_status", 'Processing'); //Getting Url (Production or Sandbox) $url = $config["meta"]["mode"] == "production" ? self::$production_url : self::$sandbox_url; $invoice_id = apply_filters("gform_paypal_invoice", "", $form, $entry); $invoice = empty($invoice_id) ? "" : "&invoice={$invoice_id}"; //Current Currency $currency = GFCommon::get_currency(); //Customer fields $customer_fields = self::customer_query_string($config, $entry); //Page style $page_style = !empty($config["meta"]["style"]) ? "&page_style=" . urlencode($config["meta"]["style"]) : ""; //Continue link text $continue_text = !empty($config["meta"]["continue_text"]) ? "&cbt=" . urlencode($config["meta"]["continue_text"]) : "&cbt=" . __("Click here to continue", "gravityformspaypal"); //If page is HTTPS, set return mode to 2 (meaning PayPal will post info back to page) //If page is not HTTPS, set return mode to 1 (meaning PayPal will redirect back to page) to avoid security warning $return_mode = GFCommon::is_ssl() ? "2" : "1"; $return_url = "&return=" . urlencode(self::return_url($form["id"], $entry["id"])) . "&rm={$return_mode}"; //Cancel URL $cancel_url = !empty($config["meta"]["cancel_url"]) ? "&cancel_return=" . urlencode($config["meta"]["cancel_url"]) : ""; //Don't display note section $disable_note = !empty($config["meta"]["disable_note"]) ? "&no_note=1" : ""; //Don't display shipping section $disable_shipping = !empty($config["meta"]["disable_shipping"]) ? "&no_shipping=1" : ""; //URL that will listen to notifications from PayPal $ipn_url = urlencode(get_bloginfo("url") . "/?page=gf_paypal_ipn"); $business_email = urlencode(trim($config["meta"]["email"])); $custom_field = $entry["id"] . "|" . wp_hash($entry["id"]); $url .= "?notify_url={$ipn_url}&charset=UTF-8¤cy_code={$currency}&business={$business_email}&custom={$custom_field}{$invoice}{$customer_fields}{$page_style}{$continue_text}{$cancel_url}{$disable_note}{$disable_shipping}{$return_url}"; $query_string = ""; switch ($config["meta"]["type"]) { case "product": $query_string = self::get_product_query_string($form, $entry); break; case "donation": $query_string = self::get_donation_query_string($form, $entry); break; case "subscription": $query_string = self::get_subscription_query_string($config, $form, $entry); break; } $query_string = apply_filters("gform_paypal_query_{$form['id']}", apply_filters("gform_paypal_query", $query_string, $form, $entry), $form, $entry); if (!$query_string) { self::log_debug("NOT sending to PayPal: The price is either zero or the gform_paypal_query filter was used to remove the querystring that is sent to PayPal."); return $confirmation; } $url .= $query_string; $url = apply_filters("gform_paypal_request_{$form['id']}", apply_filters("gform_paypal_request", $url, $form, $entry), $form, $entry); self::log_debug("Sending to PayPal: {$url}"); if (headers_sent() || $ajax) { $confirmation = "<script>function gformRedirect(){document.location.href='{$url}';}"; if (!$ajax) { $confirmation .= "gformRedirect();"; } $confirmation .= "</script>"; } else { $confirmation = array("redirect" => $url); } return $confirmation; }
/** * Create a new task from a feed. * * @access public * @param int $record_id * @param string $module * @param array $feed * @param array $entry * @param array $form * @return void */ public function create_task($record_id, $module, $feed, $entry, $form) { if (rgars($feed, 'meta/createTask') != '1') { return; } /* Create task object. */ $task = array('Subject' => GFCommon::replace_variables($feed['meta']['taskSubject'], $form, $entry, false, false, false, 'text'), 'Status' => rgars($feed, 'meta/taskStatus'), 'SMOWNERID' => rgars($feed, 'meta/taskOwner'), 'Description' => GFCommon::replace_variables($feed['meta']['taskDescription'], $form, $entry, false, false, false, 'text')); if (rgars($feed, 'meta/taskDueDate')) { $due_date = GFCommon::replace_variables($feed['meta']['taskDueDate'], $form, $entry, false, false, false, 'text'); if (is_numeric($due_date)) { $task['Due Date'] = date('Y-m-d', strtotime('+' . $due_date . ' days')); } } /* Add lead or contact ID. */ if ($module === 'Contacts') { $task['CONTACTID'] = $record_id; } else { if ($module === 'Leads') { $task['SEID'] = $record_id; $task['SEMODULE'] = $module; } } /* Filter task. */ $task = gf_apply_filters('gform_zohocrm_task', $form['id'], $task, $feed, $entry, $form); /* Remove SMOWNERID if not set. */ if (rgblank($task['SMOWNERID'])) { unset($task['SMOWNERID']); } /* Prepare task record XML. */ $task_xml = '<Tasks>' . "\r\n"; $task_xml .= '<row no="1">' . "\r\n"; foreach ($task as $field_key => $field_value) { $task_xml .= $this->get_field_xml($field_key, $field_value); } $task_xml .= '</row>' . "\r\n"; $task_xml .= '</Tasks>' . "\r\n"; $this->log_debug(__METHOD__ . '(): Creating task: ' . print_r($task, true)); $this->log_debug(__METHOD__ . '(): Creating task XML: ' . print_r($task_xml, true)); try { /* Insert task record. */ $task_record = $this->api->insert_record('Tasks', $task_xml); /* Get ID of new task record. */ $task_id = 0; foreach ($task_record->result->recorddetail as $detail) { foreach ($detail->children() as $field) { if ($field['val'] == 'Id') { $task_id = (string) $field; } } } /* Save task ID to entry meta. */ gform_update_meta($entry['id'], 'zohocrm_task_id', $task_id); /* Log that task was created. */ $this->log_debug(__METHOD__ . '(): Task #' . $task_id . ' created and assigned to ' . $module . ' #' . $record_id . '.'); return $task_id; } catch (Exception $e) { $this->log_error(__METHOD__ . '(): Could not create task; ' . $e->getMessage()); return null; } }
public function paypal_fulfillment($entry, $paypal_config, $transaction_id, $amount) { $this->log_debug('GFFeedAddOn::paypal_fulfillment(): Checking PayPal fulfillment for transaction ' . $transaction_id . ' for ' . $this->_slug); $is_fulfilled = gform_get_meta($entry['id'], "{$this->_slug}_is_fulfilled"); if ($is_fulfilled) { $this->log_debug('GFFeedAddOn::paypal_fulfillment(): Entry ' . $entry['id'] . ' is already fulfilled for ' . $this->_slug . '. No action necessary.'); return false; } $form = RGFormsModel::get_form_meta($entry['form_id']); $feed_to_process = ''; $feeds = $this->get_feeds($entry['form_id']); foreach ($feeds as $feed) { if ($feed['is_active'] && $this->is_feed_condition_met($feed, $form, $entry)) { $feed_to_process = $feed; break; } } if (empty($feed_to_process)) { $this->log_debug('GFFeedAddOn::paypal_fulfillment(): No active feeds found or feeds did not meet conditional logic for ' . $this->_slug . '. No fulfillment necessary.'); return false; } $this->process_feed($feed_to_process, $entry, $form); // updating meta to indicate this entry has been fulfilled for the current add-on $this->log_debug('GFFeedAddOn::paypal_fulfillment(): Marking entry ' . $entry['id'] . ' as fulfilled for ' . $this->_slug); gform_update_meta($entry['id'], "{$this->_slug}_is_fulfilled", true); }
public static function get_active_config($form, $lead = false) { require_once self::get_base_path() . "/data.php"; $config = false; // if lead is provided, attempt to retrieve config from lead meta if (isset($lead['id'])) { $config_id = gform_get_meta($lead['id'], 'user_registration_feed_id'); $config = GFUserData::get_feed($config_id); } // if no lead is provided or if meta retrieval fails, get all feeds and find the first feed that matches if (!$config) { $configs = GFUserData::get_feeds_by_form($form["id"]); if (!$configs) { return false; } foreach ($configs as $cnfg) { if (self::registration_condition_met($form, $cnfg, $lead)) { $config = $cnfg; break; } } } // if lead is provided and a config is found, update lead meta with config ID if (isset($lead['id']) && $config && !$config_id) { gform_update_meta($lead['id'], 'user_registration_feed_id', $config['id']); } if ($config) { return $config; } return false; }
public static function set_entry_meta($lead, $form) { $entry_meta = self::get_entry_meta($form["id"]); $keys = array_keys($entry_meta); foreach ($keys as $key) { if (isset($entry_meta[$key]['update_entry_meta_callback'])) { $callback = $entry_meta[$key]['update_entry_meta_callback']; $value = call_user_func_array($callback, array($key, $lead, $form)); gform_update_meta($lead["id"], $key, $value); $lead[$key] = $value; } } return $lead; }
public function entry_post_save($entry, $form) { if (!$this->is_payment_gateway) { return $entry; } $feed = $this->current_feed; if (!empty($this->authorization)) { //If an authorization was done, capture it if ($feed['meta']['transactionType'] == 'subscription') { $entry = $this->process_subscription($this->authorization, $feed, $this->current_submission_data, $form, $entry); } else { if ($this->payment_method_is_overridden('capture') && rgempty('captured_payment', $this->authorization)) { $this->authorization['captured_payment'] = $this->capture($this->authorization, $feed, $this->current_submission_data, $form, $entry); } $entry = $this->process_capture($this->authorization, $feed, $this->current_submission_data, $form, $entry); } } elseif ($this->payment_method_is_overridden('redirect_url')) { //If the url_redirect() function is overridden, call it. //Getting URL to redirect to ( saved to be used by the confirmation() function ) $this->redirect_url = $this->redirect_url($feed, $this->current_submission_data, $form, $entry); //Setting transaction_type to subscription or one time payment $entry['transaction_type'] = rgars($feed, 'meta/transactionType') == 'subscription' ? 2 : 1; $entry['payment_status'] = 'Processing'; } //Saving which gateway was used to process this entry gform_update_meta($entry['id'], 'payment_gateway', $this->_slug); return $entry; }
public static function set_entry_meta($entry, $form) { // ignore requests that are not the current form's submissions if (rgpost("gform_submit") != $form["id"]) { return; } $config = self::get_active_config($form); if (!$config) { return; } //updating form meta with current feed id gform_update_meta($entry["id"], "paypal_feed_id", $config["id"]); //updating form meta with current payment gateway gform_update_meta($entry["id"], "payment_gateway", "paypal"); }