diff --git a/classes/payment/service_provider.php b/classes/payment/service_provider.php index 1fb14980..8594e0cc 100644 --- a/classes/payment/service_provider.php +++ b/classes/payment/service_provider.php @@ -160,7 +160,12 @@ public static function deliver_order(string $paymentarea, int $itemid, int $paym } else { $response = $op->credit($item->cost, op::C_PAYMENT, $itemid, $desc); - return $response; + + if ($response) { + return true; + } else { + return false; + } } } } diff --git a/lib.php b/lib.php index dfca9fad..bd59382c 100644 --- a/lib.php +++ b/lib.php @@ -440,6 +440,22 @@ public function enrol_self(stdClass $instance, $user = null, $charge = true) { do { $this->enrol_user($instance, $user->id, $instance->roleid, $timestart, $timeend, null, true); } while (!$DB->record_exists('user_enrolments', $conditions)); + + try { + // Trigger event for successful enrolment. + $params = [ + 'context' => context_course::instance($instance->courseid), + 'objectid' => $instance->id, + 'courseid' => $instance->courseid, + 'relateduserid' => $user->id, + ]; + $event = \core\event\user_enrolment_created::create($params); + $event->trigger(); + } catch (\Exception $e) { + // Log the error but don't stop the enrolment process + debugging('Error triggering enrolment event: ' . $e->getMessage(), DEBUG_DEVELOPER); + } + } catch (\moodle_exception $e) { // Rollback the transaction in case of error. if ($charge) {