/** * Include the PayPal payment meta data required to process automatic recurring payments so that store managers can * manually set up automatic recurring payments for a customer via the Edit Subscription screen. * * @param array $payment_meta associative array of meta data required for automatic payments * @param WC_Subscription $subscription An instance of a subscription object * @return array * @since 2.0 */ public static function add_payment_meta_details($payment_meta, $subscription) { if (WCS_PayPal::are_reference_transactions_enabled()) { $payment_meta['paypal'] = array('post_meta' => array('_paypal_subscription_id' => array('value' => get_post_meta($subscription->id, '_paypal_subscription_id', true), 'label' => 'PayPal Billing Agreement ID'))); } return $payment_meta; }
/** * Add subscription support to the PayPal Standard gateway only when credentials are set * * @since 2.0 */ public static function add_feature_support_for_gateway($is_supported, $feature, $gateway) { if ('paypal' === $gateway->id && WCS_PayPal::are_credentials_set()) { if (in_array($feature, self::$standard_supported_features)) { $is_supported = true; } elseif (in_array($feature, self::$reference_transaction_supported_features) && WCS_PayPal::are_reference_transactions_enabled()) { $is_supported = true; } } return $is_supported; }
/** * Allow items on PayPal Standard Subscriptions to be switch when the PayPal account supports Reference Transactions * * Because PayPal Standard does not support recurring amount or date changes, items can not be switched when the subscription is using a * profile ID for PayPal Standard. However, PayPal Reference Transactions do allow these to be updated and because switching uses the checkout * process, we can migrate a subscription from PayPal Standard to Reference Transactions when the customer switches, so we will allow that. * * @since 2.0 */ public static function can_item_be_switched($item_can_be_switch, $item, $subscription) { if (false === $item_can_be_switch && 'paypal' === $subscription->payment_method && WCS_PayPal::are_reference_transactions_enabled()) { $is_billing_agreement = wcs_is_paypal_profile_a(wcs_get_paypal_id($subscription->id), 'billing_agreement'); if ('line_item' == $item['type'] && wcs_is_product_switchable_type($item['product_id'])) { $is_product_switchable = true; } else { $is_product_switchable = false; } if ($subscription->has_status('active') && 0 !== $subscription->get_date('last_payment')) { $is_subscription_switchable = true; } else { $is_subscription_switchable = false; } // If the only reason the subscription isn't switchable is because the PayPal profile ID is not a billing agreement, allow it to be switched if (false === $is_billing_agreement && $is_product_switchable && $is_subscription_switchable) { $item_can_be_switch = true; } } return $item_can_be_switch; }
/** * Do not allow subscriptions to be switched using PayPal Standard as the payment method * * @since 2.0.16 */ public static function get_available_payment_gateways($available_gateways) { if (WC_Subscriptions_Switcher::cart_contains_switches() || isset($_GET['order_id']) && wcs_order_contains_switch($_GET['order_id'])) { foreach ($available_gateways as $gateway_id => $gateway) { if ('paypal' == $gateway_id && false == WCS_PayPal::are_reference_transactions_enabled()) { unset($available_gateways[$gateway_id]); } } } return $available_gateways; }
/** * Display an assortment of notices to administrators to encourage them to get PayPal setup right. * * @since 2.0 */ public static function maybe_show_admin_notices() { self::maybe_disable_invalid_profile_notice(); self::maybe_update_credentials_error_flag(); if (!in_array(get_woocommerce_currency(), apply_filters('woocommerce_paypal_supported_currencies', array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB')))) { $valid_for_use = false; } else { $valid_for_use = true; } $payment_gateway_tab_url = admin_url('admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_paypal'); $notices = array(); if ($valid_for_use && 'yes' == WCS_PayPal::get_option('enabled') && !has_action('admin_notices', 'WC_Subscriptions_Admin::admin_installed_notice') && current_user_can('manage_options')) { if (!WCS_PayPal::are_credentials_set()) { $notices[] = array('type' => 'warning', 'text' => sprintf(esc_html__('PayPal is inactive for subscription transactions. Please %1$sset up the PayPal IPN%2$s and %3$senter your API credentials%4$s to enable PayPal for Subscriptions.', 'woocommerce-subscriptions'), '<a href="http://docs.woothemes.com/document/subscriptions/store-manager-guide/#section-4" target="_blank">', '</a>', '<a href="' . esc_url($payment_gateway_tab_url) . '">', '</a>')); } elseif ('woocommerce_page_wc-settings' === get_current_screen()->base && isset($_GET['tab']) && in_array($_GET['tab'], array('subscriptions', 'checkout')) && !WCS_PayPal::are_reference_transactions_enabled()) { $notices[] = array('type' => 'warning', 'text' => sprintf(esc_html__('%1$sPayPal Reference Transactions are not enabled on your account%2$s, some subscription management features are not enabled. Please contact PayPal and request they %3$senable PayPal Reference Transactions%4$s on your account. %5$sCheck PayPal Account%6$s %7$sLearn more %8$s', 'woocommerce-subscriptions'), '<strong>', '</strong>', '<a href="http://docs.woothemes.com/document/subscriptions/store-manager-guide/#section-4" target="_blank">', '</a>', '</p><p><a class="button" href="' . esc_url(wp_nonce_url(add_query_arg('wcs_paypal', 'check_reference_transaction_support'), __CLASS__)) . '">', '</a>', '<a class="button button-primary" href="http://docs.woothemes.com/document/subscriptions/store-manager-guide/#section-4" target="_blank">', '»</a>')); } if (isset($_GET['wcs_paypal']) && 'rt_enabled' === $_GET['wcs_paypal']) { $notices[] = array('type' => 'confirmation', 'text' => sprintf(esc_html__('%1$sPayPal Reference Transactions are enabled on your account%2$s. All subscription management features are now enabled. Happy selling!', 'woocommerce-subscriptions'), '<strong>', '</strong>')); } if (false !== get_option('wcs_paypal_credentials_error')) { $notices[] = array('type' => 'error', 'text' => sprintf(esc_html__('There is a problem with PayPal. Your API credentials may be incorrect. Please update your %1$sAPI credentials%2$s. %3$sLearn more%4$s.', 'woocommerce-subscriptions'), '<a href="' . esc_url($payment_gateway_tab_url) . '">', '</a>', '<a href="https://support.woothemes.com/hc/en-us/articles/202882473#paypal-credentials" target="_blank">', '</a>')); } if ('yes' == get_option('wcs_paypal_invalid_profile_id')) { $notices[] = array('type' => 'error', 'text' => sprintf(esc_html__('There is a problem with PayPal. Your PayPal account is issuing out-of-date subscription IDs. %1$sLearn more%2$s. %3$sDismiss%4$s.', 'woocommerce-subscriptions'), '<a href="https://support.woothemes.com/hc/en-us/articles/202882473#old-paypal-account" target="_blank">', '</a>', '<a href="' . esc_url(add_query_arg('wcs_disable_paypal_invalid_profile_id_notice', 'true')) . '">', '</a>')); } } if (!empty($notices)) { include_once dirname(__FILE__) . '/../templates/admin-notices.php'; } }
/** * If changing a subscriptions payment method from and to PayPal, the cancelled subscription hook was removed in * @see self::maybe_remove_cancelled_subscription_hook() so we want to add it again for other subscriptions. * * @since 2.0 */ public static function maybe_reattach_subscription_cancelled_callback($subscription, $new_payment_method, $old_payment_method) { if ('paypal' == $new_payment_method && 'paypal' == $old_payment_method && !WCS_PayPal::are_reference_transactions_enabled()) { add_action('woocommerce_subscription_cancelled_paypal', 'WCS_PayPal_Status_Manager::cancel_subscription'); } }