Exemplo n.º 1
0
 /**
  * Bootstraps the class and hooks required actions & filters.
  *
  * @since 2.0
  */
 public static function init()
 {
     self::$paypal_settings = self::get_options();
     // wc-api handler for express checkout transactions
     if (!has_action('woocommerce_api_wcs_paypal')) {
         add_action('woocommerce_api_wcs_paypal', __CLASS__ . '::handle_wc_api');
     }
     // When necessary, set the PayPal args to be for a subscription instead of shopping cart
     add_action('woocommerce_update_options_payment_gateways_paypal', __CLASS__ . '::reload_options', 100);
     // When necessary, set the PayPal args to be for a subscription instead of shopping cart
     add_action('woocommerce_update_options_payment_gateways_paypal', __CLASS__ . '::are_reference_transactions_enabled', 100);
     // When necessary, set the PayPal args to be for a subscription instead of shopping cart
     add_filter('woocommerce_paypal_args', __CLASS__ . '::get_paypal_args', 10, 2);
     // Check a valid PayPal IPN request to see if it's a subscription *before* WCS_Gateway_Paypal::successful_request()
     add_action('valid-paypal-standard-ipn-request', __CLASS__ . '::process_ipn_request', 0);
     add_action('woocommerce_scheduled_subscription_payment_paypal', __CLASS__ . '::process_subscription_payment', 10, 2);
     // Don't copy over PayPal details to Resubscribe Orders
     add_filter('wcs_resubscribe_order_created', __CLASS__ . '::remove_resubscribe_order_meta', 10, 2);
     // Triggered by WCS_SV_API_Base::broadcast_request() whenever an API request is made
     add_action('wc_paypal_api_request_performed', __CLASS__ . '::log_api_requests', 10, 2);
     add_filter('woocommerce_subscriptions_admin_meta_boxes_script_parameters', __CLASS__ . '::maybe_add_change_payment_method_warning');
     WCS_PayPal_Supports::init();
     WCS_PayPal_Status_Manager::init();
     WCS_PayPal_Standard_Switcher::init();
     if (is_admin()) {
         WCS_PayPal_Admin::init();
         WCS_PayPal_Change_Payment_Method_Admin::init();
     }
 }
 /**
  * Cancel a specific PayPal Standard Subscription Profile with PayPal.
  *
  * Used when switching payment methods with PayPal Standard to make sure that
  * the old subscription's profile ID is cancelled, not the new one.
  *
  * @param WC_Subscription A subscription object
  * @param string A PayPal Subscription Profile ID
  * @since 2.0
  */
 protected static function cancel_subscription($subscription, $old_paypal_subscriber_id)
 {
     // No need to cancel billing agreements
     if (wcs_is_paypal_profile_a($old_paypal_subscriber_id, 'billing_agreement')) {
         return;
     }
     $current_profile_id = wcs_get_paypal_id($subscription->id);
     // Update the subscription using the old profile ID
     wcs_set_paypal_id($subscription, $old_paypal_subscriber_id);
     // Call update_subscription_status() directly as we don't want the notes added by WCS_PayPal_Status_Manager::cancel_subscription()
     WCS_PayPal_Status_Manager::update_subscription_status($subscription, 'Cancel');
     // Restore the current profile ID
     wcs_set_paypal_id($subscription, $current_profile_id);
 }
 /**
  * Cancel subscriptions with PayPal Standard after the order has been successfully switched.
  *
  * @param int $order_id
  * @param string $old_status
  * @param string $new_status
  * @since 2.0.15
  */
 public static function maybe_cancel_paypal_after_switch($order_id, $old_status, $new_status)
 {
     $order_completed = in_array($new_status, array(apply_filters('woocommerce_payment_complete_order_status', 'processing', $order_id), 'processing', 'completed')) && in_array($old_status, apply_filters('woocommerce_valid_order_statuses_for_payment', array('pending', 'on-hold', 'failed')));
     if ($order_completed && wcs_order_contains_switch($order_id) && 'paypal_standard' == get_post_meta($order_id, '_old_payment_method', true)) {
         $old_profile_id = get_post_meta($order_id, '_old_paypal_subscription_id', true);
         if (!empty($old_profile_id)) {
             $subscriptions = wcs_get_subscriptions_for_order($order_id, array('order_type' => 'switch'));
             foreach ($subscriptions as $subscription) {
                 if (!wcs_is_paypal_profile_a($old_profile_id, 'billing_agreement')) {
                     $new_payment_method = $subscription->payment_method;
                     $new_profile_id = get_post_meta($subscription->id, '_paypal_subscription_id', true);
                     // grab the current paypal subscription id in case it's a billing agreement
                     update_post_meta($subscription->id, '_payment_method', 'paypal');
                     update_post_meta($subscription->id, '_paypal_subscription_id', $old_profile_id);
                     WCS_PayPal_Status_Manager::suspend_subscription($subscription);
                     // restore payment meta to the new data
                     update_post_meta($subscription->id, '_payment_method', $new_payment_method);
                     update_post_meta($subscription->id, '_paypal_subscription_id', $new_profile_id);
                 }
             }
         }
     }
 }
 /**
  * When a store manager or user reactivates a subscription in the store, also reactivate the subscription with PayPal.
  *
  * How PayPal Handles suspension is discussed here: https://www.x.com/developers/paypal/forums/nvp/reactivate-recurring-profile
  *
  * @since 1.1
  */
 public static function reactivate_subscription_with_paypal($order, $product_id)
 {
     _deprecated_function(__METHOD__, '2.0', 'WCS_PayPal::reactivate_subscription( $subscription )');
     foreach (wcs_get_subscriptions_for_order($order, array('order_type' => 'parent')) as $subscription) {
         WCS_PayPal_Status_Manager::reactivate_subscription($subscription);
     }
 }