function process_message($msg)
 {
     $msg_body = json_decode($msg->body, true);
     if (isset($msg_body['params']) && is_array($msg_body['params'])) {
         $msg_body['params'] = json_encode($msg_body['params']);
     }
     $msg_body = array_values($msg_body);
     $dispatcher = new ShellDispatcher($msg_body, false);
     try {
         $dispatcher->dispatch();
     } catch (Exception $e) {
         RabbitMQ::publish(json_decode($msg->body, true), ['exchange' => 'requeueable', 'queue' => 'requeueable_messages']);
         $newMessage[] = $msg->body;
         $newMessage[] = '==>';
         $newMessage[] = $e->getMessage();
         $newMessage[] = $e->getFile();
         $newMessage[] = $e->getLine();
         $newMessage[] = $e->getTraceAsString();
         $newMessage[] = $e->getCode();
         $newMessage[] = $e->getPrevious();
         RabbitMQ::publish($newMessage, ['exchange' => 'unprocessed', 'queue' => 'unprocessed_messages']);
         EmailSender::sendEmail('*****@*****.**', $msg->body, $newMessage);
     }
     $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
     // Send a message with the string "quit" to cancel the consumer.
     if ($msg->body === 'quit') {
         $msg->delivery_info['channel']->basic_cancel($msg->delivery_info['consumer_tag']);
     }
 }
 /**
  * @param $json
  * @param $email_type
  * @return ErrorResponse|null|Response
  */
 public static function setNewPassword($json, $email_type)
 {
     $response = null;
     $missing_fields = UserController::validateJSONFormat($json, User::REQUIRED_PASSWORD_RESET_FIELD);
     // Check that required fields are not missing
     if (!$missing_fields) {
         $user_mapper = new UserDBMapper();
         $email = $json['email'];
         $user = User::fromDBArray($user_mapper->getByEmail($email));
         // Set random password
         $password = ResetPasswordController::getRandomString(ResetPasswordController::PASSWORD_LENGTH);
         $json['password'] = $password;
         $id = $user->getId();
         $reset_password_user = User::fromResetPasswordQuery($id, $json);
         if ($reset_password_user) {
             $db_response = $user_mapper->resetPassword($reset_password_user);
             if ($db_response instanceof DBError) {
                 $response = new ErrorResponse($db_response);
             } else {
                 $reset_password_user = $user_mapper->getById($id);
                 if ($reset_password_user) {
                     EmailSender::sendEmail($email, $password, $email_type);
                     // Sending Email notification
                     $response = new Response(json_encode(array('message' => ResetPasswordController::RESET_PASSWORD_ACCEPTED_MESSAGE), JSON_PRETTY_PRINT), Response::STATUS_CODE_ACCEPTED);
                 } else {
                     $response = new ErrorResponse(new NotFoundError());
                 }
             }
         }
         return $response;
     }
     return new Response($response);
 }
Exemplo n.º 3
0
 public static function run()
 {
     $start = self::_logMsg("== START: processing Messages ==", __CLASS__, __FUNCTION__);
     $messages = self::_getAndMarkMessages();
     self::_logMsg("GOT " . count($messages) . ' Message(s): ', __CLASS__, __FUNCTION__);
     foreach ($messages as $message) {
         self::_logMsg("    Looping message(ID=" . $message->getId() . ': ', __CLASS__, __FUNCTION__);
         try {
             Dao::beginTransaction();
             EmailSender::sendEmail($message->getFrom(), $message->getTo(), $message->getSubject(), $message->getBody(), $message->getAttachmentAssetIdArray());
             $message->setStatus(Message::STATUS_SENT)->save();
             Dao::commitTransaction();
             self::_logMsg("    SUCCESS sending message(ID=" . $message->getId() . ').', __CLASS__, __FUNCTION__);
         } catch (Exception $ex) {
             Dao::rollbackTransaction();
             $message->setStatus(Message::STATUS_FAILED)->save();
             self::_logMsg("    ERROR sending message(ID=" . $message->getId() . ': ' . $ex->getMessage(), __CLASS__, __FUNCTION__);
             self::_logMsg("    ERROR sending message(ID=" . $message->getId() . ': ' . $ex->getTraceAsString(), __CLASS__, __FUNCTION__);
         }
     }
     $end = new UDate();
     self::_logMsg("== FINISHED: " . count($messages) . " Message(s) == ", __CLASS__, __FUNCTION__);
 }
Exemplo n.º 4
0
     // Send email to client that txn was processed
     $logger->LogInfo("Getting confirmation email contents ...");
     $confirmationEmailContents = EmailContents::fetchFromDbForCode("Confirmation Email");
     if ($confirmationEmailContents == null) {
         $logger->LogError("Cannot find confirmation email contents!");
         $logger->LogError(EmailContents::$staticErrors);
     }
     $client = $booking->getClient();
     $clientEmail = $client->email;
     $logger->LogInfo("Personalizing email ...");
     $emailPersonalizer = new EmailPersonalizer($booking);
     $emailBody = $emailPersonalizer->customizeEmailContents($confirmationEmailContents->emailText->getText($booking->languageCode));
     $logger->LogDebug("Email body:");
     $logger->LogDebug($emailBody);
     $logger->LogInfo("Sending email to client...");
     if (!$emailSender->sendEmail($clientEmail, $confirmationEmailContents->emailSubject->getText($booking->languageCode), $emailBody)) {
         $logger->LogError("Failed to send confirmation email to client.");
     }
     /* Notify Email for Hotel about Booking */
     $notifyEmailSubject = "Booking no." . $bookingId . " - Notification of Room Booking by " . $client->firstName . " " . $client->lastName;
     $logger->LogInfo("Sending email to hotel admin...");
     if (!$emailSender->sendEmail($systemConfiguration->getHotelDetails()->getHotelEmail(), $notifyEmailSubject, $invoiceHtml)) {
         $logger->LogError("Failed to send email to the hotel admin.");
     }
 } else {
     $logger->LogWarn("IPN was not processed successfully!");
     $ipnData = file_get_contents($p->ipn_log_file);
     $logger->LogWarn("IPN data:");
     $logger->LogWarn($ipnData);
 }
 break;
Exemplo n.º 5
0
function processPayOnArrival()
{
    global $bookingDetails;
    global $systemConfiguration;
    global $logger;
    global $language_selected;
    $logger->LogInfo("Processing payment on arrival ...");
    $transactionId = "N/A";
    $booking = $bookingDetails->booking;
    $paymentGateway = $bookingDetails->paymentGateway;
    $logger->LogInfo("Creating bottom portion of invoice ...");
    $logger->LogInfo("Compposing invoice ...");
    $invoiceHtml = '<br />' . "\n";
    $invoiceHtml .= '<table  style="font-family:Verdana, Geneva, sans-serif; font-size: 12px; background:#999999; width:700px; border:none;" cellpadding="4" cellspacing="1">' . "\n";
    $invoiceHtml .= '	<tr>' . "\n";
    $invoiceHtml .= '		<td align="left" colspan="2" style="font-weight:bold; font-variant:small-caps; background:#eeeeee;">' . "\n";
    $invoiceHtml .= '			' . BOOKING_DETAILS_BILLING . "\n";
    $invoiceHtml .= '		</td>' . "\n";
    $invoiceHtml .= '	</tr>' . "\n";
    $invoiceHtml .= '	<tr>' . "\n";
    $invoiceHtml .= '		<td align="left" width="30%" style="font-weight:bold; font-variant:small-caps;background:#ffffff;" width="33%">' . "\n";
    $invoiceHtml .= '			' . BOOKING_DETAILS_PAYMENT_OPTION . "\n";
    $invoiceHtml .= '		</td>' . "\n";
    $invoiceHtml .= '		<td align="left" style="background:#ffffff;">' . "\n";
    $invoiceHtml .= '			' . $paymentGateway->gatewayName->getText($language_selected) . "\n";
    $invoiceHtml .= '		</td>' . "\n";
    $invoiceHtml .= '	</tr>' . "\n";
    $invoiceHtml .= '	<tr>' . "\n";
    $invoiceHtml .= '		<td align="left" width="30%" style="font-weight:bold; font-variant:small-caps; background:#ffffff;" width="33%">' . "\n";
    $invoiceHtml .= '			' . BOOKING_DETAILS_TRANSACTION . "\n";
    $invoiceHtml .= '		</td>' . "\n";
    $invoiceHtml .= '		<td align="left" style="background:#ffffff;">' . "\n";
    $invoiceHtml .= '			' . $transactionId . "\n";
    $invoiceHtml .= '		</td>' . "\n";
    $invoiceHtml .= '	</tr>' . "\n";
    $invoiceHtml .= '</table>' . "\n";
    $booking->invoice .= $invoiceHtml;
    $booking->paymentTransactionId = $transactionId;
    $booking->paypalEmail = "";
    $booking->isPaymentSuccessful = true;
    $logger->LogInfo("Saving booking ...");
    if (!$booking->save(true)) {
        $logger->LogFatal("Error saving booking!");
        $logger->LogFatal($booking->errors);
        die("Error: " . $booking->errors[0]);
    }
    $logger->LogInfo("Save is successful.");
    // Send email to client that txn was processed
    $logger->LogInfo("Getting confirmation email contents ...");
    $confirmationEmailContents = EmailContents::fetchFromDbForCode("Confirmation Email");
    if ($confirmationEmailContents == null) {
        $logger->LogFatal("Could not find confirmation email contents.");
        die("Cannot find confirmation email details");
    }
    $client = $booking->getClient();
    $clientEmail = $client->email;
    $logger->LogInfo("Personalizing email ...");
    $emailPersonalizer = new EmailPersonalizer($booking);
    $emailBody = $emailPersonalizer->customizeEmailContents($confirmationEmailContents->emailText->getText($booking->languageCode));
    $logger->LogDebug("Email body:");
    $logger->LogDebug($emailBody);
    $logger->LogInfo("Sending email to client at " . $clientEmail . " ...");
    $emailSender = new EmailSender();
    if (!$emailSender->sendEmail($clientEmail, $confirmationEmailContents->emailSubject->getText($booking->languageCode), $emailBody)) {
        $logger->LogError("Failed to send confirmation email to client.");
    }
    /* Notify Email for Hotel about Booking */
    $notifyEmailSubject = "Booking no." . $booking->id . " - Notification of Room Booking by " . $client->firstName . " " . $client->lastName;
    $logger->LogInfo("Sending email to hotel admin...");
    if (!$emailSender->sendEmail($systemConfiguration->getHotelDetails()->getHotelEmail(), $notifyEmailSubject, $invoiceHtml)) {
        $logger->LogError("Failed to send email to the hotel admin.");
    }
    header('Location: booking-confirm.php');
}