function process_order_paypal_standard()
 {
     if (!empty($_REQUEST['learn-press-transaction-method']) && 'paypal-standard' == $_REQUEST['learn-press-transaction-method']) {
         // if we have a paypal-nonce in $_REQUEST that meaning user has clicked go back to our site after finished the transaction
         // so, create a new order
         if (!empty($_REQUEST['paypal-nonce']) && wp_verify_nonce($_REQUEST['paypal-nonce'], 'learn-press-paypal-nonce')) {
             if (!empty($_REQUEST['tx'])) {
                 //if PDT is enabled
                 $transaction_id = $_REQUEST['tx'];
             } else {
                 if (!empty($_REQUEST['txn_id'])) {
                     //if PDT is not enabled
                     $transaction_id = $_REQUEST['txn_id'];
                 } else {
                     $transaction_id = NULL;
                 }
             }
             if (!empty($_REQUEST['cm'])) {
                 $transient_transaction_id = $_REQUEST['cm'];
             } else {
                 if (!empty($_REQUEST['custom'])) {
                     $transient_transaction_id = $_REQUEST['custom'];
                 } else {
                     $transient_transaction_id = NULL;
                 }
             }
             if (!empty($_REQUEST['st'])) {
                 //if PDT is enabled
                 $transaction_status = $_REQUEST['st'];
             } else {
                 if (!empty($_REQUEST['payment_status'])) {
                     //if PDT is not enabled
                     $transaction_status = $_REQUEST['payment_status'];
                 } else {
                     $transaction_status = NULL;
                 }
             }
             if (!empty($transaction_id) && !empty($transient_transaction_id) && !empty($transaction_status)) {
                 $user = learn_press_get_current_user();
                 try {
                     //If the transient still exists, delete it and add the official transaction
                     if ($transaction_object = learn_press_get_transient_transaction('lpps', $transient_transaction_id)) {
                         learn_press_delete_transient_transaction('lpps', $transient_transaction_id);
                         $order_id = $this->get_order_id($transaction_id);
                         $order_id = learn_press_add_transaction(array('order_id' => $order_id, 'method' => 'paypal-standard', 'method_id' => $transaction_id, 'status' => $transaction_status, 'user_id' => $user->ID, 'transaction_object' => $transaction_object['transaction_object']));
                         wp_redirect(($confirm_page_id = learn_press_get_page_id('taken_course_confirm')) && get_post($confirm_page_id) ? learn_press_get_order_confirm_url($order_id) : get_site_url());
                         die;
                     }
                 } catch (Exception $e) {
                     return false;
                 }
             } else {
                 if (is_null($transaction_id) && is_null($transient_transaction_id) && is_null($transaction_status)) {
                 }
             }
         }
     }
     wp_redirect(get_site_url());
     die;
 }
예제 #2
0
/**
 * Action when user press the "Take this course" button
 *
 * @param $course_id
 * @param string $payment_method
 */
function learn_press_take_course($course_id, $payment_method = '')
{
    $user = learn_press_get_current_user();
    $can_take_course = apply_filters('learn_press_before_take_course', true, $user->ID, $course_id, $payment_method);
    if ($can_take_course) {
        if (learn_press_is_free_course($course_id)) {
            if ($order_id = learn_press_add_transaction(array('method' => 'free', 'method_id' => '', 'status' => '', 'user_id' => $user->ID, 'transaction_object' => learn_press_generate_transaction_object()))) {
                learn_press_update_order_status($order_id, 'Completed');
                learn_press_add_message('message', __('Congratulations! You have enrolled this course'));
                $json = array('result' => 'success', 'redirect' => ($confirm_page_id = learn_press_get_page_id('taken_course_confirm')) && get_post($confirm_page_id) ? learn_press_get_order_confirm_url($order_id) : get_permalink($course_id));
                learn_press_send_json($json);
            }
        } else {
            if (has_filter('learn_press_take_course_' . $payment_method)) {
                $order = null;
                $result = apply_filters('learn_press_take_course_' . $payment_method, $order);
                $result = apply_filters('learn_press_payment_result', $result, $order);
                if (is_ajax()) {
                    learn_press_send_json($result);
                    exit;
                } else {
                    wp_redirect($result['redirect']);
                    exit;
                }
            } else {
                wp_die(__('Invalid payment method.', 'learn_press'));
            }
        }
    } else {
        learn_press_add_message('error', __('Sorry! You can not enroll to this course'));
        $json = array('result' => 'error', 'redirect' => get_permalink($course_id));
        echo '<!--LPR_START-->' . json_encode($json) . '<!--LPR_END-->';
    }
}