LLMS_Controller_Orders::create_pending_order()
Handle form submission of the checkout / payment form
Description Description
-
Logs in or Registers a user
- Validates all fields
- Handles coupon pricing adjustments
-
Creates a PENDING llms_order
If errors, returns error on screen to user If success, passes to the selected gateways "process_payment" method the process_payment method should complete by returning an error or triggering the "lifterlms_process_payment_redirect" // todo check this last statement
Return Return
(void)
Source Source
File: includes/controllers/class.llms.controller.orders.php
public function create_pending_order() { if ( ! llms_verify_nonce( '_llms_checkout_nonce', 'create_pending_order', 'POST' ) ) { return; } if ( empty( $_POST['action'] ) || 'create_pending_order' !== $_POST['action'] ) { return; } // prevent timeout @set_time_limit( 0 ); /** * Allow gateways, extensions, etc to do their own validation prior to standard validation * If this returns a truthy, we'll stop processing * The extension should add a notice in addition to returning the truthy */ if ( apply_filters( 'llms_before_checkout_validation', false ) ) { return; } // setup data to pass to the pending order creation function $data = array(); $keys = array( 'llms_plan_id', 'llms_agree_to_terms', 'llms_payment_gateway', 'llms_coupon_code', ); foreach ( $keys as $key ) { if ( isset( $_POST[ $key ] ) ) { $data[ str_replace( 'llms_', '', $key ) ] = $_POST[ $key ]; } } $data['customer'] = array(); if ( get_current_user_id() ) { $data['customer']['user_id'] = get_current_user_id(); } foreach ( LLMS_Person_Handler::get_available_fields( 'checkout' ) as $cust_field ) { $cust_key = $cust_field['id']; if ( isset( $_POST[ $cust_key ] ) ) { $data['customer'][ $cust_key ] = $_POST[ $cust_key ]; } } $setup = llms_setup_pending_order( $data ); if ( is_wp_error( $setup ) ) { foreach ( $setup->get_error_messages() as $msg ) { llms_add_notice( $msg, 'error' ); } // existing user fails validation from the free checkout form if ( get_current_user_id() && isset( $_POST['form'] ) && 'free_enroll' === $_POST['form'] && isset( $_POST['llms_plan_id'] ) ) { $plan = llms_get_post( $_POST['llms_plan_id'] ); wp_redirect( $plan->get_checkout_url() ); exit; } return; } /** * Allow gateways, extensions, etc to do their own validation * after all standard validations are successfully * If this returns a truthy, we'll stop processing * The extension should add a notice in addition to returning the truthy */ if ( apply_filters( 'llms_after_checkout_validation', false ) ) { return; } $order_id = 'new'; // get order ID by Key if it exists if ( ! empty( $_POST['llms_order_key'] ) ) { $locate = llms_get_order_by_key( $_POST['llms_order_key'], 'id' ); if ( $locate ) { $order_id = $locate; } } // instantiate the order $order = new LLMS_Order( $order_id ); // if there's no id we can't proceed, return an error if ( ! $order->get( 'id' ) ) { return llms_add_notice( __( 'There was an error creating your order, please try again.', 'lifterlms' ), 'error' ); } // add order key to globals so the order can be retried if processing errors occur $_POST['llms_order_key'] = $order->get( 'order_key' ); $order->init( $setup['person'], $setup['plan'], $setup['gateway'], $setup['coupon'] ); // pass to the gateway to start processing $setup['gateway']->handle_pending_order( $order, $setup['plan'], $setup['person'], $setup['coupon'] ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: