/** * Fires when a student is updated through the payment page. * For example, being logged in, a user purchases a new course or a membership. * * @param int $user_id * @param WP_Post $object */ public static function update_student($user_id, $object) { $data = array(); if (ib_edu_collect_billing_data($object)) { $data['first_name'] = $_POST['billing_first_name']; $data['last_name'] = $_POST['billing_last_name']; // Update billing data. self::save_billing_data($user_id); } if (!empty($data)) { $data['ID'] = $user_id; wp_update_user($data); } }
/** * Create payment. * * @param int $object_id ID of the object the payment is to be associated with. * @param int $user_id * @param string $payment_type * @return IB_Educator_Payment */ public function create_payment($object_id, $user_id, $payment_type, $atts = array()) { $payment = IB_Educator_Payment::get_instance(); $payment->user_id = $user_id; $payment->payment_type = $payment_type; $payment->payment_status = 'pending'; $payment->payment_gateway = $this->get_id(); $payment->currency = ib_edu_get_currency(); if ('course' == $payment_type) { $payment->course_id = $object_id; $payment->amount = ib_edu_get_course_price($object_id); } elseif ('membership' == $payment_type) { $payment->object_id = $object_id; $payment->amount = IB_Educator_Memberships::get_instance()->get_price($object_id); } $tax_data = null; if (ib_edu_collect_billing_data($object_id)) { // Save billing data. $billing = get_user_meta($user_id, '_ib_educator_billing', true); if (!is_array($billing)) { $billing = array(); } $payment->first_name = get_user_meta($user_id, 'first_name', true); $payment->last_name = get_user_meta($user_id, 'last_name', true); $payment->address = isset($billing['address']) ? $billing['address'] : ''; $payment->address_2 = isset($billing['address_2']) ? $billing['address_2'] : ''; $payment->city = isset($billing['city']) ? $billing['city'] : ''; $payment->state = isset($billing['state']) ? $billing['state'] : ''; $payment->postcode = isset($billing['postcode']) ? $billing['postcode'] : ''; $payment->country = isset($billing['country']) ? $billing['country'] : ''; // Calculate tax. $edu_tax = IB_Educator_Tax::get_instance(); $tax_data = $edu_tax->calculate_tax($edu_tax->get_tax_class_for($object_id), $payment->amount, $payment->country, $payment->state); $payment->tax = $tax_data['tax']; $payment->amount = $tax_data['total']; } if (!empty($atts['ip'])) { $payment->ip = $atts['ip']; } $payment->save(); // Save tax data. if ($tax_data) { foreach ($tax_data['taxes'] as $tax) { $payment->update_line(array('object_id' => $tax->ID, 'line_type' => 'tax', 'amount' => $tax->amount, 'name' => $tax->name)); } } return $payment; }