/**
 *  Creates a shortcode to displays a "nag" (which can be styled with CSS targeting a class of 'my-custom-nag')
 *
 *  Sample shortcodes:
 *
 *  [givetotal total_goal="10,000" link="http://example.com"] displays "So far, we have raised $0 toward our goal of $10,000! Donate now"
 *  (where "0" will be replaced with total earnings from all forms, and "Donate Now" is linked to http://example.com)
 *
 *  [givetotal form_id="34" total_goal="10,000"] will display earnings for just form with an ID of 34.
 *
 *  [givetotal total_goal="9,000" message_before="Hey! We've raised " message_between=" of the " message_after=" we are trying to raise for this campaign!" link="http://example.com" link_text="Help Us Reach Our Goal." form_id="245"]
 *
 *  [givetotal total_goal= "5,000" multi_id="34,114,141"] will display earnings for the three forms with IDs 34, 114, and 141.
 *
 *  Note that "multi_id" will override "form_id", so don't use both.
 */
function my_give_display_earnings_shortcode($atts)
{
    $total = get_option('give_earnings_total', false);
    $atts = shortcode_atts(array('total_goal' => '10,000', 'link' => false, 'form_id' => false, 'multi_id' => '', 'message_before' => 'So far, we have raised ', 'message_between' => ' toward our goal of ', 'message_after' => '! ', 'link_text' => 'Donate Now'), $atts, 'givetotal');
    $donate_link = '';
    if ($atts['link'] != false) {
        $donate_link = ' <a href="' . $atts['link'] . '">' . $atts['link_text'] . '</a>';
    }
    if ($atts['form_id'] != false && is_numeric($atts['form_id'])) {
        $total = get_post_meta($atts['form_id'], '_give_form_earnings', true);
    }
    if ($atts['multi_id'] != false) {
        $total = 0;
        $new_array = preg_split("/,/", $atts['multi_id']);
        foreach ($new_array as $value) {
            $total += get_post_meta($value, '_give_form_earnings', true);
        }
    }
    $custom_nag = "<div class='my-custom-nag'>" . $atts['message_before'] . "<span class='my-give-currency'>" . give_currency_symbol(give_get_currency()) . "</span><span class='my-give-raised my-give-amount'>" . give_format_amount($total) . "</span>" . $atts['message_between'] . "<span class='my-give-currency'>" . give_currency_symbol(give_get_currency()) . "</span><span class='my-give-total my-give-amount'>" . $atts['total_goal'] . "</span>" . $atts['message_after'] . $donate_link . "</div>";
    return $custom_nag;
}
Example #2
0
/**
 * Given a currency determine the symbol to use. If no currency given, site default is used.
 * If no symbol is determine, the currency string is returned.
 *
 * @since  1.0
 *
 * @param  string $currency The currency string
 *
 * @return string           The symbol to use for the currency
 */
function give_currency_symbol($currency = '')
{
    if (empty($currency)) {
        $currency = give_get_currency();
    }
    switch ($currency) {
        case "GBP":
            $symbol = '&pound;';
            break;
        case "BRL":
            $symbol = 'R&#36;';
            break;
        case "EUR":
            $symbol = '&euro;';
            break;
        case "NOK":
            $symbol = 'Kr.';
            break;
        case "USD":
        case "AUD":
        case "CAD":
        case "HKD":
        case "MXN":
        case "SGD":
            $symbol = '&#36;';
            break;
        case "JPY":
            $symbol = '&yen;';
            break;
        default:
            $symbol = $currency;
            break;
    }
    return apply_filters('give_currency_symbol', $symbol, $currency);
}
Example #3
0
/**
 * Process PayPal Purchase
 *
 * @since 1.0
 *
 * @param array $purchase_data Purchase Data
 *
 * @return void
 */
function give_process_paypal_purchase($purchase_data)
{
    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) {
        wp_die(__('Nonce verification has failed', 'give'), __('Error', 'give'), array('response' => 403));
    }
    // Collect payment data
    $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']), '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' => 'paypal');
    // Record the pending payment
    $payment = give_insert_payment($payment_data);
    // Check payment
    if (!$payment) {
        // Record the error
        give_record_gateway_error(__('Payment Error', 'give'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'give'), json_encode($payment_data)), $payment);
        // Problems? send back
        give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']);
    } else {
        // Only send to PayPal if the pending payment is created successfully
        $listener_url = add_query_arg('give-listener', 'IPN', home_url('index.php'));
        // Get the success url
        $return_url = add_query_arg(array('payment-confirmation' => 'paypal', 'payment-id' => $payment), get_permalink(give_get_option('success_page')));
        // Get the PayPal redirect uri
        $paypal_redirect = trailingslashit(give_get_paypal_redirect()) . '?';
        //Item name - pass level name if variable priced
        $item_name = $purchase_data['post_data']['give-form-title'];
        if (give_has_variable_prices($purchase_data['post_data']['give-form-id']) && isset($purchase_data['post_data']['give-price-id'])) {
            $item_price_level_text = give_get_price_option_name($purchase_data['post_data']['give-form-id'], $purchase_data['post_data']['give-price-id']);
            //Is there any donation level text?
            if (!empty($item_price_level_text)) {
                $item_name .= ' - ' . $item_price_level_text;
            }
        }
        // Setup PayPal arguments
        $paypal_args = array('business' => give_get_option('paypal_email', false), 'email' => $purchase_data['user_email'], 'invoice' => $purchase_data['purchase_key'], 'amount' => $purchase_data['price'], 'item_name' => $item_name, 'no_shipping' => '1', 'shipping' => '0', 'no_note' => '1', 'currency_code' => give_get_currency(), 'charset' => get_bloginfo('charset'), 'custom' => $payment, 'rm' => '2', 'return' => $return_url, 'cancel_return' => give_get_failed_transaction_uri('?payment-id=' . $payment), 'notify_url' => $listener_url, 'page_style' => give_get_paypal_page_style(), 'cbt' => get_bloginfo('name'), 'bn' => 'WordImpress_Donate_Give_US');
        if (!empty($purchase_data['user_info']['address'])) {
            $paypal_args['address1'] = $purchase_data['user_info']['address']['line1'];
            $paypal_args['address2'] = $purchase_data['user_info']['address']['line2'];
            $paypal_args['city'] = $purchase_data['user_info']['address']['city'];
            $paypal_args['country'] = $purchase_data['user_info']['address']['country'];
        }
        if (give_get_option('paypal_button_type') === 'standard') {
            $paypal_extra_args = array('cmd' => '_xclick');
        } else {
            $paypal_extra_args = array('cmd' => '_donations');
        }
        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
        $paypal_args = apply_filters('give_paypal_redirect_args', $paypal_args, $purchase_data);
        // Build query
        $paypal_redirect .= http_build_query($paypal_args);
        // Fix for some sites that encode the entities
        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
        // Redirect to PayPal
        wp_redirect($paypal_redirect);
        exit;
    }
}
Example #4
0
/**
 * Process the payment
 *
 * @since  1.0
 * @return void
 */
function give_offline_process_payment($purchase_data)
{
    $purchase_summary = give_get_purchase_summary($purchase_data);
    // setup the payment details
    $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']), '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' => 'offline');
    // record the pending payment
    $payment = give_insert_payment($payment_data);
    if ($payment) {
        give_offline_send_admin_notice($payment);
        give_offline_send_donor_instructions($payment);
        give_send_to_success_page();
    } else {
        // if errors are present, send the user back to the donation form so they can be corrected
        give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']);
    }
}
Example #5
0
/**
 * Processes the purchase data and uses the Manual Payment gateway to record
 * the transaction in the Purchase History
 *
 * @since 1.0
 *
 * @param array $purchase_data Purchase Data
 *
 * @return void
 */
function give_manual_payment($purchase_data)
{
    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) {
        wp_die(esc_html__('Nonce verification has failed', 'give'), esc_html__('Error', 'give'), array('response' => 403));
    }
    //Create payment_data array
    $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']), 'give_price_id' => isset($purchase_data['post_data']['give-price-id']) ? $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');
    // Record the pending payment
    $payment = give_insert_payment($payment_data);
    if ($payment) {
        give_update_payment_status($payment, 'publish');
        give_send_to_success_page();
    } else {
        give_record_gateway_error(esc_html__('Payment Error', 'give'), sprintf(esc_html__('The payment creation failed while processing a manual (free or test) donation. Payment data: %s', 'give'), json_encode($payment_data)), $payment);
        // If errors are present, send the user back to the purchase page so they can be corrected
        give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']);
    }
}
Example #6
0
/**
 * Process PayPal Purchase.
 *
 * @since 1.0
 *
 * @param array $purchase_data Purchase Data
 *
 * @return void
 */
function give_process_paypal_purchase($purchase_data)
{
    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) {
        wp_die(esc_html__('Nonce verification has failed.', 'give'), esc_html__('Error', 'give'), array('response' => 403));
    }
    $form_id = intval($purchase_data['post_data']['give-form-id']);
    $price_id = isset($purchase_data['post_data']['give-price-id']) ? $purchase_data['post_data']['give-price-id'] : '';
    // Collect payment data.
    $payment_data = array('price' => $purchase_data['price'], 'give_form_title' => $purchase_data['post_data']['give-form-title'], 'give_form_id' => $form_id, 'give_price_id' => $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' => 'paypal');
    // Record the pending payment.
    $payment_id = give_insert_payment($payment_data);
    // Check payment.
    if (!$payment_id) {
        // Record the error.
        give_record_gateway_error(esc_html__('Payment Error', 'give'), sprintf(esc_html__('Payment creation failed before sending donor to PayPal. Payment data: %s', 'give'), json_encode($payment_data)), $payment_id);
        // Problems? Send back.
        give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']);
    } else {
        // Only send to PayPal if the pending payment is created successfully.
        $listener_url = add_query_arg('give-listener', 'IPN', home_url('index.php'));
        // Get the success url.
        $return_url = add_query_arg(array('payment-confirmation' => 'paypal', 'payment-id' => $payment_id), get_permalink(give_get_option('success_page')));
        // Get the PayPal redirect uri.
        $paypal_redirect = trailingslashit(give_get_paypal_redirect()) . '?';
        //Item name - pass level name if variable priced.
        $item_name = $purchase_data['post_data']['give-form-title'];
        //Verify has variable prices.
        if (give_has_variable_prices($form_id) && isset($purchase_data['post_data']['give-price-id'])) {
            $item_price_level_text = give_get_price_option_name($form_id, $purchase_data['post_data']['give-price-id']);
            $price_level_amount = give_get_price_option_amount($form_id, $purchase_data['post_data']['give-price-id']);
            //Donation given doesn't match selected level (must be a custom amount).
            if ($price_level_amount != give_sanitize_amount($purchase_data['price'])) {
                $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true);
                //user custom amount text if any, fallback to default if not.
                $item_name .= ' - ' . (!empty($custom_amount_text) ? $custom_amount_text : esc_html__('Custom Amount', 'give'));
            } elseif (!empty($item_price_level_text)) {
                $item_name .= ' - ' . $item_price_level_text;
            }
        } elseif (give_get_form_price($form_id) !== give_sanitize_amount($purchase_data['price'])) {
            $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true);
            //user custom amount text if any, fallback to default if not.
            $item_name .= ' - ' . (!empty($custom_amount_text) ? $custom_amount_text : esc_html__('Custom Amount', 'give'));
        }
        // Setup PayPal API params.
        $paypal_args = array('business' => give_get_option('paypal_email', false), 'first_name' => $purchase_data['user_info']['first_name'], 'last_name' => $purchase_data['user_info']['last_name'], 'email' => $purchase_data['user_email'], 'invoice' => $purchase_data['purchase_key'], 'amount' => $purchase_data['price'], 'item_name' => stripslashes($item_name), 'no_shipping' => '1', 'shipping' => '0', 'no_note' => '1', 'currency_code' => give_get_currency(), 'charset' => get_bloginfo('charset'), 'custom' => $payment_id, 'rm' => '2', 'return' => $return_url, 'cancel_return' => give_get_failed_transaction_uri('?payment-id=' . $payment_id), 'notify_url' => $listener_url, 'page_style' => give_get_paypal_page_style(), 'cbt' => get_bloginfo('name'), 'bn' => 'givewp_SP');
        //Add user address if present.
        if (!empty($purchase_data['user_info']['address'])) {
            $paypal_args['address1'] = isset($purchase_data['user_info']['address']['line1']) ? $purchase_data['user_info']['address']['line1'] : '';
            $paypal_args['address2'] = isset($purchase_data['user_info']['address']['line2']) ? $purchase_data['user_info']['address']['line2'] : '';
            $paypal_args['city'] = isset($purchase_data['user_info']['address']['city']) ? $purchase_data['user_info']['address']['city'] : '';
            $paypal_args['state'] = isset($purchase_data['user_info']['address']['state']) ? $purchase_data['user_info']['address']['state'] : '';
            $paypal_args['country'] = isset($purchase_data['user_info']['address']['country']) ? $purchase_data['user_info']['address']['country'] : '';
        }
        //Donations or regular transactions?
        if (give_get_option('paypal_button_type') === 'standard') {
            $paypal_extra_args = array('cmd' => '_xclick');
        } else {
            $paypal_extra_args = array('cmd' => '_donations');
        }
        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
        $paypal_args = apply_filters('give_paypal_redirect_args', $paypal_args, $purchase_data);
        // Build query.
        $paypal_redirect .= http_build_query($paypal_args);
        // Fix for some sites that encode the entities.
        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
        // Redirect to PayPal.
        wp_redirect($paypal_redirect);
        exit;
    }
}
Example #7
0
/**
 * 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;
}
Example #8
0
 /**
  * Define General Settings Metabox and field configurations.
  *
  * Filters are provided for each settings section to allow add-ons and other plugins to add their own settings
  *
  * @param $active_tab active tab settings; null returns full array
  *
  * @return array
  */
 public function give_settings($active_tab)
 {
     $give_settings = array('general' => array('id' => 'options_page', 'give_title' => __('General Settings', 'give'), 'show_on' => array('key' => 'options-page', 'value' => array($this->key)), 'fields' => apply_filters('give_settings_general', array(array('name' => __('General Settings', 'give'), 'desc' => '', 'type' => 'give_title', 'id' => 'give_title_general_settings_1'), array('name' => __('Success Page', 'give'), 'desc' => sprintf(__('This is the page donors are sent to after completing their donations. The %1$s[give_receipt]%2$s shortcode should be on this page.', 'give'), '<code>', '</code>'), 'id' => 'success_page', 'type' => 'select', 'options' => give_cmb2_get_post_options(array('post_type' => 'page', 'numberposts' => -1))), array('name' => __('Failed Transaction Page', 'give'), 'desc' => __('This is the page donors are sent to if their transaction is cancelled or fails.', 'give'), 'id' => 'failure_page', 'type' => 'select', 'options' => give_cmb2_get_post_options(array('post_type' => 'page', 'numberposts' => -1))), array('name' => __('Donation History Page', 'give'), 'desc' => sprintf(__('This page shows a complete donation history for the current user. The %1$s[donation_history]%2$s shortcode should be on this page.', 'give'), '<code>', '</code>'), 'id' => 'history_page', 'type' => 'select', 'options' => give_cmb2_get_post_options(array('post_type' => 'page', 'numberposts' => -1))), array('name' => __('Base Country', 'give'), 'desc' => __('Where does your site operate from?', 'give'), 'id' => 'base_country', 'type' => 'select', 'options' => give_get_country_list()), array('name' => __('Currency Settings', 'give'), 'desc' => '', 'type' => 'give_title', 'id' => 'give_title_general_settings_2'), array('name' => __('Currency', 'give'), 'desc' => 'Choose your currency. Note that some payment gateways have currency restrictions.', 'id' => 'currency', 'type' => 'select', 'options' => give_get_currencies(), 'default' => 'USD'), array('name' => __('Currency Position', 'give'), 'desc' => 'Choose the position of the currency sign.', 'id' => 'currency_position', 'type' => 'select', 'options' => array('before' => sprintf(__('Before - %1$s10', 'give'), give_currency_symbol(give_get_currency())), 'after' => sprintf(__('After - 10%1$s', 'give'), give_currency_symbol(give_get_currency()))), 'default' => 'before'), array('name' => __('Thousands Separator', 'give'), 'desc' => __('The symbol (typically , or .) to separate thousands', 'give'), 'id' => 'thousands_separator', 'type' => 'text_small', 'default' => ','), array('name' => __('Decimal Separator', 'give'), 'desc' => __('The symbol (usually , or .) to separate decimal points', 'give'), 'id' => 'decimal_separator', 'type' => 'text_small', 'default' => '.')))), 'gateways' => array('id' => 'options_page', 'give_title' => __('Payment Gateways', 'give'), 'show_on' => array('key' => 'options-page', 'value' => array($this->key)), 'fields' => apply_filters('give_settings_gateways', array(array('name' => __('Gateways Settings', 'give'), 'desc' => '', 'id' => 'give_title_gateway_settings_1', 'type' => 'give_title'), array('name' => __('Test Mode', 'give'), 'desc' => __('While in test mode no live transactions are processed. To fully use test mode, you must have a sandbox (test) account for the payment gateway you are testing.', 'give'), 'id' => 'test_mode', 'type' => 'checkbox'), array('name' => __('Enabled Gateways', 'give'), 'desc' => __('Choose the payment gateways you would like enabled.', 'give'), 'id' => 'gateways', 'type' => 'enabled_gateways'), array('name' => __('Default Gateway', 'give'), 'desc' => __('This is the gateway that will be selected by default.', 'give'), 'id' => 'default_gateway', 'type' => 'default_gateway'), array('name' => __('PayPal Standard', 'give'), 'desc' => '', 'type' => 'give_title', 'id' => 'give_title_gateway_settings_2'), array('name' => __('PayPal Email', 'give'), 'desc' => __('Enter your PayPal account\'s email', 'give'), 'id' => 'paypal_email', 'type' => 'text_email'), array('name' => __('PayPal Page Style', 'give'), 'desc' => __('Enter the name of the page style to use, or leave blank to use the default', 'give'), 'id' => 'paypal_page_style', 'type' => 'text'), array('name' => __('PayPal Transaction Type', 'give'), 'desc' => __('Nonprofits must verify their status to withdraw donations they receive via PayPal. PayPal users that are not verified nonprofits must demonstrate how their donations will be used, once they raise more than $10,000. By default, Give transactions are sent to PayPal as donations. You may change the transaction type using this option if you feel you may not meet PayPal\'s donation requirements.', 'give'), 'id' => 'paypal_button_type', 'type' => 'radio_inline', 'options' => array('donation' => __('Donation', 'give'), 'standard' => __('Standard Transaction', 'give')), 'default' => 'donation'), array('name' => __('Disable PayPal IPN Verification', 'give'), 'desc' => __('If donations are not getting marked as complete, then check this box. This forces the site to use a slightly less secure method of verifying donations.', 'give'), 'id' => 'disable_paypal_verification', 'type' => 'checkbox'), array('name' => __('Offline Donations', 'give'), 'desc' => '', 'type' => 'give_title', 'id' => 'give_title_gateway_settings_3'), array('name' => __('Collect Billing Details', 'give'), 'desc' => __('This option will enable the billing details section for offline donations. The fieldset will appear above the offline donation instructions. Note: You may customize this option per form as needed.', 'give'), 'id' => 'give_offline_donation_enable_billing_fields', 'type' => 'checkbox'), array('name' => __('Offline Donation Instructions', 'give'), 'desc' => __('The following content will appear for all forms when the user selects the offline donation payment option. Note: You may customize the content per form as needed.', 'give'), 'id' => 'global_offline_donation_content', 'default' => give_get_default_offline_donation_content(), 'type' => 'wysiwyg', 'options' => array('textarea_rows' => 6)), array('name' => __('Offline Donation Email Instructions Subject', 'give'), 'desc' => __('Enter the subject line for the donation receipt email.', 'give'), 'id' => 'offline_donation_subject', 'default' => __('{donation} - Offline Donation Instructions', 'give'), 'type' => 'text'), array('name' => __('Offline Donation Email Instructions', 'give'), 'desc' => __('Enter the instructions you want emailed to the donor after they have submitted the donation form. Most likely this would include important information like mailing address and who to make the check out to.', 'give'), 'id' => 'global_offline_donation_email', 'default' => give_get_default_offline_donation_email_content(), 'type' => 'wysiwyg', 'options' => array('textarea_rows' => 6))))), 'display' => array('id' => 'options_page', 'give_title' => __('Display Settings', 'give'), 'show_on' => array('key' => 'options-page', 'value' => array($this->key)), 'fields' => apply_filters('give_settings_display', array(array('name' => __('Display Settings', 'give'), 'desc' => '', 'id' => 'give_title_display_settings_1', 'type' => 'give_title'), array('name' => __('Disable CSS', 'give'), 'desc' => __('Enable this option if you would like to disable all of Give\'s included CSS stylesheets.', 'give'), 'id' => 'disable_css', 'type' => 'checkbox'), array('name' => __('Enable Floating Labels', 'give'), 'desc' => sprintf(esc_html__('Enable this option if you would like to enable %1$sfloating labels%2$s in Give\'s donation forms. %3$sBe aware that if you have the "Disable CSS" option enabled, you will need to style the floating labels yourself.', 'give'), '<a href="' . esc_url("http://bradfrost.com/blog/post/float-label-pattern/") . '" target="_blank">', '</a>', '<br />'), 'id' => 'enable_floatlabels', 'type' => 'checkbox'), array('name' => __('Disable Welcome Screen', 'give'), 'desc' => sprintf(esc_html__('Enable this option if you would like to disable the Give Welcome screen every time Give is activated and/or updated. You can always access the Welcome Screen %1$shere%2$s if you want in the future.', 'give'), '<a href="' . esc_url(admin_url('index.php?page=give-about')) . '">', '</a>'), 'id' => 'disable_welcome', 'type' => 'checkbox'), array('name' => __('Post Types', 'give'), 'desc' => '', 'id' => 'give_title_display_settings_2', 'type' => 'give_title'), array('name' => __('Disable Form Single Views', 'give'), 'desc' => __('By default, all forms have single views enabled which create a specific URL on your website for that form. This option disables the singular and archive views from being publicly viewable. Note: you will need to embed forms using a shortcode or widget if enabled.', 'give'), 'id' => 'disable_forms_singular', 'type' => 'checkbox'), array('name' => __('Disable Form Archives', 'give'), 'desc' => __('Archives pages list all the forms you have created. This option will disable only the form\'s archive page(s). The single form\'s view will remain in place. Note: you will need to refresh your permalinks after this option has been enabled.', 'give'), 'id' => 'disable_forms_archives', 'type' => 'checkbox'), array('name' => __('Disable Form Excerpts', 'give'), 'desc' => __('The excerpt is an optional summary or description of a donation form; in short, a summary as to why the user should give.', 'give'), 'id' => 'disable_forms_excerpt', 'type' => 'checkbox'), array('name' => __('Featured Image Size', 'give'), 'desc' => __('The Featured Image is an image that is chosen as the representative image for a donation form. Some themes may have custom featured image sizes. Please select the size you would like to display for your single donation forms\' featured image.', 'give'), 'id' => 'featured_image_size', 'type' => 'select', 'default' => 'large', 'options' => give_get_featured_image_sizes()), array('name' => __('Disable Form Featured Image', 'give'), 'desc' => __('If you do not wish to use the featured image functionality you can disable it using this option and it will not be displayed for single donation forms.', 'give'), 'id' => 'disable_form_featured_img', 'type' => 'checkbox'), array('name' => __('Disable Single Form Sidebar', 'give'), 'desc' => __('The sidebar allows you to add additional widget to the Give single form view. If you don\'t plan on using the sidebar you may disable it with this option.', 'give'), 'id' => 'disable_form_sidebar', 'type' => 'checkbox'), array('name' => __('Taxonomies', 'give'), 'desc' => '', 'id' => 'give_title_display_settings_3', 'type' => 'give_title'), array('name' => __('Enable Form Categories', 'give'), 'desc' => __('Check this option if you would like to categorize your donation forms. This option enables the form\'s category taxonomy.', 'give'), 'id' => 'enable_categories', 'type' => 'checkbox'), array('name' => __('Enable Form Tags', 'give'), 'desc' => __('Check this option if you would like to tag your donation forms. This option enables the form\'s tag taxonomy.', 'give'), 'id' => 'enable_tags', 'type' => 'checkbox')))), 'emails' => array('id' => 'options_page', 'give_title' => __('Give Email Settings', 'give'), 'show_on' => array('key' => 'options-page', 'value' => array($this->key)), 'fields' => apply_filters('give_settings_emails', array(array('name' => __('Email Settings', 'give'), 'desc' => '', 'id' => 'give_title_email_settings_1', 'type' => 'give_title'), array('id' => 'email_template', 'name' => __('Email Template', 'give'), 'desc' => __('Choose a template. Click "Save Changes" then "Preview Donation Receipt" to see the new template.', 'give'), 'type' => 'select', 'options' => give_get_email_templates()), array('id' => 'email_logo', 'name' => __('Logo', 'give'), 'desc' => __('Upload or choose a logo to be displayed at the top of the donation receipt emails. Displayed on HTML emails only.', 'give'), 'type' => 'file'), array('id' => 'from_name', 'name' => __('From Name', 'give'), 'desc' => __('The name donation receipts are said to come from. This should probably be your site or shop name.', 'give'), 'default' => get_bloginfo('name'), 'type' => 'text'), array('id' => 'from_email', 'name' => __('From Email', 'give'), 'desc' => __('Email to send donation receipts from. This will act as the "from" and "reply-to" address.', 'give'), 'default' => get_bloginfo('admin_email'), 'type' => 'text'), array('name' => __('Donation Receipt', 'give'), 'desc' => '', 'id' => 'give_title_email_settings_2', 'type' => 'give_title'), array('id' => 'donation_subject', 'name' => __('Donation Email Subject', 'give'), 'desc' => __('Enter the subject line for the donation receipt email', 'give'), 'default' => __('Donation Receipt', 'give'), 'type' => 'text'), array('id' => 'donation_receipt', 'name' => __('Donation Receipt', 'give'), 'desc' => __('Enter the email that is sent to users after completing a successful donation. HTML is accepted. Available template tags:', 'give') . '<br/>' . give_get_emails_tags_list(), 'type' => 'wysiwyg', 'default' => give_get_default_donation_receipt_email()), array('name' => __('New Donation Notification', 'give'), 'desc' => '', 'id' => 'give_title_email_settings_3', 'type' => 'give_title'), array('id' => 'donation_notification_subject', 'name' => __('Donation Notification Subject', 'give'), 'desc' => __('Enter the subject line for the donation notification email', 'give'), 'type' => 'text', 'default' => __('New Donation - #{payment_id}', 'give')), array('id' => 'donation_notification', 'name' => __('Donation Notification', 'give'), 'desc' => __('Enter the email that is sent to donation notification emails after completion of a donation. HTML is accepted. Available template tags:', 'give') . '<br/>' . give_get_emails_tags_list(), 'type' => 'wysiwyg', 'default' => give_get_default_donation_notification_email()), array('id' => 'admin_notice_emails', 'name' => __('Donation Notification Emails', 'give'), 'desc' => sprintf(__('Enter the email address(es) that should receive a notification anytime a donation is made, please only enter %1$sone email address per line%2$s and not separated by commas.', 'give'), '<span class="give-underline">', '</span>'), 'type' => 'textarea', 'default' => get_bloginfo('admin_email')), array('id' => 'disable_admin_notices', 'name' => __('Disable Admin Notifications', 'give'), 'desc' => __('Check this box if you do not want to receive emails when new donations are made.', 'give'), 'type' => 'checkbox')))), 'addons' => array('id' => 'options_page', 'give_title' => __('Give Add-ons Settings', 'give'), 'show_on' => array('key' => 'options-page', 'value' => array($this->key)), 'fields' => apply_filters('give_settings_addons', array())), 'licenses' => array('id' => 'options_page', 'give_title' => __('Give Licenses', 'give'), 'show_on' => array('key' => 'options-page', 'value' => array($this->key)), 'fields' => apply_filters('give_settings_licenses', array())), 'advanced' => array('id' => 'options_page', 'give_title' => __('Advanced Options', 'give'), 'show_on' => array('key' => 'options-page', 'value' => array($this->key)), 'fields' => apply_filters('give_settings_advanced', array(array('name' => __('Access Control', 'give'), 'desc' => '', 'id' => 'give_title_session_control_1', 'type' => 'give_title'), array('id' => 'session_lifetime', 'name' => __('Session Lifetime', 'give'), 'desc' => __('Give will start a new session per user once they have donated. This option controls the lifetime a user\'s session is kept alive. An active session allows users to view donation receipts on your site without having to be logged in as long as they are using the same browser they used when donating.', 'give'), 'type' => 'select', 'options' => array('86400' => __('24 Hours', 'give'), '172800' => __('48 Hours', 'give'), '259200' => __('72 Hours', 'give'), '604800' => __('1 Week', 'give'))), array('name' => __('Email Access', 'give'), 'desc' => __('Would you like your donors to be able to access their donation history using only email? Donors whose sessions have expired and do not have an account may still access their donation history via a temporary email access link.', 'give'), 'id' => 'email_access', 'type' => 'checkbox'), array('id' => 'recaptcha_key', 'name' => __('reCAPTCHA Site Key', 'give'), 'desc' => sprintf(__('If you would like to prevent spam on the email access form navigate to %1$sthe reCAPTCHA website%2$s and sign up for an API key. The reCAPTCHA uses Google\'s user-friendly single click verification method.', 'give'), '<a href="https://www.google.com/recaptcha/" target="_blank">', '</a>'), 'default' => '', 'type' => 'text'), array('id' => 'recaptcha_secret', 'name' => __('reCAPTCHA Secret Key', 'give'), 'desc' => __('Please paste the reCAPTCHA secret key here from your manage reCAPTCHA API Keys panel.', 'give'), 'default' => '', 'type' => 'text'), array('name' => __('Data Control', 'give'), 'desc' => '', 'id' => 'give_title_data_control_2', 'type' => 'give_title'), array('name' => __('Remove All Data on Uninstall?', 'give'), 'desc' => __('Check this box if you would like Give to completely remove all of its data when the plugin is deleted.', 'give'), 'id' => 'uninstall_on_delete', 'type' => 'checkbox'), array('name' => __('Filter Control', 'give'), 'desc' => '', 'id' => 'give_title_filter_control', 'type' => 'give_title'), array('name' => __('Disable <code>the_content</code> filter', 'give'), 'desc' => sprintf(__('If you are seeing extra social buttons, related posts, or other unwanted elements appearing within your forms then you can disable WordPress\' content filter. <a href="%s" target="_blank">Learn more</a> about the_content filter.', 'give'), esc_url('https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content')), 'id' => 'disable_the_content_filter', 'type' => 'checkbox'), array('name' => __('Script Loading', 'give'), 'desc' => '', 'id' => 'give_title_script_control', 'type' => 'give_title'), array('name' => __('Load Scripts in Footer?', 'give'), 'desc' => __('Check this box if you would like Give to load all frontend JavaScript files in the footer.', 'give'), 'id' => 'scripts_footer', 'type' => 'checkbox')))), 'api' => array('id' => 'options_page', 'give_title' => __('API', 'give'), 'show_on' => array('key' => 'options-page', 'value' => array($this->key)), 'show_names' => false, 'fields' => apply_filters('give_settings_system', array(array('id' => 'api', 'name' => __('API', 'give'), 'type' => 'api')))), 'system_info' => array('id' => 'options_page', 'give_title' => __('System Info', 'give'), 'show_on' => array('key' => 'options-page', 'value' => array($this->key)), 'fields' => apply_filters('give_settings_system', array(array('id' => 'system_info', 'name' => __('System Info', 'give'), 'desc' => __('Please copy and paste this information in your ticket when contacting support.', 'give'), 'type' => 'system_info')))));
     //Return all settings array if necessary
     if ($active_tab === null || !isset($give_settings[$active_tab])) {
         return apply_filters('give_registered_settings', $give_settings);
     }
     // Add other tabs and settings fields as needed
     return apply_filters('give_registered_settings', $give_settings[$active_tab]);
 }
Example #9
0
/**
 * 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;
}
Example #10
0
 /**
  * Process purchase.
  *
  * @since 1.0.0
  *
  * @param array $purchase_data Purchase Data
  *
  * @return void
  */
 function process_purchase($purchase_data)
 {
     if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) {
         wp_die(__('Nonce verification has failed', 'pronamic_ideal'), __('Error', 'pronamic_ideal'), array('response' => 403));
     }
     $form_id = intval($purchase_data['post_data']['give-form-id']);
     // Collect payment data
     $payment_data = array('price' => $purchase_data['price'], 'give_form_title' => $purchase_data['post_data']['give-form-title'], 'give_form_id' => $form_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' => $this->id);
     // Record the pending payment
     $donation_id = give_insert_payment($payment_data);
     if (!$donation_id) {
         // Record the error
         // /wp-admin/edit.php?post_type=give_forms&page=give-reports&tab=logs&view=gateway_errors
         // @see https://github.com/WordImpress/Give/blob/1.3.6/includes/gateways/functions.php#L267-L285
         give_record_gateway_error(__('Payment Error', 'pronamic_ideal'), sprintf(__('Payment creation failed before sending buyer to payment provider. Payment data: %s', 'pronamic_ideal'), json_encode($payment_data)), $donation_id);
         // Problems? send back
         // @see https://github.com/WordImpress/Give/blob/1.3.6/includes/forms/functions.php#L150-L184
         give_send_back_to_checkout(array('payment-error' => true, 'payment-mode' => $purchase_data['post_data']['give-gateway']));
     } else {
         $config_id = give_get_option(sprintf('give_%s_configuration', $this->id));
         $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id);
         if ($gateway) {
             // Data
             $data = new Pronamic_WP_Pay_Extensions_Give_PaymentData($donation_id, $this);
             $gateway->set_payment_method($this->payment_method);
             $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data, $this->payment_method);
             $error = $gateway->get_error();
             if (is_wp_error($error)) {
                 // Record the error
                 // /wp-admin/edit.php?post_type=give_forms&page=give-reports&tab=logs&view=gateway_errors
                 // @see https://github.com/WordImpress/Give/blob/1.3.6/includes/gateways/functions.php#L267-L285
                 give_record_gateway_error(__('Payment Error', 'pronamic_ideal'), implode('<br />', $error->get_error_messages()), $donation_id);
                 // Problems? send back
                 // @see https://github.com/WordImpress/Give/blob/1.3.6/includes/forms/functions.php#L150-L184
                 give_send_back_to_checkout(array('payment-error' => true, 'payment-mode' => $purchase_data['post_data']['give-gateway']));
             } else {
                 // Redirect
                 $gateway->redirect($payment);
             }
         }
     }
 }
Example #11
0
/**
 * Get the currency code a payment was made in
 *
 * @since 1.0
 *
 * @param int $payment_id Payment ID
 *
 * @return string $currency The currency code
 */
function give_get_payment_currency_code($payment_id = 0)
{
    $meta = give_get_payment_meta($payment_id);
    $currency = isset($meta['currency']) ? $meta['currency'] : give_get_currency();
    return apply_filters('give_payment_currency_code', $currency, $payment_id);
}
Example #12
0
/**
 * Set the number of decimal places per currency
 *
 * @since 1.0
 *
 * @param int $decimals Number of decimal places
 *
 * @return int $decimals
 */
function give_currency_decimal_filter($decimals = 2)
{
    $currency = give_get_currency();
    switch ($currency) {
        case 'RIAL':
        case 'JPY':
        case 'TWD':
        case 'HUF':
            $decimals = 0;
            break;
    }
    return apply_filters('give_currency_decimal_count', $decimals, $currency);
}
Example #13
0
/**
 * Donation Amount Field
 *
 * Outputs the donation amount field that appears at the top of the donation forms. If the user has custom amount enabled the field will output as a customizable input
 *
 * @since  1.0
 *
 * @param  int   $form_id Give Form ID
 * @param  array $args
 *
 * @return void
 */
function give_output_donation_amount_top($form_id = 0, $args = array())
{
    global $give_options;
    $variable_pricing = give_has_variable_prices($form_id);
    $allow_custom_amount = get_post_meta($form_id, '_give_custom_amount', true);
    $currency_position = isset($give_options['currency_position']) ? $give_options['currency_position'] : 'before';
    $symbol = give_currency_symbol(give_get_currency());
    $currency_output = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>';
    $default_amount = give_format_amount(give_get_default_form_amount($form_id));
    $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true);
    do_action('give_before_donation_levels', $form_id, $args);
    //Set Price, No Custom Amount Allowed means hidden price field
    if ($allow_custom_amount == 'no') {
        ?>

		<label class="give-hidden" for="give-amount-hidden"><?php 
        echo esc_html__('Donation Amount:', 'give');
        ?>
</label>
		<input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount"
		       value="<?php 
        echo $default_amount;
        ?>
" required>
		<div class="set-price give-donation-amount form-row-wide">
			<?php 
        if ($currency_position == 'before') {
            echo $currency_output;
        }
        ?>
			<span id="give-amount-text" class="give-text-input give-amount-top"><?php 
        echo $default_amount;
        ?>
</span>
			<?php 
        if ($currency_position == 'after') {
            echo $currency_output;
        }
        ?>
		</div>
		<?php 
    } else {
        //Custom Amount Allowed
        ?>
		<div class="give-total-wrap">
			<div class="give-donation-amount form-row-wide">
				<?php 
        if ($currency_position == 'before') {
            echo $currency_output;
        }
        ?>
				<label class="give-hidden" for="give-amount"><?php 
        echo esc_html__('Donation Amount:', 'give');
        ?>
</label>
				<input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="tel" placeholder="" value="<?php 
        echo $default_amount;
        ?>
" autocomplete="off">
				<?php 
        if ($currency_position == 'after') {
            echo $currency_output;
        }
        ?>
			</div>
		</div>
	<?php 
    }
    do_action('give_after_donation_amount', $form_id, $args);
    //Custom Amount Text
    if (!$variable_pricing && $allow_custom_amount == 'yes' && !empty($custom_amount_text)) {
        ?>
		<p class="give-custom-amount-text"><?php 
        echo $custom_amount_text;
        ?>
</p>
	<?php 
    }
    //Output Variable Pricing Levels
    if ($variable_pricing) {
        give_output_levels($form_id);
    }
    do_action('give_after_donation_levels', $form_id, $args);
}
 /**
  * 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']);
     }
 }
Example #15
0
 /**
  * Setup the currency code
  *
  * @since  1.5
  * @access private
  *
  * @return string The currency for the payment
  */
 private function setup_currency()
 {
     $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('give_payment_currency_default', give_get_currency(), $this);
     return $currency;
 }
Example #16
0
/**
 * Give Currency Symbol
 *
 * @description: Given a currency determine the symbol to use. If no currency given, site default is used. If no symbol is determine, the currency string is returned.
 *
 * @since      1.0
 *
 * @param  string $currency The currency string
 *
 * @return string           The symbol to use for the currency
 */
function give_currency_symbol($currency = '')
{
    if (empty($currency)) {
        $currency = give_get_currency();
    }
    switch ($currency) {
        case 'GBP':
            $symbol = '£';
            break;
        case 'BRL':
            $symbol = 'R$';
            break;
        case 'EUR':
            $symbol = '€';
            break;
        case 'NOK':
            $symbol = 'Kr.';
            break;
        case 'INR':
            $symbol = '₹';
            break;
        case 'USD':
        case 'AUD':
        case 'CAD':
        case 'HKD':
        case 'MXN':
        case 'SGD':
            $symbol = '$';
            break;
        case 'JPY':
            $symbol = '¥';
            break;
        case 'THB':
            $symbol = '฿';
            break;
        case 'TRY':
            $symbol = '₺';
            break;
        case 'TWD':
            $symbol = 'NT$';
            break;
        case 'ILS':
            $symbol = '₪';
            break;
        case 'RIAL':
            $symbol = '﷼';
            break;
        case 'RUB':
            $symbol = 'руб';
            break;
        case 'DKK':
        case 'SEK':
            $symbol = 'kr';
            break;
        case 'PLN':
            $symbol = 'zł';
            break;
        case 'PHP':
            $symbol = '₱';
            break;
        case 'MYR':
            $symbol = 'RM';
            break;
        case 'HUF':
            $symbol = 'Ft';
            break;
        case 'CZK':
            $symbol = 'Kč';
            break;
        default:
            $symbol = $currency;
            break;
    }
    return apply_filters('give_currency_symbol', $symbol, $currency);
}
Example #17
0
/**
 * Set the number of decimal places per currency
 *
 * @since 1.0
 * @since 1.6 $decimals parameter removed from function params
 **
 * @return int $decimals
 */
function give_currency_decimal_filter()
{
    remove_filter('give_sanitize_amount_decimals', 'give_currency_decimal_filter');
    // Set default number of decimals.
    $decimals = give_get_price_decimals();
    add_filter('give_sanitize_amount_decimals', 'give_currency_decimal_filter');
    // Get number of decimals with backward compatibility ( version < 1.6 )
    if (1 <= func_num_args()) {
        $decimals = false === func_get_arg(0) ? $decimals : absint(func_get_arg(0));
    }
    $currency = give_get_currency();
    switch ($currency) {
        case 'RIAL':
        case 'JPY':
        case 'TWD':
        case 'HUF':
            $decimals = 0;
            break;
    }
    return apply_filters('give_currency_decimal_count', $decimals, $currency);
}