/**
  * Get available types.
  *
  * @return array
  */
 public static function get_types()
 {
     _ib_edu_deprecated_function('IB_Educator_Payment::get_types', '1.7', 'edr_get_payment_types');
     return edr_get_payment_types();
 }
Exemple #2
0
 /**
  * Edit payment action.
  */
 public static function edit_payment()
 {
     $payment_id = isset($_GET['payment_id']) ? absint($_GET['payment_id']) : 0;
     $payment = edr_get_payment($payment_id);
     $errors = array();
     if (count($_POST)) {
         // Verify nonce.
         check_admin_referer('ib_educator_edit_payment_' . $payment_id);
         // Capability check.
         if (!current_user_can('manage_educator')) {
             return;
         }
         // Payment type.
         if (isset($_POST['payment_type']) && array_key_exists($_POST['payment_type'], edr_get_payment_types())) {
             $payment->payment_type = $_POST['payment_type'];
         }
         // Student ID.
         if (empty($payment->user_id)) {
             if (!empty($_POST['student_id']) && is_numeric($_POST['student_id'])) {
                 $payment->user_id = $_POST['student_id'];
             } else {
                 $errors[] = 'empty_student_id';
             }
         }
         // Course ID.
         if (empty($payment->course_id)) {
             if (!empty($_POST['course_id']) && is_numeric($_POST['course_id'])) {
                 $payment->course_id = $_POST['course_id'];
             } elseif ('course' == $payment->payment_type) {
                 $errors[] = 'empty_course_id';
             }
         }
         // Object ID.
         if (isset($_POST['object_id']) && is_numeric($_POST['object_id'])) {
             $payment->object_id = $_POST['object_id'];
         }
         // Tax.
         if (isset($_POST['tax']) && is_numeric($_POST['tax'])) {
             $payment->tax = $_POST['tax'];
         }
         // Amount.
         if (isset($_POST['amount']) && is_numeric($_POST['amount'])) {
             $payment->amount = $_POST['amount'];
         }
         if (isset($_POST['currency'])) {
             $payment->currency = sanitize_text_field($_POST['currency']);
         }
         // Transaction ID.
         if (isset($_POST['txn_id'])) {
             $payment->txn_id = sanitize_text_field($_POST['txn_id']);
         }
         // Payment status.
         if (isset($_POST['payment_status']) && array_key_exists($_POST['payment_status'], edr_get_payment_statuses())) {
             $payment->payment_status = $_POST['payment_status'];
         }
         // Payment gateway.
         if (isset($_POST['payment_gateway'])) {
             $payment->payment_gateway = sanitize_title($_POST['payment_gateway']);
         }
         // First Name.
         if (isset($_POST['first_name'])) {
             $payment->first_name = sanitize_text_field($_POST['first_name']);
         }
         // Last Name.
         if (isset($_POST['last_name'])) {
             $payment->last_name = sanitize_text_field($_POST['last_name']);
         }
         // Address.
         if (isset($_POST['address'])) {
             $payment->address = sanitize_text_field($_POST['address']);
         }
         // Address Line 2.
         if (isset($_POST['address_2'])) {
             $payment->address_2 = sanitize_text_field($_POST['address_2']);
         }
         // City.
         if (isset($_POST['city'])) {
             $payment->city = sanitize_text_field($_POST['city']);
         }
         // Postcode.
         if (isset($_POST['postcode'])) {
             $payment->postcode = sanitize_text_field($_POST['postcode']);
         }
         // State / Province.
         if (isset($_POST['state'])) {
             $payment->state = sanitize_text_field($_POST['state']);
         }
         // Country.
         if (isset($_POST['country'])) {
             $payment->country = sanitize_text_field($_POST['country']);
         }
         if (!empty($errors)) {
             ib_edu_message('edit_payment_errors', $errors);
             return;
         }
         if ($payment->save()) {
             // Update payment meta.
             if (isset($_POST['line_id']) && is_array($_POST['line_id'])) {
                 foreach ($_POST['line_id'] as $key => $line_id) {
                     if (!is_numeric($line_id)) {
                         continue;
                     }
                     $payment->update_line(array('ID' => $line_id, 'object_id' => isset($_POST['line_object_id'][$key]) ? intval($_POST['line_object_id'][$key]) : 0, 'line_type' => isset($_POST['line_type'][$key]) ? sanitize_text_field($_POST['line_type'][$key]) : '', 'amount' => isset($_POST['line_amount'][$key]) ? sanitize_text_field($_POST['line_amount'][$key]) : 0.0, 'tax' => isset($_POST['line_tax'][$key]) ? sanitize_text_field($_POST['line_tax'][$key]) : 0.0, 'name' => isset($_POST['line_name'][$key]) ? sanitize_text_field($_POST['line_name'][$key]) : ''));
                 }
             }
             $api = IB_Educator::get_instance();
             $entry_saved = true;
             // Create entry for the student.
             // Implemented for the "course" payment type.
             if (isset($_POST['create_entry']) && !$api->get_entry(array('payment_id' => $payment->ID))) {
                 $entry = edr_get_entry();
                 $entry->course_id = $payment->course_id;
                 $entry->user_id = $payment->user_id;
                 $entry->payment_id = $payment->ID;
                 $entry->entry_status = 'inprogress';
                 $entry->entry_date = date('Y-m-d H:i:s');
                 $entry_saved = $entry->save();
                 if ($entry_saved) {
                     // Send notification email to the student.
                     $student = get_user_by('id', $payment->user_id);
                     $course = get_post($payment->course_id, OBJECT, 'display');
                     if ($student && $course) {
                         ib_edu_send_notification($student->user_email, 'student_registered', array('course_title' => $course->post_title), array('student_name' => $student->display_name, 'course_title' => $course->post_title, 'course_excerpt' => $course->post_excerpt));
                     }
                 }
             }
             // Setup membership for the student.
             if (isset($_POST['setup_membership']) && 'membership' == $payment->payment_type) {
                 $ms = Edr_Memberships::get_instance();
                 // Setup membership.
                 $ms->setup_membership($payment->user_id, $payment->object_id);
                 // Send notification email.
                 $student = get_user_by('id', $payment->user_id);
                 $membership = $ms->get_membership($payment->object_id);
                 if ($student && $membership) {
                     $user_membership = $ms->get_user_membership($student->ID);
                     $membership_meta = $ms->get_membership_meta($membership->ID);
                     $expiration = $user_membership ? $user_membership['expiration'] : 0;
                     ib_edu_send_notification($student->user_email, 'membership_register', array(), array('student_name' => $student->display_name, 'membership' => $membership->post_title, 'expiration' => $expiration ? date_i18n(get_option('date_format'), $expiration) : __('None', 'ibeducator'), 'price' => $ms->format_price($membership_meta['price'], $membership_meta['duration'], $membership_meta['period'], false)));
                 }
             }
             if ($entry_saved) {
                 wp_redirect(admin_url('admin.php?page=ib_educator_payments&edu-action=edit-payment&payment_id=' . $payment->ID . '&edu-message=saved'));
                 exit;
             }
         }
     }
 }
Exemple #3
0
<?php

if (!defined('ABSPATH')) {
    exit;
}
if (!current_user_can('manage_educator')) {
    echo '<p>' . __('Access denied', 'ibeducator') . '</p>';
    return;
}
$payment_id = isset($_GET['payment_id']) ? absint($_GET['payment_id']) : 0;
$payment = edr_get_payment($payment_id);
$payment_statuses = edr_get_payment_statuses();
$types = edr_get_payment_types();
$api = IB_Educator::get_instance();
$student = null;
$post = null;
if ($payment->ID) {
    $student = get_user_by('id', $payment->user_id);
    if ('course' == $payment->payment_type) {
        $post = get_post($payment->course_id);
    } elseif ('membership' == $payment->payment_type) {
        $post = get_post($payment->object_id);
    }
} else {
    if (isset($_POST['payment_type']) && array_key_exists($_POST['payment_type'], $types)) {
        $payment->payment_type = $_POST['payment_type'];
    } else {
        $payment->payment_type = 'course';
    }
}
$edu_countries = Edr_Countries::get_instance();
Exemple #4
0
    /**
     * Display the filters form.
     */
    public function display_payment_filters()
    {
        $types = edr_get_payment_types();
        $statuses = edr_get_payment_statuses();
        ?>
		<div class="ib-edu-tablenav top">
			<form class="ib-edu-admin-search" action="<?php 
        echo esc_url(admin_url('admin.php'));
        ?>
" method="get">
				<input type="hidden" name="page" value="ib_educator_payments">
				<div class="block">
					<label for="search-payment-id"><?php 
        echo _x('ID', 'ID of an item', 'ibeducator');
        ?>
</label>
					<input type="text" id="search-payment-id" name="id" value="<?php 
        if (!empty($_GET['id'])) {
            echo intval($_GET['id']);
        }
        ?>
">
				</div>
				<div class="block">
					<label for="search-payment-type"><?php 
        _e('Payment Type', 'ibeducator');
        ?>
</label>
					<select id="search-payment-type" name="payment_type">
						<option value=""><?php 
        _e('All', 'ibeducator');
        ?>
</option>
						<?php 
        foreach ($types as $t_value => $t_name) {
            $selected = isset($_GET['payment_type']) && $t_value == $_GET['payment_type'] ? ' selected="selected"' : '';
            echo '<option value="' . esc_attr($t_value) . '"' . $selected . '>' . esc_html($t_name) . '</option>';
        }
        ?>
					</select>
				</div>
				<div class="block">
					<label for="search-payment-status"><?php 
        _e('Status', 'ibeducator');
        ?>
</label>
					<select id="search-payment-status" name="status">
						<option value=""><?php 
        _e('All', 'ibeducator');
        ?>
</option>
						<?php 
        foreach ($statuses as $key => $value) {
            $selected = isset($_GET['status']) && $key == $_GET['status'] ? ' selected="selected"' : '';
            echo '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($value) . '</option>';
        }
        ?>
					</select>
				</div>
				<div class="block">
					<input type="submit" class="button" value="<?php 
        _e('Search', 'ibeducator');
        ?>
">
				</div>
			</form>
		</div>
		<?php 
    }