public/wordpress/wp-content/plugins/wp-courseware/includes/gateways/gateway-paypal.php
/**
	 * Process Subscription Cancellation.
	 *
	 * @since 4.3.0
	 *
	 * @param Subscription $subscription The subscription object.
	 *
	 * @return bool True if successful, False otherwise.
	 */
Process Subscription Cancellation.

@param Subscription $subscription The subscription object.

@return bool True if successful, False otherwise.
Process Subscription Cancellation . @param Subscription $subscription The subscription object . @return bool True if successful False otherwise .
public function process_subscription_cancellation( $subscription ) {
		$this->setup();
		$request_body = apply_filters( 'wpcw_gateway_paypal_cancel_subscription_api_request_body_args', array(
			'USER'      => $this->get_api_username(),
			'PWD'       => $this->get_api_password(),
			'SIGNATURE' => $this->get_api_signature(),
			'VERSION'   => '124',
			'METHOD'    => 'ManageRecurringPaymentsProfileStatus',
			'PROFILEID' => $subscription->get_profile_id(),
			'ACTION'    => 'Cancel',
		), $subscription, $this );
		$request_headers = apply_filters( 'wpcw_gateway_paypal_cancel_subscription_api_request_headers', array(
			'Content-Type'  => 'application/x-www-form-urlencoded',
			'Cache-Control' => 'no-cache',
		), $subscription, $this );
		$request_args = apply_filters( 'wpcw_gateway_paypal_cancel_subscription_request_args', array(
			'body'        => $request_body,
			'headers'     => $request_headers,
			'timeout'     => 30,
			'httpversion' => '1.1',
		), $subscription, $this );
		$error   = '';
		$request = wp_remote_post( $this->get_api_endpoint(), $request_args );
		$success = false;
		if ( is_wp_error( $request ) ) {
			$error = $request->get_error_message();
		} else {
			$body    = wp_remote_retrieve_body( $request );
			$code    = wp_remote_retrieve_response_code( $request );
			$message = wp_remote_retrieve_response_message( $request );
			if ( is_string( $body ) ) {
				wp_parse_str( $body, $body );
			}
			if ( empty( $code ) || 200 !== (int) $code ) {
				$success = false;
			}
			if ( empty( $message ) || 'OK' !== $message ) {
				$success = false;
			}
			$this->log( 'PayPal Subscription Cancellation Response Body' . wpcw_print_r( $body, true ) );
			if ( isset( $body['ACK'] ) && 'success' === strtolower( $body['ACK'] ) ) {
				$success = true;
			} else {
				if ( isset( $body['L_LONGMESSAGE0'] ) ) {
					$error = $body['L_LONGMESSAGE0'];
				} else {
					$error = esc_html__( 'PayPal failed to cancel the subscription for an unknown reason.', 'wp-courseware' );
				}
			}
			$cancelled_codes = apply_filters( 'wpcw_gateway_paypal_cancel_codes', array( 11556, 11557, 11531 ) );
			if ( $error && in_array( $error, $cancelled_codes ) ) {
				$success = true;
			}
			do_action( 'wpcw_gateway_paypal_after_subscription_cancellation_request', $subscription, $body, $code, $message, $error );
		}
		if ( $success ) {
			if ( ! $subscription->is_expired() && ! $subscription->has_status( 'refunded' ) ) {
				$subscription->cancel_at_period_end();
			} else {
				$subscription->cancel();
			}
		} else {
			$subscription->add_note( sprintf( __( 'Subscription Failed to Cancel. PayPal Error: %s', 'wp-courseware' ), $error ) );
		}
		do_action( 'wpcw_gateway_paypal_subscription_cancellation', $subscription );
		return $success;
	}
public function process_subscription_cancellation ( $ subscription ) { $ this -> setup ( ) ; $ request_body = apply_filters ( 'wpcw_gateway_paypal_cancel_subscription_api_request_body_args' , array ( 'USER' => $ this -> get_api_username ( ) , 'PWD' => $ this -> get_api_password ( ) , 'SIGNATURE' => $ this -> get_api_signature ( ) , 'VERSION' => '124' , 'METHOD' => 'ManageRecurringPaymentsProfileStatus' , 'PROFILEID' => $ subscription -> get_profile_id ( ) , 'ACTION' => 'Cancel' , ) , $ subscription , $ this ) ; $ request_headers = apply_filters ( 'wpcw_gateway_paypal_cancel_subscription_api_request_headers' , array ( 'Content-Type' => 'application/x-www-form-urlencoded' , 'Cache-Control' => 'no-cache' , ) , $ subscription , $ this ) ; $ request_args = apply_filters ( 'wpcw_gateway_paypal_cancel_subscription_request_args' , array ( 'body' => $ request_body , 'headers' => $ request_headers , 'timeout' => 30 , 'httpversion' => '1.1' , ) , $ subscription , $ this ) ; $ error = '' ; $ request = wp_remote_post ( $ this -> get_api_endpoint ( ) , $ request_args ) ; $ success = false ; if ( is_wp_error ( $ request ) ) { $ error = $ request -> get_error_message ( ) ; } else { $ body = wp_remote_retrieve_body ( $ request ) ; $ code = wp_remote_retrieve_response_code ( $ request ) ; $ message = wp_remote_retrieve_response_message ( $ request ) ; if ( is_string ( $ body ) ) { wp_parse_str ( $ body , $ body ) ; } if ( empty ( $ code ) || 200 !== ( int ) $ code ) { $ success = false ; } if ( empty ( $ message ) || 'OK' !== $ message ) { $ success = false ; } $ this -> log ( 'PayPal Subscription Cancellation Response Body' . wpcw_print_r ( $ body , true ) ) ; if ( isset ( $ body [ 'ACK' ] ) && 'success' === strtolower ( $ body [ 'ACK' ] ) ) { $ success = true ; } else { if ( isset ( $ body [ 'L_LONGMESSAGE0' ] ) ) { $ error = $ body [ 'L_LONGMESSAGE0' ] ; } else { $ error = esc_html__ ( 'PayPal failed to cancel the subscription for an unknown reason.' , 'wp-courseware' ) ; } } $ cancelled_codes = apply_filters ( 'wpcw_gateway_paypal_cancel_codes' , array ( 11556 , 11557 , 11531 ) ) ; if ( $ error && in_array ( $ error , $ cancelled_codes ) ) { $ success = true ; } do_action ( 'wpcw_gateway_paypal_after_subscription_cancellation_request' , $ subscription , $ body , $ code , $ message , $ error ) ; } if ( $ success ) { if ( ! $ subscription -> is_expired ( ) && ! $ subscription -> has_status ( 'refunded' ) ) { $ subscription -> cancel_at_period_end ( ) ; } else { $ subscription -> cancel ( ) ; } } else { $ subscription -> add_note ( sprintf ( __ ( 'Subscription Failed to Cancel. PayPal Error: %s' , 'wp-courseware' ) , $ error ) ) ; } do_action ( 'wpcw_gateway_paypal_subscription_cancellation' , $ subscription ) ; return $ success ; }
Process Subscription Cancellation.
Process Subscription Cancellation .
// Setup Gateway. /**
		 * Filter: PayPal Cancel Subscription Request Body Args.
		 *
		 * @since 4.3.0
		 *
		 * @param array The array of args for the request body.
		 * @param Subscription   $subscription The subscription object.
		 * @param Gateway_Paypal $this The gateway object.
		 *
		 * @return array The array of args for the request body.
		 */ /**
		 * Filter: PayPal Cancel Subscription Request Headers.
		 *
		 * @since 4.3.0
		 *
		 * @param array The array of request headers.
		 * @param Subscription   $subscription The subscription object.
		 * @param Gateway_Paypal $this The gateway object.
		 *
		 * @return array The array of request headers.
		 */ /**
		 * Filter: PayPal Cancel Subscription Request Args.
		 *
		 * @since 4.3.0
		 *
		 * @param array The array of request args.
		 * @param Subscription   $subscription The order object.
		 * @param Gateway_Paypal $this The gateway object.
		 *
		 * @return array he array of request args.
		 */ /**
			 * Sometimes a subscription has already been cancelled in PayPal and PayPal returns an error indicating it's not active
			 * Let's catch those cases and consider the cancellation successful.
			 *
			 * @since 4.3.0
			 */ /**
			 * Action: Subscription Cancellation.
			 *
			 * @since 4.3.0
			 *
			 * @param Subscription $subscription The subscription object.
			 * @param mixed        $body The request response body.
			 * @param string       $code The request response code.
			 * @param string       $message The request response message if any.
			 * @param string       $error The request response error if any.
			 */ /**
		 * Action: Subscription Cancellation.
		 *
		 * @since 4.3.0
		 *
		 * @param Subscription $subscription The subscription object.
		 */