本文整理汇总了PHP中give_get_currency函数的典型用法代码示例。如果您正苦于以下问题:PHP give_get_currency函数的具体用法?PHP give_get_currency怎么用?PHP give_get_currency使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了give_get_currency函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: my_give_display_earnings_shortcode
/**
* 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;
}
示例2: give_currency_symbol
/**
* 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 "USD":
case "AUD":
case "CAD":
case "HKD":
case "MXN":
case "SGD":
$symbol = '$';
break;
case "JPY":
$symbol = '¥';
break;
default:
$symbol = $currency;
break;
}
return apply_filters('give_currency_symbol', $symbol, $currency);
}
示例3: give_process_paypal_purchase
/**
* 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('&', '&', $paypal_redirect);
// Redirect to PayPal
wp_redirect($paypal_redirect);
exit;
}
}
示例4: give_offline_process_payment
/**
* 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']);
}
}
示例5: give_manual_payment
/**
* 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']);
}
}
示例6: give_process_paypal_purchase
/**
* 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('&', '&', $paypal_redirect);
// Redirect to PayPal.
wp_redirect($paypal_redirect);
exit;
}
}
示例7: give_tools_sysinfo_get
/**
* 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';
}
//.........这里部分代码省略.........
示例8: give_insert_payment
/**
* 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;
}
示例9: process_purchase
/**
* 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);
}
}
}
}
示例10: give_get_payment_currency_code
/**
* 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);
}
示例11: give_currency_decimal_filter
/**
* 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);
}
示例12: give_output_donation_amount_top
/**
* 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);
}
示例13: give_process_authorize_net_payment
/**
* 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);
//.........这里部分代码省略.........
示例14: setup_currency
/**
* 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;
}
示例15: give_currency_symbol
/**
* 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);
}