Skip to content

Commit

Permalink
revert code back to its original form + add trigger event
Browse files Browse the repository at this point in the history
  • Loading branch information
Buda9 committed Sep 21, 2024
1 parent af49072 commit eeae69d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion classes/payment/service_provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
16 changes: 16 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit eeae69d

Please sign in to comment.