public/wordpress/wp-content/plugins/wp-courseware/includes/gateways/gateway-stripe.php
/**
	 * Process Subscription Cancellation.
	 *
	 * @since 4.3.0
	 *
	 * @param Subscription $subscription The subscription object.
	 */
Process Subscription Cancellation.

@param Subscription $subscription The subscription object.
Process Subscription Cancellation . @param Subscription $subscription The subscription object .
public function process_subscription_cancellation( $subscription ) {
		try {
			if ( ! $subscription instanceof Subscription ) {
				throw new Stripe_Exception( 'stripe-subscription-not-setup', __( 'The subscription is not setup. Aborting cancellation...', 'wp-courseware' ) );
			}
			$this->setup();
			$profile_id = $subscription->get_profile_id();
			if ( empty( $profile_id ) ) {
				throw new Stripe_Exception( 'stripe-subscription-profile-id-not-set', __( 'The subscription profile id is not setup. Aborting cancellation...', 'wp-courseware' ) );
			}
			if ( ! $subscription->has_status( 'refunded' ) ) {
				$stripe_subscription = $this->get_api()->update_subscription( $profile_id, array( 'cancel_at_period_end' => true ) );
			} else {
				$stripe_subscription = $this->get_api()->get_subscription( $profile_id );
			}
			if ( ! empty( $stripe_subscription->error ) ) {
				throw new Stripe_Exception( $stripe_subscription->error->type, $stripe_subscription->error->message );
			}
			if ( true === $stripe_subscription->cancel_at_period_end ) {
				$subscription->cancel_at_period_end();
			} else {
				$stripe_subscription->cancel();
				$subscription->cancel();
			}
		} catch ( Stripe_Exception $exception ) {
			$this->log( sprintf( __( 'An error occurred while trying to cancel the subscription. Error Message: %s', 'wp-courseware' ), $exception->getLocalizedMessage() ) );
			return false;
		}
		return true;
	}
public function process_subscription_cancellation ( $ subscription ) { try { if ( ! $ subscription instanceof Subscription ) { throw new Stripe_Exception ( 'stripe-subscription-not-setup' , __ ( 'The subscription is not setup. Aborting cancellation...' , 'wp-courseware' ) ) ; } $ this -> setup ( ) ; $ profile_id = $ subscription -> get_profile_id ( ) ; if ( empty ( $ profile_id ) ) { throw new Stripe_Exception ( 'stripe-subscription-profile-id-not-set' , __ ( 'The subscription profile id is not setup. Aborting cancellation...' , 'wp-courseware' ) ) ; } if ( ! $ subscription -> has_status ( 'refunded' ) ) { $ stripe_subscription = $ this -> get_api ( ) -> update_subscription ( $ profile_id , array ( 'cancel_at_period_end' => true ) ) ; } else { $ stripe_subscription = $ this -> get_api ( ) -> get_subscription ( $ profile_id ) ; } if ( ! empty ( $ stripe_subscription -> error ) ) { throw new Stripe_Exception ( $ stripe_subscription -> error -> type , $ stripe_subscription -> error -> message ) ; } if ( true === $ stripe_subscription -> cancel_at_period_end ) { $ subscription -> cancel_at_period_end ( ) ; } else { $ stripe_subscription -> cancel ( ) ; $ subscription -> cancel ( ) ; } } catch ( Stripe_Exception $ exception ) { $ this -> log ( sprintf ( __ ( 'An error occurred while trying to cancel the subscription. Error Message: %s' , 'wp-courseware' ) , $ exception -> getLocalizedMessage ( ) ) ) ; return false ; } return true ; }
Process Subscription Cancellation.
Process Subscription Cancellation .