/** * Sends an email notification with the details of the transaction error * @param string $subject email subject line * @param array $data transaction data * @return void */ protected function send_error_to_admin($subject, $data = array()) { global $CFG; require_once $CFG->libdir . '/eventslib.php'; $admin = get_admin(); $site = get_site(); $message = sprintf("%s: Transaction #%d failed. %s \n\n", $site->fullname, $this->_transaction->get_id(), $subject); foreach ($data as $key => $value) { $message .= "{$key} => {$value}\n"; } // Update the transaction with the error message details $this->_transaction->set_error($message); $eventdata = new stdClass(); $eventdata->component = 'local_moodec'; $eventdata->name = 'payment_gateway'; $eventdata->userfrom = $admin; $eventdata->userto = $admin; $eventdata->subject = $this->_gatewayName . " ERROR: " . $subject; $eventdata->fullmessage = $message; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; message_send($eventdata); }
// (so we can notify the user they've been removed) $removedProducts = $cart->refresh(); // Check if a transaction has already been made for this cart if (!!$cart->get_transaction_id()) { // Get the existing transaction if the cart has recorded one $transaction = new MoodecTransaction($cart->get_transaction_id()); // We reset the transaction, in case the items in the cart have changed $transaction->reset(); } else { // Otherwise create a new transaction $transaction = new MoodecTransaction(); } // Set the transactionId in the cart to that of the transaction // We do this in case the transaction reset created a new transaction // Or, to add the transaction id to the cart if one didn't already exist $cart->set_transaction_id($transaction->get_id()); // We need to add all the products in the cart to the transaction foreach ($cart->get() as $pID => $vID) { // Get the product in the cart $product = local_moodec_get_product($pID); // Add the product to the transaction, relative to variation if ($product->get_type() === PRODUCT_TYPE_VARIABLE) { $transaction->add($pID, $product->get_variation($vID)->get_price(), $vID); } else { $transaction->add($pID, $product->get_price()); } } echo $OUTPUT->header(); ?> <h1 class="page__title"><?php