/** * * Display admin bar when active * * @return bool */ public function give_admin_bar_menu() { global $wp_admin_bar; if (!give_is_test_mode() || !current_user_can('view_give_reports')) { return false; } //Add the main siteadmin menu item $wp_admin_bar->add_menu(array('id' => 'give-test-notice', 'href' => admin_url() . 'edit.php?post_type=give_forms&page=give-settings&tab=gateways', 'parent' => 'top-secondary', 'title' => __('Give Test Mode Active', 'give'), 'meta' => array('class' => 'give-test-mode-active'))); }
/** * Complete a purchase * * Performs all necessary actions to complete a purchase. * Triggered by the give_update_payment_status() function. * * @since 1.0 * * @param int $payment_id the ID number of the payment * @param string $new_status the status of the payment, probably "publish" * @param string $old_status the status of the payment prior to being marked as "complete", probably "pending" * * @return void */ function give_complete_purchase($payment_id, $new_status, $old_status) { if ($old_status == 'publish' || $old_status == 'complete') { return; } // Make sure that payments are only completed once // Make sure the payment completion is only processed when new status is complete if ($new_status != 'publish' && $new_status != 'complete') { return; } $payment_meta = give_get_payment_meta($payment_id); $creation_date = get_post_field('post_date', $payment_id, 'raw'); $completed_date = give_get_payment_completed_date($payment_id); $user_info = give_get_payment_meta_user_info($payment_id); $donor_id = give_get_payment_customer_id($payment_id); $amount = give_get_payment_amount($payment_id); do_action('give_pre_complete_purchase', $payment_id); $price_id = isset($_POST['give-price-id']) ? (int) $_POST['give-price-id'] : false; // Ensure these actions only run once, ever if (empty($completed_date)) { if (!give_is_test_mode() || apply_filters('give_log_test_payment_stats', false)) { give_record_sale_in_log($payment_meta['form_id'], $payment_id, $price_id, $creation_date); give_increase_purchase_count($payment_meta['form_id']); give_increase_earnings($payment_meta['form_id'], $amount); } do_action('give_complete_form_donation', $payment_meta['form_id'], $payment_id, $payment_meta); } // Clear the total earnings cache delete_transient('give_earnings_total'); // Clear the This Month earnings (this_monththis_month is NOT a typo) delete_transient(md5('give_earnings_this_monththis_month')); delete_transient(md5('give_earnings_todaytoday')); // Increase the donor's purchase stats Give()->customers->increment_stats($donor_id, $amount); give_increase_total_earnings($amount); // Ensure this action only runs once ever if (empty($completed_date)) { // Save the completed date give_update_payment_meta($payment_id, '_give_completed_date', current_time('mysql')); do_action('give_complete_purchase', $payment_id); } }
/** * Get the Export Data * * @access public * @since 1.0 * @global object $wpdb Used to query the database using the WordPress * Database API * @return array $data The data for the CSV file */ public function get_data() { global $wpdb, $give_options; $data = array(); $payments = give_get_payments(array('offset' => 0, 'number' => -1, 'mode' => give_is_test_mode() ? 'test' : 'live', 'status' => isset($_POST['give_export_payment_status']) ? $_POST['give_export_payment_status'] : 'any', 'month' => isset($_POST['month']) ? absint($_POST['month']) : date('n'), 'year' => isset($_POST['year']) ? absint($_POST['year']) : date('Y'))); foreach ($payments as $payment) { $payment_meta = give_get_payment_meta($payment->ID); $user_info = give_get_payment_meta_user_info($payment->ID); $total = give_get_payment_amount($payment->ID); $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email']; $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : ''; $form_title = isset($payment_meta['form_title']) ? $payment_meta['form_title'] : ''; if (is_numeric($user_id)) { $user = get_userdata($user_id); } else { $user = false; } $data[] = array('id' => $payment->ID, 'seq_id' => give_get_payment_number($payment->ID), 'email' => $payment_meta['email'], 'first' => $user_info['first_name'], 'last' => $user_info['last_name'], 'address1' => isset($user_info['address']['line1']) ? $user_info['address']['line1'] : '', 'address2' => isset($user_info['address']['line2']) ? $user_info['address']['line2'] : '', 'city' => isset($user_info['address']['city']) ? $user_info['address']['city'] : '', 'state' => isset($user_info['address']['state']) ? $user_info['address']['state'] : '', 'country' => isset($user_info['address']['country']) ? $user_info['address']['country'] : '', 'zip' => isset($user_info['address']['zip']) ? $user_info['address']['zip'] : '', 'amount' => html_entity_decode(give_format_amount($total)), 'form_id' => $form_id, 'form' => $form_title, 'gateway' => give_get_gateway_admin_label(get_post_meta($payment->ID, '_give_payment_gateway', true)), 'trans_id' => give_get_payment_transaction_id($payment->ID), 'key' => $payment_meta['key'], 'date' => $payment->post_date, 'user' => $user ? $user->display_name : __('guest', 'give'), 'status' => give_get_payment_status($payment, true)); } $data = apply_filters('give_export_get_data', $data); $data = apply_filters('give_export_get_data_' . $this->export_type, $data); return $data; }
/** * Get PayPal Redirect * * @since 1.0 * * @param bool $ssl_check Is SSL? * * @return string */ function give_get_paypal_redirect($ssl_check = false) { if (is_ssl() || !$ssl_check) { $protocal = 'https://'; } else { $protocal = 'http://'; } // Check the current payment mode if (give_is_test_mode()) { // Test mode $paypal_uri = $protocal . 'www.sandbox.paypal.com/cgi-bin/webscr'; } else { // Live mode $paypal_uri = $protocal . 'www.paypal.com/cgi-bin/webscr'; } return apply_filters('give_paypal_uri', $paypal_uri); }
/** * Get system info * * @since 1.0 * @access public * @global object $wpdb Used to query the database using the WordPress Database API * @global array $give_options Array of all Give options * @return string $return A string containing the info to output */ function give_tools_sysinfo_get() { global $wpdb, $give_options; if (!class_exists('Browser')) { require_once GIVE_PLUGIN_DIR . 'includes/libraries/browser.php'; } $browser = new Browser(); // Get theme info if (get_bloginfo('version') < '3.4') { $theme_data = get_theme_data(get_stylesheet_directory() . '/style.css'); $theme = $theme_data['Name'] . ' ' . $theme_data['Version']; } else { $theme_data = wp_get_theme(); $theme = $theme_data->Name . ' ' . $theme_data->Version; } // Try to identify the hosting provider $host = give_get_host(); $return = '### Begin System Info ###' . "\n\n"; // Start with the basics... $return .= '-- Site Info' . "\n\n"; $return .= 'Site URL: ' . site_url() . "\n"; $return .= 'Home URL: ' . home_url() . "\n"; $return .= 'Multisite: ' . (is_multisite() ? 'Yes' : 'No') . "\n"; $return = apply_filters('give_sysinfo_after_site_info', $return); // Can we determine the site's host? if ($host) { $return .= "\n" . '-- Hosting Provider' . "\n\n"; $return .= 'Host: ' . $host . "\n"; $return = apply_filters('give_sysinfo_after_host_info', $return); } // The local users' browser information, handled by the Browser class $return .= "\n" . '-- User Browser' . "\n\n"; $return .= $browser; $return = apply_filters('give_sysinfo_after_user_browser', $return); // WordPress configuration $return .= "\n" . '-- WordPress Configuration' . "\n\n"; $return .= 'Version: ' . get_bloginfo('version') . "\n"; $return .= 'Language: ' . (defined('WPLANG') && WPLANG ? WPLANG : 'en_US') . "\n"; $return .= 'Permalink Structure: ' . (get_option('permalink_structure') ? get_option('permalink_structure') : 'Default') . "\n"; $return .= 'Active Theme: ' . $theme . "\n"; $return .= 'Show On Front: ' . get_option('show_on_front') . "\n"; // Only show page specs if frontpage is set to 'page' if (get_option('show_on_front') == 'page') { $front_page_id = get_option('page_on_front'); $blog_page_id = get_option('page_for_posts'); $return .= 'Page On Front: ' . ($front_page_id != 0 ? get_the_title($front_page_id) . ' (#' . $front_page_id . ')' : 'Unset') . "\n"; $return .= 'Page For Posts: ' . ($blog_page_id != 0 ? get_the_title($blog_page_id) . ' (#' . $blog_page_id . ')' : 'Unset') . "\n"; } // Make sure wp_remote_post() is working $request['cmd'] = '_notify-validate'; $params = array('sslverify' => false, 'timeout' => 60, 'user-agent' => 'Give/' . GIVE_VERSION, 'body' => $request); $response = wp_remote_post('https://www.paypal.com/cgi-bin/webscr', $params); if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) { $WP_REMOTE_POST = 'wp_remote_post() works'; } else { $WP_REMOTE_POST = 'wp_remote_post() does not work'; } $return .= 'Remote Post: ' . $WP_REMOTE_POST . "\n"; $return .= 'Table Prefix: ' . 'Length: ' . strlen($wpdb->prefix) . ' Status: ' . (strlen($wpdb->prefix) > 16 ? 'ERROR: Too long' : 'Acceptable') . "\n"; $return .= 'Admin AJAX: ' . (give_test_ajax_works() ? 'Accessible' : 'Inaccessible') . "\n"; $return .= 'WP_DEBUG: ' . (defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set') . "\n"; $return .= 'Memory Limit: ' . WP_MEMORY_LIMIT . "\n"; $return .= 'Registered Post Stati: ' . implode(', ', get_post_stati()) . "\n"; $return = apply_filters('give_sysinfo_after_wordpress_config', $return); // GIVE configuration $return .= "\n" . '-- Give Configuration' . "\n\n"; $return .= 'Version: ' . GIVE_VERSION . "\n"; $return .= 'Upgraded From: ' . get_option('give_version_upgraded_from', 'None') . "\n"; $return .= 'Test Mode: ' . (give_is_test_mode() ? "Enabled\n" : "Disabled\n"); $return .= 'Currency Code: ' . give_get_currency() . "\n"; $return .= 'Currency Position: ' . give_get_option('currency_position', 'before') . "\n"; $return .= 'Decimal Separator: ' . give_get_option('decimal_separator', '.') . "\n"; $return .= 'Thousands Separator: ' . give_get_option('thousands_separator', ',') . "\n"; $return = apply_filters('give_sysinfo_after_give_config', $return); // GIVE pages $return .= "\n" . '-- Give Page Configuration' . "\n\n"; $return .= 'Success Page: ' . (!empty($give_options['success_page']) ? get_permalink($give_options['success_page']) . "\n" : "Unset\n"); $return .= 'Failure Page: ' . (!empty($give_options['failure_page']) ? get_permalink($give_options['failure_page']) . "\n" : "Unset\n"); $return .= 'Give Forms Slug: ' . (defined('GIVE_SLUG') ? '/' . GIVE_SLUG . "\n" : "/donations\n"); $return = apply_filters('give_sysinfo_after_give_pages', $return); // GIVE gateways $return .= "\n" . '-- Give Gateway Configuration' . "\n\n"; $active_gateways = give_get_enabled_payment_gateways(); if ($active_gateways) { $default_gateway_is_active = give_is_gateway_active(give_get_default_gateway(null)); if ($default_gateway_is_active) { $default_gateway = give_get_default_gateway(null); $default_gateway = $active_gateways[$default_gateway]['admin_label']; } else { $default_gateway = 'Test Payment'; } $gateways = array(); foreach ($active_gateways as $gateway) { $gateways[] = $gateway['admin_label']; } $return .= 'Enabled Gateways: ' . implode(', ', $gateways) . "\n"; $return .= 'Default Gateway: ' . $default_gateway . "\n"; } else { $return .= 'Enabled Gateways: None' . "\n"; } $return = apply_filters('give_sysinfo_after_give_gateways', $return); // GIVE Templates $dir = get_stylesheet_directory() . '/give_templates/*'; if (is_dir($dir) && count(glob("{$dir}/*")) !== 0) { $return .= "\n" . '-- Give Template Overrides' . "\n\n"; foreach (glob($dir) as $file) { $return .= 'Filename: ' . basename($file) . "\n"; } $return = apply_filters('give_sysinfo_after_give_templates', $return); } // Must-use plugins $muplugins = get_mu_plugins(); if (count($muplugins > 0)) { $return .= "\n" . '-- Must-Use Plugins' . "\n\n"; foreach ($muplugins as $plugin => $plugin_data) { $return .= $plugin_data['Name'] . ': ' . $plugin_data['Version'] . "\n"; } $return = apply_filters('give_sysinfo_after_wordpress_mu_plugins', $return); } // WordPress active plugins $return .= "\n" . '-- WordPress Active Plugins' . "\n\n"; $plugins = get_plugins(); $active_plugins = get_option('active_plugins', array()); foreach ($plugins as $plugin_path => $plugin) { if (!in_array($plugin_path, $active_plugins)) { continue; } $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } $return = apply_filters('give_sysinfo_after_wordpress_plugins', $return); // WordPress inactive plugins $return .= "\n" . '-- WordPress Inactive Plugins' . "\n\n"; foreach ($plugins as $plugin_path => $plugin) { if (in_array($plugin_path, $active_plugins)) { continue; } $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } $return = apply_filters('give_sysinfo_after_wordpress_plugins_inactive', $return); if (is_multisite()) { // WordPress Multisite active plugins $return .= "\n" . '-- Network Active Plugins' . "\n\n"; $plugins = wp_get_active_network_plugins(); $active_plugins = get_site_option('active_sitewide_plugins', array()); foreach ($plugins as $plugin_path) { $plugin_base = plugin_basename($plugin_path); if (!array_key_exists($plugin_base, $active_plugins)) { continue; } $plugin = get_plugin_data($plugin_path); $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } $return = apply_filters('give_sysinfo_after_wordpress_ms_plugins', $return); } // Server configuration (really just versioning) $return .= "\n" . '-- Webserver Configuration' . "\n\n"; $return .= 'PHP Version: ' . PHP_VERSION . "\n"; $return .= 'MySQL Version: ' . $wpdb->db_version() . "\n"; $return .= 'Webserver Info: ' . $_SERVER['SERVER_SOFTWARE'] . "\n"; $return = apply_filters('give_sysinfo_after_webserver_config', $return); // PHP configs... now we're getting to the important stuff $return .= "\n" . '-- PHP Configuration' . "\n\n"; $return .= 'Safe Mode: ' . (ini_get('safe_mode') ? 'Enabled' : 'Disabled' . "\n"); $return .= 'Memory Limit: ' . ini_get('memory_limit') . "\n"; $return .= 'Upload Max Size: ' . ini_get('upload_max_filesize') . "\n"; $return .= 'Post Max Size: ' . ini_get('post_max_size') . "\n"; $return .= 'Upload Max Filesize: ' . ini_get('upload_max_filesize') . "\n"; $return .= 'Time Limit: ' . ini_get('max_execution_time') . "\n"; $return .= 'Max Input Vars: ' . ini_get('max_input_vars') . "\n"; $return .= 'Display Errors: ' . (ini_get('display_errors') ? 'On (' . ini_get('display_errors') . ')' : 'N/A') . "\n"; $return = apply_filters('give_sysinfo_after_php_config', $return); // PHP extensions and such $return .= "\n" . '-- PHP Extensions' . "\n\n"; $return .= 'cURL: ' . (function_exists('curl_init') ? 'Supported' : 'Not Supported') . "\n"; $return .= 'fsockopen: ' . (function_exists('fsockopen') ? 'Supported' : 'Not Supported') . "\n"; $return .= 'SOAP Client: ' . (class_exists('SoapClient') ? 'Installed' : 'Not Installed') . "\n"; $return .= 'Suhosin: ' . (extension_loaded('suhosin') ? 'Installed' : 'Not Installed') . "\n"; $return = apply_filters('give_sysinfo_after_php_ext', $return); // Session stuff $return .= "\n" . '-- Session Configuration' . "\n\n"; $return .= 'Give Use Sessions: ' . (defined('GIVE_USE_PHP_SESSIONS') && GIVE_USE_PHP_SESSIONS ? 'Enforced' : (Give()->session->use_php_sessions() ? 'Enabled' : 'Disabled')) . "\n"; $return .= 'Session: ' . (isset($_SESSION) ? 'Enabled' : 'Disabled') . "\n"; // The rest of this is only relevant is session is enabled if (isset($_SESSION)) { $return .= 'Session Name: ' . esc_html(ini_get('session.name')) . "\n"; $return .= 'Cookie Path: ' . esc_html(ini_get('session.cookie_path')) . "\n"; $return .= 'Save Path: ' . esc_html(ini_get('session.save_path')) . "\n"; $return .= 'Use Cookies: ' . (ini_get('session.use_cookies') ? 'On' : 'Off') . "\n"; $return .= 'Use Only Cookies: ' . (ini_get('session.use_only_cookies') ? 'On' : 'Off') . "\n"; } $return = apply_filters('give_sysinfo_after_session_config', $return); $return .= "\n" . '### End System Info ###'; return $return; }
/** * Adds body classes for Give pages * * @since 1.0 * * @param array $class current classes * * @return array Modified array of classes */ function give_add_body_classes($class) { $classes = (array) $class; if (give_is_success_page()) { $classes[] = 'give-success'; $classes[] = 'give-page'; } if (give_is_failed_transaction_page()) { $classes[] = 'give-failed-transaction'; $classes[] = 'give-page'; } if (give_is_donation_history_page()) { $classes[] = 'give-donation-history'; $classes[] = 'give-page'; } if (give_is_test_mode()) { $classes[] = 'give-test-mode'; $classes[] = 'give-page'; } //Theme-specific Classes used to prevent conflicts via CSS $current_theme = wp_get_theme(); switch ($current_theme->template) { case 'Divi': $classes[] = 'give-divi'; break; case 'Avada': $classes[] = 'give-avada'; break; case 'twentysixteen': $classes[] = 'give-twentysixteen'; break; } return array_unique($classes); }
/** * Purchase Form Validate Gateway * * Validate the gateway and donation amount * * @access private * @since 1.0 * @return string */ function give_purchase_form_validate_gateway() { $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; $amount = isset($_REQUEST['give-amount']) ? give_sanitize_amount($_REQUEST['give-amount']) : 0; $gateway = give_get_default_gateway($form_id); // Check if a gateway value is present if (!empty($_REQUEST['give-gateway'])) { $gateway = sanitize_text_field($_REQUEST['give-gateway']); //Is amount being donated in LIVE mode 0.00? If so, error: if ($amount == 0 && !give_is_test_mode()) { give_set_error('invalid_donation_amount', esc_html__('Please insert a valid donation amount.', 'give')); } elseif (!give_verify_minimum_price()) { give_set_error('invalid_donation_minimum', sprintf(esc_html__('This form has a minimum donation amount of %s.', 'give'), give_currency_filter(give_format_amount(give_get_form_minimum_price($form_id))))); } elseif ($amount == 0 && give_is_test_mode()) { $gateway = 'manual'; } elseif (!give_is_gateway_active($gateway)) { give_set_error('invalid_gateway', esc_html__('The selected payment gateway is not enabled.', 'give')); } } return $gateway; }
/** * Insert Payment * * @since 1.0 * * @param array $payment_data Arguments passed * * @return int|bool Payment ID if payment is inserted, false otherwise */ function give_insert_payment($payment_data = array()) { if (empty($payment_data)) { return false; } $payment = new Give_Payment(); $gateway = !empty($payment_data['gateway']) ? $payment_data['gateway'] : ''; $gateway = empty($gateway) && isset($_POST['give-gateway']) ? $_POST['give-gateway'] : $gateway; $form_id = isset($payment_data['give_form_id']) ? $payment_data['give_form_id'] : 0; $price_id = isset($payment_data['give_price_id']) ? $payment_data['give_price_id'] : give_get_price_id($payment_data['give_form_id'], $payment_data['price']); $form_title = isset($payment_data['give_form_title']) ? $payment_data['give_form_title'] : get_the_title($form_id); //Set properties $payment->total = $payment_data['price']; $payment->status = !empty($payment_data['status']) ? $payment_data['status'] : 'pending'; $payment->currency = !empty($payment_data['currency']) ? $payment_data['currency'] : give_get_currency(); $payment->user_info = $payment_data['user_info']; $payment->gateway = $gateway; $payment->form_title = $form_title; $payment->form_id = $form_id; $payment->price_id = $price_id; $payment->user_id = $payment_data['user_info']['id']; $payment->email = $payment_data['user_email']; $payment->first_name = $payment_data['user_info']['first_name']; $payment->last_name = $payment_data['user_info']['last_name']; $payment->email = $payment_data['user_info']['email']; $payment->ip = give_get_ip(); $payment->key = $payment_data['purchase_key']; $payment->mode = give_is_test_mode() ? 'test' : 'live'; $payment->parent_payment = !empty($payment_data['parent']) ? absint($payment_data['parent']) : ''; //Add the donation $args = array('price' => $payment->total, 'price_id' => $payment->price_id, 'fees' => isset($payment_data['fees']) ? $payment_data['fees'] : array()); $payment->add_donation($payment->form_id, $args); //Set date if present if (isset($payment_data['post_date'])) { $payment->date = $payment_data['post_date']; } //Handle sequential payments if (give_get_option('enable_sequential')) { $number = give_get_next_payment_number(); $payment->number = give_format_payment_number($number); update_option('give_last_payment_number', $number); } // Clear the user's purchased cache delete_transient('give_user_' . $payment_data['user_info']['id'] . '_purchases'); //Save payment $payment->save(); //Hook it do_action('give_insert_payment', $payment->ID, $payment_data); //Return payment ID upon success if (!empty($payment->ID)) { return $payment->ID; } // Return false if no payment was inserted return false; }
/** * Purchase Form Validate Gateway * * @access private * @since 1.0 * @return string */ function give_purchase_form_validate_gateway() { $gateway = give_get_default_gateway($_REQUEST['give-form-id']); // Check if a gateway value is present if (!empty($_REQUEST['give-gateway'])) { $gateway = sanitize_text_field($_REQUEST['give-gateway']); //Is amount being donated in LIVE mode above 0.00? if ('0.00' == $_REQUEST['give-amount'] && !give_is_test_mode()) { give_set_error('invalid_donation_amount', __('Please insert a valid donation amount.', 'give')); } elseif (!give_verify_minimum_price()) { $minimum = give_currency_filter(give_format_amount(give_get_form_minimum_price($_REQUEST['give-form-id']))); $error_message = __('This form has a minimum donation amount of %s', 'give'); give_set_error('invalid_donation_minimum', sprintf($error_message, $minimum)); } elseif ('0.00' == $_REQUEST['give-amount'] && give_is_test_mode()) { $gateway = 'manual'; } elseif (!give_is_gateway_active($gateway)) { give_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'give')); } } return $gateway; }
/** * Undoes a donation, including the decrease of donations and earning stats. Used for when refunding or deleting a donation * * @since 1.0 * * @param int $form_id Form (Post) ID * @param int $payment_id Payment ID * * @return void */ function give_undo_purchase($form_id, $payment_id) { if (give_is_test_mode()) { return; } $amount = give_get_payment_amount($payment_id); // decrease earnings give_decrease_earnings($form_id, $amount); // decrease purchase count give_decrease_purchase_count($form_id); }
/** * Adds body classes for Give pages * * @since 1.0 * * @param array $classes current classes * * @return array Modified array of classes */ function give_add_body_classes($class) { $classes = (array) $class; if (give_is_success_page()) { $classes[] = 'give-success'; $classes[] = 'give-page'; } if (give_is_failed_transaction_page()) { $classes[] = 'give-failed-transaction'; $classes[] = 'give-page'; } if (give_is_donation_history_page()) { $classes[] = 'give-donation-history'; $classes[] = 'give-page'; } if (give_is_test_mode()) { $classes[] = 'give-test-mode'; $classes[] = 'give-page'; } return array_unique($classes); }
/** * Authorize.net Payments * * @param $purchase_data */ public function give_process_authorize_net_payment($purchase_data) { if (!isset($_POST['card_number']) || $_POST['card_number'] == '') { give_set_error('empty_card', __('You must enter a card number', 'give')); } if (!isset($_POST['card_name']) || $_POST['card_name'] == '') { give_set_error('empty_card_name', __('You must enter the name on your card', 'give')); } if (!isset($_POST['card_exp_month']) || $_POST['card_exp_month'] == '') { give_set_error('empty_month', __('You must enter an expiration month', 'give')); } if (!isset($_POST['card_exp_year']) || $_POST['card_exp_year'] == '') { give_set_error('empty_year', __('You must enter an expiration year', 'give')); } if (!isset($_POST['card_cvc']) || $_POST['card_cvc'] == '' || strlen($_POST['card_cvc']) < 3) { give_set_error('empty_cvc', __('You must enter a valid CVC', 'give')); } $errors = give_get_errors(); //No errors: Continue with payment processing if (!$errors) { //Include Authorize SDK require_once GIVE_AUTHORIZE_PLUGIN_DIR . '/includes/anet_php_sdk/AuthorizeNet.php'; if (!give_is_test_mode()) { //LIVE: $authorize_api_login = give_get_option('give_api_login'); $authorize_trans_key = give_get_option('give_transaction_key'); } else { //SANDBOX $authorize_api_login = give_get_option('give_authorize_sandbox_api_login'); $authorize_trans_key = give_get_option('give_authorize_sandbox_transaction_key'); } //Check for credentials entered if (empty($authorize_api_login) || empty($authorize_trans_key)) { give_set_error('error_id_here', __('Error: Missing API Login or Transaction key. Please enter them in the plugin settings.', 'give-authorize')); return; } //Proceed with Authorize AIM $transaction = new AuthorizeNetAIM($authorize_api_login, $authorize_trans_key); $transaction->VERIFY_PEER = false; //Sandbox or not? if (give_is_test_mode()) { $transaction->setSandbox(true); } else { $transaction->setSandbox(false); } $card_info = $purchase_data['card_info']; $card_names = explode(' ', $card_info['card_name']); $first_name = isset($card_names[0]) ? $card_names[0] : $purchase_data['user_info']['first_name']; if (!empty($card_names[1])) { unset($card_names[0]); $last_name = implode(' ', $card_names); } else { $last_name = $purchase_data['user_info']['last_name']; } $transaction->amount = $purchase_data['price']; $transaction->card_num = strip_tags(trim($card_info['card_number'])); $transaction->card_code = strip_tags(trim($card_info['card_cvc'])); $transaction->exp_date = strip_tags(trim($card_info['card_exp_month'])) . '/' . strip_tags(trim($card_info['card_exp_year'])); $transaction->description = give_get_purchase_summary($purchase_data); $transaction->first_name = $first_name; $transaction->last_name = $last_name; $transaction->address = $card_info['card_address'] . ' ' . $card_info['card_address_2']; $transaction->city = $card_info['card_city']; $transaction->country = $card_info['card_country']; $transaction->state = $card_info['card_state']; $transaction->zip = $card_info['card_zip']; $transaction->customer_ip = give_get_ip(); $transaction->email = $purchase_data['user_email']; $transaction->invoice_num = $purchase_data['purchase_key']; try { $response = $transaction->authorizeAndCapture(); if ($response->approved) { $payment_data = array('price' => $purchase_data['price'], 'give_form_title' => $purchase_data['post_data']['give-form-title'], 'give_form_id' => intval($purchase_data['post_data']['give-form-id']), 'price_id' => isset($purchase_data['post_data']['give-price-id']) ? intval($purchase_data['post_data']['give-price-id']) : '', 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => give_get_currency(), 'user_info' => $purchase_data['user_info'], 'status' => 'pending', 'gateway' => 'authorizenet'); $payment = give_insert_payment($payment_data); if ($payment) { give_update_payment_status($payment, 'publish'); give_send_to_success_page(); } else { give_set_error('authorize_error', __('Error: your payment could not be recorded. Please try again', 'give')); give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']); } } else { if (isset($response->response_reason_text)) { $error = $response->response_reason_text; } elseif (isset($response->error_message)) { $error = $response->error_message; } else { $error = ''; } if (strpos(strtolower($error), 'the credit card number is invalid') !== false) { give_set_error('invalid_card', __('Your card number is invalid', 'give')); } elseif (strpos(strtolower($error), 'this transaction has been declined') !== false) { give_set_error('invalid_card', __('Your card has been declined', 'give')); } elseif (isset($response->response_reason_text)) { give_set_error('api_error', $response->response_reason_text); } elseif (isset($response->error_message)) { give_set_error('api_error', $response->error_message); } else { give_set_error('api_error', sprintf(__('An error occurred. Error data: %s', 'give'), print_r($response, true))); } give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']); } } catch (AuthorizeNetException $e) { give_set_error('request_error', $e->getMessage()); give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']); } } else { give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']); } }
/** * Purchase Form Validate Gateway * * @access private * @since 1.0 * @return string */ function give_purchase_form_validate_gateway() { $gateway = give_get_default_gateway($_REQUEST['give-form-id']); // Check if a gateway value is present if (!empty($_REQUEST['give-gateway'])) { $gateway = sanitize_text_field($_REQUEST['give-gateway']); //Is amount being donated in LIVE mode above 0.00? if ('0.00' == $_REQUEST['give-amount'] && !give_is_test_mode()) { give_set_error('invalid_donation_amount', __('Please insert a valid donation amount.', 'give')); } elseif ('0.00' == $_REQUEST['give-amount'] && give_is_test_mode()) { $gateway = 'manual'; } elseif (!give_is_gateway_active($gateway)) { give_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'give')); } } return $gateway; }