/** * Improve message displayed on checkout when a subscription is in the cart but not gateways support subscriptions. * * @since 1.5.2 */ public static function no_available_payment_methods_message($no_gateways_message) { global $woocommerce; if (WC_Subscriptions_Cart::cart_contains_subscription() && 'no' == get_option(WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals', 'no')) { $no_gateways_message = __('Sorry, it seems there are no available payment methods which support subscriptions. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce-subscriptions'); } return $no_gateways_message; }
/** * Only display the gateways which support subscriptions if manual payments are not allowed. * * @since 1.0 */ public static function get_available_payment_gateways($available_gateways) { $accept_manual_payment = get_option(WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals', 'no'); if ('no' == $accept_manual_payment && (WC_Subscriptions_Cart::cart_contains_subscription() || isset($_GET['order_id']) && WC_Subscriptions_Order::order_contains_subscription($_GET['order_id']))) { foreach ($available_gateways as $gateway_id => $gateway) { if (!method_exists($gateway, 'supports') || $gateway->supports('subscriptions') !== true) { unset($available_gateways[$gateway_id]); } } } return $available_gateways; }
/** * Only displays the gateways which support subscriptions. * * @since 1.0 */ public static function get_available_payment_gateways($available_gateways) { if (WC_Subscriptions_Cart::cart_contains_subscription() || isset($_GET['order_id']) && WC_Subscriptions_Order::order_contains_subscription($_GET['order_id'])) { // || WC_Subscriptions_Order::order_contains_subscription( $order_id ) foreach ($available_gateways as $gateway_id => $gateway) { if (!method_exists($gateway, 'supports') || $gateway->supports('subscriptions') !== true) { unset($available_gateways[$gateway_id]); } } } return $available_gateways; }
/** * Handle any subscription switch items on checkout (and before WC_Subscriptions_Checkout::process_checkout()) * * If the item is on the same billing schedule as the old subscription (and the next payment date is the same) or the * item is the only item on the subscription, the subscription item will be updated (and a note left on the order). * If the item is on a new billing schedule and there are other items on the existing subscription, the old item will * be removed and the new item will be added to a new subscription by @see WC_Subscriptions_Checkout::process_checkout() * * @param int $order_id The post_id of a shop_order post/WC_Order object * @param array $posted_data The data posted on checkout * @since 2.0 */ public static function process_checkout($order_id, $posted_data) { global $wpdb; if (!WC_Subscriptions_Cart::cart_contains_subscription()) { return; } $order = wc_get_order($order_id); try { // Start transaction if available $wpdb->query('START TRANSACTION'); foreach (WC()->cart->recurring_carts as $recurring_cart_key => $recurring_cart) { foreach ($recurring_cart->get_cart() as $cart_item_key => $cart_item) { if (!isset($cart_item['subscription_switch']['subscription_id'])) { continue; } $subscription = wcs_get_subscription($cart_item['subscription_switch']['subscription_id']); $existing_item = wcs_get_order_item($cart_item['subscription_switch']['item_id'], $subscription); // If there are no more payments due on the subscription, because we're in the last billing period, we need to use the subscription's expiration date, not next payment date if (0 == ($next_payment_timestamp = $subscription->get_time('next_payment'))) { $next_payment_timestamp = $subscription->get_time('end'); } if ($cart_item['data']->subscription_period != $subscription->billing_period || $cart_item['data']->subscription_period_interval != $subscription->billing_interval) { $is_different_billing_schedule = true; } else { $is_different_billing_schedule = false; } if (0 !== $cart_item['subscription_switch']['first_payment_timestamp'] && $next_payment_timestamp !== $cart_item['subscription_switch']['first_payment_timestamp']) { $is_different_payment_date = true; } elseif (0 !== $cart_item['subscription_switch']['first_payment_timestamp'] && 0 == $subscription->get_time('next_payment')) { // if the subscription doesn't have a next payment but the switched item does $is_different_payment_date = true; } else { $is_different_payment_date = false; } if (date('Y-m-d', strtotime($recurring_cart->end_date)) !== date('Y-m-d', $subscription->get_time('end'))) { $is_different_length = true; } else { $is_different_length = false; } // WC_Abstract_Order::get_item_count() uses quantites, not just line item rows if (1 == count($subscription->get_items())) { $is_single_item_subscription = true; } else { $is_single_item_subscription = false; } // If the item is on the same schedule, we can just add it to the new subscription and remove the old item if ($is_single_item_subscription || false === $is_different_billing_schedule && false === $is_different_payment_date && false === $is_different_length) { // Add the new item $item_id = WC_Subscriptions_Checkout::add_cart_item($subscription, $cart_item, $cart_item_key); // Remove the item from the cart so that WC_Subscriptions_Checkout doesn't add it to a subscription if (1 == count(WC()->cart->recurring_carts[$recurring_cart_key]->get_cart())) { // If this is the only item in the cart, clear out recurring carts so WC_Subscriptions_Checkout doesn't try to create an empty subscription unset(WC()->cart->recurring_carts[$recurring_cart_key]); } else { unset(WC()->cart->recurring_carts[$recurring_cart_key]->cart_contents[$cart_item_key]); } do_action('woocommerce_subscription_item_switched', $order, $subscription, $item_id, $cart_item['subscription_switch']['item_id']); } // If the old subscription has just one item, we can safely update its billing schedule if ($is_single_item_subscription) { if ($is_different_billing_schedule) { update_post_meta($subscription->id, '_billing_period', $cart_item['data']->subscription_period); update_post_meta($subscription->id, '_billing_interval', absint($cart_item['data']->subscription_period_interval)); } $updated_dates = array(); if ('1' == $cart_item['data']->subscription_length || 0 != $recurring_cart->end_date && date('Y-m-d H:i:s', $cart_item['subscription_switch']['first_payment_timestamp']) >= $recurring_cart->end_date) { $subscription->delete_date('next_payment'); } else { if ($is_different_payment_date) { $updated_dates['next_payment'] = date('Y-m-d H:i:s', $cart_item['subscription_switch']['first_payment_timestamp']); } } if ($is_different_length) { $updated_dates['end'] = $recurring_cart->end_date; } if (!empty($updated_dates)) { $subscription->update_dates($updated_dates); } } // Remove the old item from the subscription but don't delete it completely by changing its line item type to "line_item_switched" wc_update_order_item($cart_item['subscription_switch']['item_id'], array('order_item_type' => 'line_item_switched')); $old_item_name = wcs_get_order_item_name($existing_item, array('attributes' => true)); $new_item_name = wcs_get_cart_item_name($cart_item, array('attributes' => true)); // translators: 1$: old item name, 2$: new item name when switching $subscription->add_order_note(sprintf(_x('Customer switched from: %1$s to %2$s.', 'used in order notes', 'woocommerce-subscriptions'), $old_item_name, $new_item_name)); // Change the shipping self::update_shipping_methods($subscription, $recurring_cart); // Finally, change the addresses but only if they've changed self::maybe_update_subscription_address($order, $subscription); $subscription->calculate_totals(); } } // Everything seems to be in order $wpdb->query('COMMIT'); } catch (Exception $e) { // There was an error adding the subscription, roll back and delete pending order for switch $wpdb->query('ROLLBACK'); wp_delete_post($order_id, true); throw $e; } }
/** * Payment fields. */ public function payment_fields() { $contains_subscription = false; if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.1', '>=')) { $order_id = absint(get_query_var('order-pay')); } else { $order_id = isset($_GET['order_id']) ? absint($_GET['order_id']) : 0; } // Check from "pay for order" page. if (0 < $order_id) { $contains_subscription = $this->api->order_contains_subscription($order_id); } elseif (class_exists('WC_Subscriptions_Cart')) { $contains_subscription = WC_Subscriptions_Cart::cart_contains_subscription(); } if ($contains_subscription) { wp_enqueue_script('wc-credit-card-form'); if ($description = $this->get_description()) { echo wpautop(wptexturize($description)); } woocommerce_get_template('credit-card/payment-form.php', array('order_total' => 0, 'installments' => 0, 'free_interest' => 0, 'transaction_rate' => 0, 'rates' => array()), 'woocommerce/iugu/', WC_Iugu::get_templates_path()); } else { parent::payment_fields(); } }
/** * Force tokenization for subscriptions, this can be forced either during checkout * or when the payment method for a subscription is being changed * * @since 4.1.0 * @see SV_WC_Payment_Gateway::tokenization_forced() * @param bool $force_tokenization whether tokenization should be forced * @return bool true if tokenization should be forced, false otherwise */ public function maybe_force_tokenization_1_5($force_tokenization) { // pay page with subscription? $pay_page_subscription = false; if ($this->get_gateway()->is_pay_page_gateway()) { $order_id = $this->get_gateway()->get_checkout_pay_page_order_id(); if ($order_id) { $pay_page_subscription = WC_Subscriptions_Order::order_contains_subscription($order_id); } } if (WC_Subscriptions_Cart::cart_contains_subscription() || WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment || $pay_page_subscription) { $force_tokenization = true; } return $force_tokenization; }
/** * During the checkout process, force registration when the cart contains a subscription. * * @since 1.1 */ public static function force_registration_during_checkout($woocommerce_params) { if (WC_Subscriptions_Cart::cart_contains_subscription() && !is_user_logged_in()) { $_POST['createaccount'] = 1; } }
/** * Function to check if cart contains subscription * * @return bool whether cart contains subscription or not */ public function is_cart_contains_subscription() { if (class_exists('WC_Subscriptions_Cart') && WC_Subscriptions_Cart::cart_contains_subscription()) { return true; } return false; }
/** * Gets the authorization message displayed at checkout. * * @since 2.4.0 * @return string */ public function get_authorization_message() { if ($this->supports_subscriptions() && (WC_Subscriptions_Cart::cart_contains_subscription() || WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment)) { if ($this->recurring_authorization_message) { $raw_message = $this->recurring_authorization_message; } else { $raw_message = $this->get_default_recurring_authorization_message(); } } else { if ($this->authorization_message) { $raw_message = $this->authorization_message; } else { $raw_message = $this->get_default_authorization_message(); } } /** * Filters the authorization message displayed at checkout, before replacing the placeholders. * * @since 2.4.0 * @param string $message the raw authorization message text * @param \WC_Gateway_Authorize_Net_CIM_eCheck $gateway the gateway object */ $raw_message = apply_filters('wc_' . $this->get_id() . '_raw_authorization_message', $raw_message, $this); $order_total = ($order = wc_get_order($this->get_checkout_pay_page_order_id())) ? $order->get_total() : WC()->cart->total; /** * Filters the authorization message placeholders. * * @since 2.4.0 * @param array $placeholders the authorization message placeholders * @param \WC_Gateway_Authorize_Net_CIM_eCheck $gateway the gateway object */ $placeholders = apply_filters('wc_' . $this->get_id() . '_authorization_message_placeholders', array('{merchant_name}' => get_bloginfo('name'), '{order_total}' => wc_price($order_total), '{order_date}' => date_i18n(wc_date_format())), $this); $message = str_replace(array_keys($placeholders), $placeholders, $raw_message); /** * Filters the authorization message displayed at checkout. * * @since 2.4.0 * @param string $message the authorization message text * @param \WC_Gateway_Authorize_Net_CIM_eCheck $gateway the gateway object */ return apply_filters('wc_' . $this->get_id() . '_authorization_message', $message, $this); }
/** * Init gateway */ public function init_gateway() { global $woocommerce; if (!class_exists('WC_Payment_Gateway')) { return; } load_plugin_textdomain('woocommerce-gateway-amazon-payments-advanced', false, dirname(plugin_basename(__FILE__)) . '/languages/'); switch ($woocommerce->countries->get_base_country()) { case 'GB': define('WC_AMAZON_PA_WIDGETS_URL', 'https://static-eu.payments-amazon.com/OffAmazonPayments/uk/' . ($this->settings['sandbox'] == 'yes' ? 'sandbox/' : '') . 'js/Widgets.js?sellerId=' . $this->settings['seller_id']); define('WC_AMAZON_WIDGET_ENDPOINT', 'https://payments' . ($this->settings['sandbox'] == 'yes' ? '-sandbox' : '') . '.amazon.co.uk'); define('WC_AMAZON_REGISTER_URL', 'https://sellercentral-europe.amazon.com/gp/on-board/workflow/Registration/login.html?passthrough%2Fsource=internal-landing-select&passthrough%2F*entries*=0&passthrough%2FmarketplaceID=A2WQPBGJ59HSXT&passthrough%2FsuperSource=OAR&passthrough%2F*Version*=1&passthrough%2Fld=APRPWOOCOMMERCE&passthrough%2Faccount=cba&passthrough%2FwaiveFee=1'); break; case 'DE': define('WC_AMAZON_PA_WIDGETS_URL', 'https://static-eu.payments-amazon.com/OffAmazonPayments/de/' . ($this->settings['sandbox'] == 'yes' ? 'sandbox/' : '') . 'js/Widgets.js?sellerId=' . $this->settings['seller_id']); define('WC_AMAZON_WIDGET_ENDPOINT', 'https://payments' . ($this->settings['sandbox'] == 'yes' ? '-sandbox' : '') . '.amazon.de'); define('WC_AMAZON_REGISTER_URL', 'https://sellercentral-europe.amazon.com/gp/on-board/workflow/Registration/login.html?passthrough%2Fsource=internal-landing-select&passthrough%2F*entries*=0&passthrough%2FmarketplaceID=A1OCY9REWJOCW5&passthrough%2FsuperSource=OAR&passthrough%2F*Version*=1&passthrough%2Fld=APRPWOOCOMMERCE&passthrough%2Faccount=cba&passthrough%2FwaiveFee=1'); break; default: define('WC_AMAZON_PA_WIDGETS_URL', 'https://static-na.payments-amazon.com/OffAmazonPayments/us/' . ($this->settings['sandbox'] == 'yes' ? 'sandbox/' : '') . 'js/Widgets.js?sellerId=' . $this->settings['seller_id']); define('WC_AMAZON_WIDGET_ENDPOINT', 'https://payments' . ($this->settings['sandbox'] == 'yes' ? '-sandbox' : '') . '.amazon.com'); define('WC_AMAZON_REGISTER_URL', 'https://sellercentral.amazon.com/hz/me/sp/signup?solutionProviderOptions=mws-acc%3B&marketplaceId=AGWSWK15IEJJ7&solutionProviderToken=AAAAAQAAAAEAAAAQ1XU19m0BwtKDkfLZx%2B03RwAAAHBZVsoAgz2yhE7DemKr0y26Mce%2F9Q64kptY6CRih871XhB7neN0zoPX6c1wsW3QThdY6g1Re7CwxJkhvczwVfvZ9BvjG1V%2F%2FHrRgbIf47cTrdo5nNT8jmYSIEJvFbSm85nWxpvHjSC4CMsVL9s%2FPsZt&solutionProviderId=A1BVJDFFHQ7US4'); break; } include_once 'includes/class-wc-gateway-amazon-payments-advanced.php'; add_filter('woocommerce_payment_gateways', array($this, 'add_gateway')); if (empty($this->settings['seller_id']) || $this->settings['enabled'] == 'no') { return; } // Disable for subscriptions until supported if (!is_admin() && class_exists('WC_Subscriptions_Cart') && WC_Subscriptions_Cart::cart_contains_subscription() && 'no' === get_option(WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals', 'no')) { return; } include_once 'includes/class-wc-amazon-payments-advanced-order-handler.php'; add_action('wp_enqueue_scripts', array($this, 'scripts')); if ($this->settings['cart_button_display_mode'] == 'button') { add_action('woocommerce_proceed_to_checkout', array($this, 'checkout_button'), 12); } elseif ($this->settings['cart_button_display_mode'] == 'banner') { add_action('woocommerce_before_cart', array($this, 'checkout_message'), 5); } add_action('woocommerce_before_checkout_form', array($this, 'checkout_message'), 5); add_action('before_woocommerce_pay', array($this, 'checkout_message'), 5); if (empty($this->reference_id)) { return; } add_action('woocommerce_checkout_before_customer_details', array($this, 'payment_widget'), 20); add_action('woocommerce_checkout_before_customer_details', array($this, 'address_widget'), 10); add_action('woocommerce_checkout_init', array($this, 'remove_checkout_fields')); add_filter('woocommerce_available_payment_gateways', array($this, 'remove_gateways')); add_action('woocommerce_checkout_update_order_review', array($this, 'get_customer_details')); }
/** * Check is a subscription coupon is valid before applying * * * @since 1.2 */ public static function validate_subscription_coupon($valid, $coupon) { // only check subscription coupons if (!in_array($coupon->type, array('recurring_fee', 'sign_up_fee'))) { return $valid; } // prevent subscription coupons from being applied to non-subscription products if (!WC_Subscriptions_Cart::cart_contains_subscription()) { $valid = false; self::$coupon_error = __('This coupon is only valid for subscriptions.', WC_Subscriptions::$text_domain); add_filter('woocommerce_coupon_error', __CLASS__ . '::add_coupon_error', 10); } // prevent sign up fee coupons from being applied to subscriptions without a sign up fee if (0 == WC_Subscriptions_Cart::get_cart_subscription_sign_up_fee() && 'sign_up_fee' == $coupon->type) { $valid = false; self::$coupon_error = __('This coupon is only valid for subscriptions with a sign-up fee.', WC_Subscriptions::$text_domain); add_filter('woocommerce_coupon_error', __CLASS__ . '::add_coupon_error', 10); } return $valid; }
/** * Update order shipping/cart tax total * * @since 4.4 * @param (string) $type "shipping" to update shipping tax total; "cart" to update cart tax total * @param (float) $new_tax new value for tax */ private function update_tax_total($type, $new_tax) { if ($type == 'shipping') { $tax_key = 'shipping_taxes'; $total_key = 'shipping_tax_total'; } else { $tax_key = 'taxes'; $total_key = 'tax_total'; } $this->cart->{$tax_key}[WT_RATE_ID] = $new_tax; if (!WT_SUBS_ACTIVE || !WC_Subscriptions_Cart::cart_contains_subscription()) { // Removing zero tax row causes display issues for subscription orders if (WC_WooTax::get_option('show_zero_tax') != 'true' && $new_tax == 0) { unset($this->cart->{$tax_key}[WT_RATE_ID]); } } // Use get_tax_total to set new tax total so we don't override other rates $this->cart->{$total_key} = version_compare(WOOCOMMERCE_VERSION, '2.2', '>=') ? WC_Tax::get_tax_total($this->cart->{$tax_key}) : $this->cart->tax->get_tax_total($this->cart->{$tax_key}); $this->{$total_key} = $new_tax; }
/** * Helper to scan the cart for subscriptions (since we do not want to show a Checkout with PayPal * button in the cart view if there are any) * * @since 1.0.0 */ public function does_cart_contain_any_subscriptions() { if (!$this->subscription_support_enabled) { return false; } if (!class_exists('WC_Subscriptions_Cart')) { return false; } return WC_Subscriptions_Cart::cart_contains_subscription(); }
/** * Maybe disable the gateway in 2 situations: * * 1) when the admin has opted not to show it at checkout * 2) when on the checkout > pay page as PPE does not yet support this * * @since 3.0.0 * @return bool|true */ public function is_available() { $is_available = parent::is_available(); // don't show on checkout page if (!$this->is_express_checkout() && is_checkout() && !$this->show_on_checkout()) { $is_available = false; } // don't display when order review table is rendered via AJAX if (!$this->is_express_checkout() && defined('DOING_AJAX') && DOING_AJAX && isset($_POST['action']) && $_POST['action'] == 'woocommerce_update_order_review' && !$this->show_on_checkout()) { $is_available = false; } // don't show on checkout > pay page if (is_checkout_pay_page()) { $is_available = false; } // don't show if the cart contains a subscription and manual renewals are not enabled if ($this->get_plugin()->is_subscriptions_active() && WC_Subscriptions_Cart::cart_contains_subscription() && 'no' === get_option(WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals', 'no')) { $is_available = false; } return $is_available; }
/** * UI - Payment page fields for Inspire Commerce. */ function payment_fields() { // Description of payment method from settings if ($this->description) { ?> <p><?php echo $this->description; ?> </p> <?php } ?> <fieldset style="padding-left: 40px;"> <?php $user = wp_get_current_user(); $this->check_payment_method_conversion($user->user_login, $user->ID); if ($this->user_has_stored_data($user->ID)) { ?> <fieldset> <input type="radio" name="inspire-use-stored-payment-info" id="inspire-use-stored-payment-info-yes" value="yes" checked="checked" onclick="document.getElementById('inspire-new-info').style.display='none'; document.getElementById('inspire-stored-info').style.display='block'"; /><label for="inspire-use-stored-payment-info-yes" style="display: inline;"><?php _e('Use a stored credit card', 'woocommerce'); ?> </label> <div id="inspire-stored-info" style="padding: 10px 0 0 40px; clear: both;"> <?php $i = 0; $method = $this->get_payment_method($i); while ($method != null) { ?> <p> <input type="radio" name="inspire-payment-method" id="<?php echo $i; ?> " value="<?php echo $i; ?> " <?php if ($i == 0) { echo 'checked'; } ?> /> <?php echo $method->cc_number; ?> (<?php $exp = $method->cc_exp; echo substr($exp, 0, 2) . '/' . substr($exp, -2); ?> ) <br /> </p> <?php $method = $this->get_payment_method(++$i); } ?> </fieldset> <fieldset> <p> <input type="radio" name="inspire-use-stored-payment-info" id="inspire-use-stored-payment-info-no" value="no" onclick="document.getElementById('inspire-stored-info').style.display='none'; document.getElementById('inspire-new-info').style.display='block'"; /> <label for="inspire-use-stored-payment-info-no" style="display: inline;"><?php _e('Use a new payment method', 'woocommerce'); ?> </label> </p> <div id="inspire-new-info" style="display:none"> </fieldset> <?php } else { ?> <fieldset> <!-- Show input boxes for new data --> <div id="inspire-new-info"> <?php } ?> <!-- Credit card number --> <p class="form-row form-row-first"> <label for="ccnum"><?php echo __('Credit Card number', 'woocommerce'); ?> <span class="required">*</span></label> <input type="text" class="input-text" id="ccnum" name="ccnum" maxlength="16" /> </p> <!-- Credit card type --> <p class="form-row form-row-last"> <label for="cardtype"><?php echo __('Card type', 'woocommerce'); ?> <span class="required">*</span></label> <select name="cardtype" id="cardtype" class="woocommerce-select"> <?php foreach ($this->cardtypes as $type) { ?> <option value="<?php echo $type; ?> "><?php _e($type, 'woocommerce'); ?> </option> <?php } ?> </select> </p> <div class="clear"></div> <!-- Credit card expiration --> <p class="form-row form-row-first"> <label for="cc-expire-month"><?php echo __('Expiration date', 'woocommerce'); ?> <span class="required">*</span></label> <select name="expmonth" id="expmonth" class="woocommerce-select woocommerce-cc-month"> <option value=""><?php _e('Month', 'woocommerce'); ?> </option><?php $months = array(); for ($i = 1; $i <= 12; $i++) { $timestamp = mktime(0, 0, 0, $i, 1); $months[date('n', $timestamp)] = date('F', $timestamp); } foreach ($months as $num => $name) { printf('<option value="%u">%s</option>', $num, $name); } ?> </select> <select name="expyear" id="expyear" class="woocommerce-select woocommerce-cc-year"> <option value=""><?php _e('Year', 'woocommerce'); ?> </option><?php $years = array(); for ($i = date('y'); $i <= date('y') + 15; $i++) { printf('<option value="20%u">20%u</option>', $i, $i); } ?> </select> </p> <?php // Credit card security code if ($this->cvv == 'yes') { ?> <p class="form-row form-row-last"> <label for="cvv"><?php _e('Card security code', 'woocommerce'); ?> <span class="required">*</span></label> <input oninput="validate_cvv(this.value)" type="text" class="input-text" id="cvv" name="cvv" maxlength="4" style="width:45px" /> <span class="help"><?php _e('3 or 4 digits usually found on the signature strip.', 'woocommerce'); ?> </span> </p><?php } // Option to store credit card data if ($this->saveinfo == 'yes' && !(class_exists('WC_Subscriptions_Cart') && WC_Subscriptions_Cart::cart_contains_subscription())) { ?> <div style="clear: both;"></div> <p> <label for="saveinfo"><?php _e('Save this billing method?', 'woocommerce'); ?> </label> <input type="checkbox" class="input-checkbox" id="saveinfo" name="saveinfo" /> <span class="help"><?php _e('Select to store your billing information for future use.', 'woocommerce'); ?> </span> </p> <?php } ?> </fieldset> </fieldset> <?php }
/** * Add scripts */ public function scripts() { $enqueue_scripts = is_cart() || is_checkout() || is_checkout_pay_page(); if (!apply_filters('woocommerce_amazon_pa_enqueue_scripts', $enqueue_scripts)) { return; } $type = 'yes' == $this->settings['enable_login_app'] ? 'app' : 'standard'; wp_enqueue_style('amazon_payments_advanced', plugins_url('assets/css/style.css', __FILE__)); wp_enqueue_script('amazon_payments_advanced_widgets', WC_Amazon_Payments_Advanced_API::get_widgets_url(), array(), '1.0', true); wp_enqueue_script('amazon_payments_advanced', plugins_url('assets/js/amazon-' . $type . '-widgets.js', __FILE__), array(), '1.0', true); $redirect_page = is_cart() ? add_query_arg('amazon_payments_advanced', 'true', get_permalink(woocommerce_get_page_id('checkout'))) : add_query_arg('amazon_payments_advanced', 'true'); $params = array('seller_id' => $this->settings['seller_id'], 'reference_id' => $this->reference_id, 'redirect' => esc_url_raw($redirect_page), 'is_checkout_pay_page' => is_checkout_pay_page(), 'is_checkout' => is_checkout(), 'access_token' => $this->access_token); if ('yes' == $this->settings['enable_login_app']) { $params['button_type'] = 'LwA'; $params['button_color'] = 'Gold'; $params['button_size'] = 'small'; $params['checkout_url'] = esc_url_raw(get_permalink(woocommerce_get_page_id('checkout'))); } if (class_exists('WC_Subscriptions_Cart')) { $cart_contains_subscription = WC_Subscriptions_Cart::cart_contains_subscription() || wcs_cart_contains_renewal(); $change_payment_for_subscription = isset($_GET['change_payment_method']) && wcs_is_subscription(absint($_GET['change_payment_method'])); $params['is_recurring'] = $cart_contains_subscription || $change_payment_for_subscription; } $params = array_map('esc_js', apply_filters('woocommerce_amazon_pa_widgets_params', $params)); wp_localize_script('amazon_payments_advanced', 'amazon_payments_advanced_params', $params); }
/** * Sets which coupons should be applied for this calculation. * * This function is hooked to "woocommerce_before_calculate_totals" so that WC will calculate a subscription * product's total based on the total of it's price per period and sign up fee (if any). * * @since 1.3.5 */ public static function remove_coupons($cart) { global $woocommerce; $calculation_type = WC_Subscriptions_Cart::get_calculation_type(); // Only hook when totals are being calculated completely (on cart & checkout pages) if ('none' == $calculation_type || !WC_Subscriptions_Cart::cart_contains_subscription() || !is_checkout() && !is_cart() && !defined('WOOCOMMERCE_CHECKOUT') && !defined('WOOCOMMERCE_CART')) { return; } $applied_coupons = $cart->get_applied_coupons(); // If we're calculating a sign-up fee or recurring fee only amount, remove irrelevant coupons if (!empty($applied_coupons)) { // Keep track of which coupons, if any, need to be reapplied immediately $coupons_to_reapply = array(); if (in_array($calculation_type, array('combined_total', 'sign_up_fee_total', 'recurring_total'))) { foreach ($applied_coupons as $coupon_code) { $coupon = new WC_Coupon($coupon_code); if (in_array($coupon->type, array('recurring_fee', 'recurring_percent'))) { // always apply coupons to their specific calculation case if ('recurring_total' == $calculation_type) { $coupons_to_reapply[] = $coupon_code; } elseif ('combined_total' == $calculation_type && !WC_Subscriptions_Cart::cart_contains_free_trial()) { // sometimes apply recurring coupons to initial total $coupons_to_reapply[] = $coupon_code; } else { self::$removed_coupons[] = $coupon_code; } } elseif (in_array($calculation_type, array('combined_total', 'sign_up_fee_total', 'none')) && !in_array($coupon->type, array('recurring_fee', 'recurring_percent'))) { // apply all coupons to the first payment $coupons_to_reapply[] = $coupon_code; } else { self::$removed_coupons[] = $coupon_code; } } // Now remove all coupons (WC only provides a function to remove all coupons) $cart->remove_coupons(); // And re-apply those which relate to this calculation $woocommerce->cart->applied_coupons = $coupons_to_reapply; } } }
/** * Override the WooCommerce "Place Order" text with "Sign Up Now" * * @since 1.0 */ public static function order_button_text($button_text) { global $product; if (WC_Subscriptions_Cart::cart_contains_subscription()) { $button_text = get_option(WC_Subscriptions_Admin::$option_prefix . '_order_button_text', __('Sign Up Now', 'woocommerce-subscriptions')); } return $button_text; }
/** * Change Checkout URL * * Triggered from the 'woocommerce_get_checkout_url' action. * Alter the checkout url to the custom Klarna Checkout Checkout page. * **/ function change_checkout_url($url) { global $woocommerce; global $klarna_checkout_url; $checkout_settings = get_option('woocommerce_klarna_checkout_settings'); $enabled = $checkout_settings['enabled']; $modify_standard_checkout_url = $checkout_settings['modify_standard_checkout_url']; $klarna_country = WC()->session->get('klarna_country'); $available_countries = $this->get_authorized_countries(); // Change the Checkout URL if this is enabled in the settings if ($modify_standard_checkout_url == 'yes' && $enabled == 'yes' && !empty($klarna_checkout_url) && in_array(strtoupper($klarna_country), $available_countries) && array_key_exists(strtoupper($klarna_country), WC()->countries->get_allowed_countries())) { if (class_exists('WC_Subscriptions_Cart') && WC_Subscriptions_Cart::cart_contains_subscription()) { if (in_array(strtoupper($klarna_country), array('SE', 'FI', 'NO'))) { $url = $klarna_checkout_url; } else { return $url; } } else { $url = $klarna_checkout_url; } } return $url; }
/** * Payment fields for Realex. * * @see WC_Payment_Gateway::payment_fields() */ public function payment_fields() { if ($this->threedsecure->is_3dsecure_available() && (!is_checkout_pay_page() || isset($_GET['pay_for_order']))) { parent::payment_fields(); ?> <style type="text/css">#payment ul.payment_methods li label[for='payment_method_realex'] img:nth-child(n+2) { margin-left:1px; }</style> <?php return; } // default to new card $card_ref = 'new'; if ($this->vault_available()) { // get the credit card tokens for the user $current_user = wp_get_current_user(); $credit_cards = array(); if ($current_user->ID) { $credit_cards = get_user_meta($current_user->ID, 'woocommerce_realex_cc', true); } // if there are saved cards, and one hasn't been selected, default to the first if ($credit_cards) { $card_ref = (object) current($credit_cards); $card_ref = $card_ref->ref; } } ?> <style type="text/css">#payment ul.payment_methods li label[for='payment_method_realex'] img:nth-child(n+2) { margin-left:1px; }</style> <fieldset> <?php if ($this->description) { ?> <p><?php echo esc_html($this->description); ?> <?php if ($this->is_test_mode()) { esc_html_e('TEST MODE ENABLED', 'woocommerce-gateway-realex'); } ?> </p><?php } ?> <?php if ($this->vault_available() && $credit_cards) { ?> <div> <p class="form-row form-row-first" style="width:65%;"> <?php foreach ($credit_cards as $credit_card) { $credit_card = (object) $credit_card; ?> <input type="radio" id="<?php echo esc_attr($credit_card->ref); ?> " name="realex_card_ref" style="width:auto;" value="<?php echo esc_attr($credit_card->ref); ?> " <?php checked($credit_card->ref, $card_ref); ?> /> <label style="display:inline;" for="<?php echo esc_attr($credit_card->ref); ?> "> <?php /* translators: Placeholders: %1$s - credit card type, %2$s - credit card last 4, %3$s - credit card expiration MM/YY */ printf(esc_html__('%1$s ending in %2$s (%3$s)', 'woocommerce-gateway-realex'), $this->card_type_options[$credit_card->type], $credit_card->last4, $credit_card->expiration_month . '/' . $credit_card->expiration_year); ?> </label><br /> <?php } ?> <input type="radio" id="realex_new" name="realex_card_ref" style="width:auto;" <?php checked('new', $card_ref); ?> value="0" /> <label style="display:inline;" for="realex_new"><?php esc_html_e('Use Another Credit Card', 'woocommerce-gateway-realex'); ?> </label> </p> <p class="form-row form-row-last" style="width:30%;"><a class="button" href="<?php echo esc_url(wc_get_page_permalink('myaccount')); ?> #saved-cards"><?php echo esc_html($this->managecards); ?> </a></p> <div style="clear:both;"></div> </div> <div class="clear"></div> <?php } ?> <div class="realex_vault_new" style="<?php echo $card_ref == 'new' ? '' : 'display:none;'; ?> "> <p class="form-row form-row-first"> <label for="realex_accountNumber"><?php echo __("Credit Card number", 'woocommerce-gateway-realex'); ?> <span class="required">*</span></label> <input type="text" class="input-text" id="realex_accountNumber" name="realex_accountNumber" maxlength="19" autocomplete="off" /> </p> <p class="form-row form-row-last"> <label for="realex_cardType"><?php _e('Card Type', 'woocommerce-gateway-realex'); ?> <span class="required">*</span></label> <select name="realex_cardType" id="realex_cardType" style="width:auto;"><br /> <option value=""> <?php foreach ($this->cardtypes as $type) { if (isset($this->card_type_options[$type])) { ?> <option value="<?php echo esc_attr(preg_replace('/-.*$/', '', $type)); ?> " rel="<?php echo esc_attr($type); ?> "><?php esc_html_e($this->card_type_options[$type], 'woocommerce-gateway-realex'); ?> </option> <?php } } ?> </select> </p> <div class="clear"></div> <p class="form-row form-row-first"> <label for="realex_expirationMonth"><?php esc_html_e('Expiration date', 'woocommerce-gateway-realex'); ?> <span class="required">*</span></label> <select name="realex_expirationMonth" id="realex_expirationMonth" class="woocommerce-select woocommerce-cc-month" style="width:auto;"> <option value=""><?php esc_attr_e('Month', 'woocommerce-gateway-realex'); ?> </option> <?php foreach (range(1, 12) as $month) { ?> <option value="<?php echo sprintf('%02d', $month); ?> "><?php echo sprintf('%02d', $month); ?> </option> <?php } ?> </select> <select name="realex_expirationYear" id="realex_expirationYear" class="woocommerce-select woocommerce-cc-year" style="width:auto;"> <option value=""><?php esc_attr_e('Year', 'woocommerce-gateway-realex'); ?> </option> <?php foreach (range(date('Y'), date('Y') + 20) as $year) { ?> <option value="<?php echo $year; ?> "><?php echo $year; ?> </option> <?php } ?> </select> </p> <?php if ($this->cvv == 'yes') { ?> <p class="form-row form-row-last"> <label for="realex_cvNumber"><?php esc_html_e('Card security code', 'woocommerce-gateway-realex'); ?> <span class="required">*</span></label> <input type="text" class="input-text" id="realex_cvNumber" name="realex_cvNumber" maxlength="4" style="width:60px" autocomplete="off" /> </p> <?php } ?> <?php if (in_array('SWITCH', $this->get_real_cardtypes())) { ?> <?php if ($this->cvv == 'no') { ?> <p class="form-row form-row-last" style="display:none;"> <?php } else { ?> <div class="clear"></div> <p class="form-row form-row-first" style="display:none;"> <?php } ?> <label for="realex_issueNumber"><?php esc_html_e('Issue Number', 'woocommerce-gateway-realex'); ?> </label> <input type="text" class="input-text" id="realex_issueNumber" name="realex_issueNumber" maxlength="3" style="width:60px" autocomplete="off" /> </p> <?php } ?> <div class="clear"></div> <?php if ($this->vault_available()) { ?> <?php if (wc_realex()->is_subscriptions_active() && WC_Subscriptions_Cart::cart_contains_subscription() && in_array('subscriptions', $this->supports)) { ?> <input name="realex_vault_new" type="hidden" value="1" /> <?php } else { /* Normal behavior */ ?> <div class="realex_create-account"> <p class="form-row"> <input id="realex_vault_new" name="realex_vault_new" type="checkbox" value="1" style="width:auto;" /> <label for="realex_vault_new" style="display:inline;"><?php echo esc_html($this->vaulttext); ?> </label> </p> </div> <div class="clear"></div> <?php } ?> <?php } ?> </div> </fieldset> <?php }
/** * Load handlers for cart and orders after WC Cart is loaded. */ public function init_handlers() { // Disable if no seller ID if (empty($this->settings['seller_id']) || $this->settings['enabled'] == 'no') { return; } // Disable for subscriptions until supported if (!is_admin() && class_exists('WC_Subscriptions_Cart') && WC_Subscriptions_Cart::cart_contains_subscription() && 'no' === get_option(WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals', 'no')) { return; } add_action('wp_enqueue_scripts', array($this, 'scripts')); if ($this->settings['cart_button_display_mode'] == 'button') { add_action('woocommerce_proceed_to_checkout', array($this, 'checkout_button'), 12); } elseif ($this->settings['cart_button_display_mode'] == 'banner') { add_action('woocommerce_before_cart', array($this, 'checkout_message'), 5); } add_action('woocommerce_before_checkout_form', array($this, 'checkout_message'), 5); add_action('before_woocommerce_pay', array($this, 'checkout_message'), 5); if (empty($this->reference_id)) { return; } //add_filter( 'woocommerce_cart_needs_payment', '__return_true' ); add_action('woocommerce_checkout_before_customer_details', array($this, 'payment_widget'), 20); add_action('woocommerce_checkout_before_customer_details', array($this, 'address_widget'), 10); add_action('woocommerce_checkout_init', array($this, 'remove_checkout_fields')); add_filter('woocommerce_available_payment_gateways', array($this, 'remove_gateways')); add_action('woocommerce_checkout_update_order_review', array($this, 'get_customer_details')); }
echo '</div>'; } } if ($klarna_order['status'] == 'checkout_incomplete') { wp_redirect($this->klarna_checkout_url); exit; } // Display Klarna iframe if ($this->is_rest()) { $snippet = '<div>' . $klarna_order['html_snippet'] . '</div>'; } else { $snippet = '<div class="klarna-thank-you-snippet">' . $klarna_order['gui']['snippet'] . '</div>'; } do_action('klarna_before_kco_confirmation', intval($_GET['sid'])); // WC Subscriptions 2.0 needs this if (class_exists('WC_Subscriptions_Cart') && WC_Subscriptions_Cart::cart_contains_subscription()) { sleep(5); $parent_order = new WC_Order(intval($_GET['sid'])); $subscriptions = array(); // First clear out any subscriptions created for a failed payment to give us a clean slate for creating new subscriptions $subscriptions = wcs_get_subscriptions_for_order($parent_order->id, array('order_type' => 'parent')); if (!empty($subscriptions)) { foreach ($subscriptions as $subscription) { wp_delete_post($subscription->id); } } WC()->cart->calculate_totals(); // Create new subscriptions for each group of subscription products in the cart (that is not a renewal) foreach (WC()->cart->recurring_carts as $recurring_cart) { $subscription = WC_Subscriptions_Checkout::create_subscription($parent_order, $recurring_cart); // Exceptions are caught by WooCommerce
/** * Function to apply Gift Certificate's credit to cart */ public function apply_smart_coupon_to_cart() { $this->global_wc()->cart->smart_coupon_credit_used = array(); $cart_contains_subscription = false; if (class_exists('WC_Subscriptions_Cart') && WC_Subscriptions_Cart::cart_contains_subscription()) { $cart_contains_subscription = true; } if ($cart_contains_subscription) { $calculation_type = WC_Subscriptions_Cart::get_calculation_type(); if ($calculation_type == 'recurring_total') { return; } } if ($this->global_wc()->cart->applied_coupons) { foreach ($this->global_wc()->cart->applied_coupons as $code) { $smart_coupon = new WC_Coupon($code); if ($smart_coupon->is_valid() && $smart_coupon->discount_type == 'smart_coupon') { $order_total = $this->global_wc()->cart->cart_contents_total + $this->global_wc()->cart->tax_total + $this->global_wc()->cart->shipping_tax_total + $this->global_wc()->cart->shipping_total; if ($this->global_wc()->cart->discount_total != 0 && $this->global_wc()->cart->discount_total + $smart_coupon->amount > $order_total) { $smart_coupon->amount = $order_total - $this->global_wc()->cart->discount_total; } elseif ($smart_coupon->amount > $order_total) { $smart_coupon->amount = $order_total; } $this->global_wc()->cart->discount_total = $this->global_wc()->cart->discount_total + $smart_coupon->amount; if ($cart_contains_subscription) { WC_Subscriptions_Cart::increase_coupon_discount_amount($code, $smart_coupon->amount); } $this->global_wc()->cart->smart_coupon_credit_used[$code] = $smart_coupon->amount; //Code for displaying the price label for the store credit coupons if (empty($this->global_wc()->cart->coupon_discount_amounts)) { $this->global_wc()->cart->coupon_discount_amounts = array(); } $this->global_wc()->cart->coupon_discount_amounts[$code] = $smart_coupon->amount; } } } }
/** * Retrieve full details from the order using 'GetBillingAgreementDetails' (if it contains a subscription). * * @param string $amazon_reference_id * * @return bool|object Boolean false on failure, object of OrderReferenceDetails on success. */ function get_amazon_order_details($amazon_reference_id) { if (!WC_Subscriptions_Cart::cart_contains_subscription()) { return parent::get_amazon_order_details($amazon_reference_id); } $response = WC_Amazon_Payments_Advanced_API::request(array('Action' => 'GetBillingAgreementDetails', 'AmazonBillingAgreementId' => $amazon_reference_id)); if (!is_wp_error($response) && isset($response->GetBillingAgreementDetailsResult->BillingAgreementDetails)) { return $response->GetBillingAgreementDetailsResult->BillingAgreementDetails; } return false; }