LLMS_Controller_Orders::switch_payment_source()

Handle form submission of the “Update Payment Method” form on the student dashboard when viewing a single order


Description Description


Return Return

(void)


Top ↑

Source Source

File: includes/controllers/class.llms.controller.orders.php

	public function switch_payment_source() {

		// invalid nonce or the form wasn't submitted
		if ( ! llms_verify_nonce( '_switch_source_nonce', 'llms_switch_order_source', 'POST' ) ) {
			return;
		} elseif ( ! isset( $_POST['order_id'] ) && ! is_numeric( $_POST['order_id'] ) && 0 == $_POST['order_id'] ) {
			return llms_add_notice( __( 'Missing order information.', 'lifterlms' ), 'error' );
		}

		$order = llms_get_post( $_POST['order_id'] );
		if ( ! $order || get_current_user_id() != $order->get( 'user_id' ) ) {
			return llms_add_notice( __( 'Invalid Order.', 'lifterlms' ), 'error' );
		} elseif ( empty( $_POST['llms_payment_gateway'] ) ) {
			return llms_add_notice( __( 'Missing gateway information.', 'lifterlms' ), 'error' );
		}

		$plan = llms_get_post( $order->get( 'plan_id' ) );
		$gateway_id = sanitize_text_field( $_POST['llms_payment_gateway'] );
		$gateway = $this->validate_selected_gateway( $gateway_id, $plan );

		if ( is_wp_error( $gateway ) ) {
			return llms_add_notice( $gateway->get_error_message(), 'error' );
		}

		// handoff to the gateway
		$gateway->handle_payment_source_switch( $order, $_POST );

		// if the order is pending cancel and there were no errors returned activate it
		if ( 'llms-pending-cancel' === $order->get( 'status' ) && ! llms_notice_count( 'error' ) ) {
			$order->set_status( 'active' );
		}

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.10.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.





Permalink: