/** * Get available statuses. * * @return array */ public static function get_statuses() { _ib_edu_deprecated_function('IB_Educator_Payment::get_statuses', '1.7', 'edr_get_payment_statuses'); return edr_get_payment_statuses(); }
/** * 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; } } } }
?> </th> <th><?php _e('Payment Status', 'ibeducator'); ?> </th> <th><?php _e('Amount', 'ibeducator'); ?> </th> <th></th> </tr> </thead> <tbody> <?php $statuses = edr_get_payment_statuses(); ?> <?php foreach ($payments as $payment) { ?> <tr> <td><?php echo absint($payment->ID); ?> </td> <td><?php echo esc_html(date_i18n(get_option('date_format'), strtotime($payment->payment_date))); ?> </td> <td> <?php
/** * Prepare items. * Fetch and setup payments(items). */ public function prepare_items() { $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns()); $statuses = edr_get_payment_statuses(); $args = array('per_page' => $this->get_items_per_page('payments_per_page', 10), 'page' => $this->get_pagenum()); if (!empty($_GET['status']) && array_key_exists($_GET['status'], $statuses)) { $args['payment_status'] = array($_GET['status']); } if (!empty($_GET['id'])) { $args['payment_id'] = $_GET['id']; } if (!empty($_GET['payment_type'])) { $args['payment_type'] = $_GET['payment_type']; } $payments = IB_Educator::get_instance()->get_payments($args); if (!empty($payments)) { $this->set_pagination_args(array('total_items' => $payments['num_items'], 'per_page' => $args['per_page'])); $this->items = $payments['rows']; } }