public function OnPaid(Invoice $Invoice, AbstractPaymentModule $payment_module = null)
 {
     $db = Core::GetDBInstance();
     if (!in_array($Invoice->Purpose, $this->HandledPurposes)) {
         return;
     }
     Log::Log("RegistryInvoiceObserver::OnPaid(InvoiceID={$Invoice->ID})", E_USER_NOTICE);
     // Get domain information
     try {
         $Domain = DBDomain::GetInstance()->Load($Invoice->ItemID);
     } catch (Exception $e) {
         Log::Log("RegistryInvoiceObserver::OnPaid() thown exception: {$e->getMessage()}", E_USER_ERROR);
     }
     if ($Domain) {
         Log::Log("Invoice purpose: {$Invoice->Purpose}", E_USER_NOTICE);
         // Get user information
         $userinfo = $db->GetRow("SELECT * FROM users WHERE id=?", array($Domain->UserID));
         // Check command
         switch ($Invoice->Purpose) {
             case INVOICE_PURPOSE::DOMAIN_TRADE:
                 try {
                     $Action = new UpdateDomainContactAction($Invoice);
                     try {
                         $Action->Run();
                     } catch (UpdateDomainContactAction_Exception $e) {
                         Log::Log(sprintf("Trade failed. %s", $e->getMessage()), E_ERROR);
                         DBDomain::GetInstance()->Save($Action->GetDomain());
                         // Send mail
                         $args = array("client" => $userinfo, "Invoice" => $Invoice, "domain_name" => $Domain->Name, "extension" => $Domain->Extension, "domain_trade_failure_reason" => $e->getMessage());
                         mailer_send("domain_trade_action_required.eml", $args, $userinfo["email"], $userinfo["name"]);
                     }
                 } catch (LogicException $e2) {
                     Log::Log($e2->getMessage(), E_ERROR);
                 }
                 break;
             case INVOICE_PURPOSE::DOMAIN_CREATE:
                 if ($Domain->Status == DOMAIN_STATUS::AWAITING_PAYMENT || $Domain->Status == DOMAIN_STATUS::REJECTED) {
                     $Domain->Status = DOMAIN_STATUS::PENDING;
                     $Domain->IncompleteOrderOperation = INCOMPLETE_OPERATION::DOMAIN_CREATE;
                     $Domain = DBDomain::GetInstance()->Save($Domain);
                     // If domain has incomplete information skip domain creation. Update status to Pending.
                     if (count($Domain->GetContactList()) == 0 || count($Domain->GetNameserverList()) == 0) {
                         //
                         // Send mail
                         //
                         Log::Log("Domain registration process not completed. Need more information from client.", E_USER_NOTICE);
                         $args = array("client" => $userinfo, "Invoice" => $Invoice, "domain_name" => $Domain->Name, "extension" => $Domain->Extension);
                         mailer_send("domain_registration_action_required.eml", $args, $userinfo["email"], $userinfo["name"]);
                         // Write information in invoice
                         $Invoice->ActionStatus = INVOICE_ACTION_STATUS::FAILED;
                         $Invoice->ActionFailReason = _('Domain registration process not completed. Need more information from client.');
                     } else {
                         Log::Log("Trying to register domain", E_USER_NOTICE);
                         ///// get Registry instance and connect to registry server
                         try {
                             $Registry = RegistryModuleFactory::GetInstance()->GetRegistryByExtension($Domain->Extension);
                         } catch (Exception $e) {
                             Log::Log($e->getMessage(), E_ERROR);
                             return;
                         }
                         // Validate license for this module
                         if (!License::IsModuleLicensed($Registry->GetModuleName())) {
                             throw new LicensingException("Your license does not permit module {$Registry->ModuleName()}");
                         }
                         //
                         $extra_data = $db->GetAll("SELECT * FROM domains_data WHERE domainid=?", array($Domain->ID));
                         if ($extra_data && count($extra_data) > 0) {
                             foreach ($extra_data as $v) {
                                 $extra[$v["key"]] = $v["value"];
                             }
                         } else {
                             $extra = array();
                         }
                         // Try to create domain name
                         try {
                             $cr = $Registry->CreateDomain($Domain, $Domain->Period, $extra);
                         } catch (Exception $e) {
                             $args = array("client" => $userinfo, "Invoice" => $Invoice, "domain_name" => $Domain->Name, "extension" => $Domain->Extension, "domain_reg_failure_reason" => $e->getMessage());
                             mailer_send("domain_registration_action_required.eml", $args, $userinfo["email"], $userinfo["name"]);
                             // If domain not created
                             Log::Log("Cannot register domain name. Server return: " . $e->getMessage(), E_ERROR);
                             $Invoice->ActionStatus = INVOICE_ACTION_STATUS::FAILED;
                             $Invoice->ActionFailReason = $e->getMessage();
                         }
                         if ($cr) {
                             // If domain created
                             Log::Log(sprintf("Domain %s successfully registered. Updating database", $Domain->GetHostName()), E_USER_NOTICE);
                             $Invoice->ActionStatus = INVOICE_ACTION_STATUS::COMPLETE;
                         }
                     }
                 } else {
                     Log::Log("Domain status '{$Domain->Status}'. Expected 'Awaiting payment'", E_ERROR);
                     $retval = false;
                     $Invoice->ActionStatus = INVOICE_ACTION_STATUS::FAILED;
                     $Invoice->ActionFailReason = sprintf(_("Domain status '%s'. Expected 'Awaiting payment'"), $Domain->Status);
                 }
                 break;
             case INVOICE_PURPOSE::DOMAIN_TRANSFER:
                 if ($Domain->Status == DOMAIN_STATUS::AWAITING_PAYMENT) {
                     //
                     // Send mail
                     //
                     $args = array("client" => $userinfo, "domain_name" => $Domain->Name, "extension" => $Domain->Extension, "Invoice" => $Invoice);
                     mailer_send("domain_transfer_action_required.eml", $args, $userinfo["email"], $userinfo["name"]);
                     Log::Log("Domain transfer process not completed. Need more information from client.", E_USER_NOTICE);
                     $Domain->IncompleteOrderOperation = INCOMPLETE_OPERATION::DOMAIN_TRANSFER;
                     $Domain->Status = DOMAIN_STATUS::PENDING;
                     DBDomain::GetInstance()->Save($Domain);
                     $Invoice->ActionStatus = INVOICE_ACTION_STATUS::COMPLETE;
                 }
                 break;
             case INVOICE_PURPOSE::DOMAIN_RENEW:
                 // Renew domain name
                 Log::Log("Trying to renew domain", E_USER_NOTICE);
                 ///// Get registry instance and connect to registry server
                 try {
                     $Registry = RegistryModuleFactory::GetInstance()->GetRegistryByExtension($Domain->Extension);
                 } catch (Exception $e) {
                     Log::Log($e->getMessage(), E_ERROR);
                     return;
                 }
                 try {
                     $renew = $Registry->RenewDomain($Domain, array('period' => $Domain->Period));
                 } catch (Exception $e) {
                     $renew = false;
                     $err = $e->getMessage();
                 }
                 if ($renew) {
                     Log::Log("Domain successfully renewed.", E_USER_NOTICE);
                     $Invoice->ActionStatus = INVOICE_ACTION_STATUS::COMPLETE;
                     $Domain->DeleteStatus = DOMAIN_DELETE_STATUS::NOT_SET;
                     DBDomain::GetInstance()->Save($Domain);
                 } else {
                     $Domain->SetExtraField('RenewInvoiceID', $Invoice->ID);
                     DBDomain::GetInstance()->Save($Domain);
                     //
                     // Send mail here
                     //
                     $args = array("client" => $userinfo, "domain_name" => $Domain->Name, "extension" => $Domain->Extension, "reason" => $err, "years" => $Domain->Period);
                     mailer_send("renewal_failed.eml", $args, $userinfo["email"], $userinfo["name"]);
                     // If renew failed
                     Log::Log("Cannot renew domain name. Server return: " . $err, E_ERROR);
                     $Invoice->ActionStatus = INVOICE_ACTION_STATUS::FAILED;
                     $Invoice->ActionFailReason = $err;
                 }
                 /////
                 break;
         }
         $Invoice->Save();
     } else {
         // Domain not found
         Log::Log(sprintf("Domain width ID '%s' not found.", $Invoice->ItemID), E_ERROR);
     }
     // OnPaymentComplete routine succeffully completed.
     Log::Log("RegistryInvoiceObserver::OnPaid Successfully completed.", E_USER_NOTICE);
 }
Esempio n. 2
0
 public function HandleImpendingExpiration(Domain $domain)
 {
     // http://bugzilla.webta.net/show_bug.cgi?id=210
     // Prevent domain expiration
     $Config = $this->GetManifest()->GetSectionConfig();
     $days = $Config->domain->xpath("//renewal/notifications/period");
     $last_notification_period = (int) end($days);
     $last_renewal_date = $domain->RenewalDate ? $domain->RenewalDate : $domain->ExpireDate;
     $days_before_expire = (int) ceil(($last_renewal_date - time()) / 86400);
     if ($days_before_expire <= $last_notification_period) {
         if ($days_before_expire < 0) {
             // Today will expire... OMG!
             $days_before_expire = 0;
         }
         // Set renew period
         $period = (int) $Config->domain->renewal->min_period;
         $domain->Period = $period;
         // Copypasta from class.RenewProcess.php
         // Issue invoice for renew and send notification to client.
         $Invoice = new Invoice(INVOICE_PURPOSE::DOMAIN_RENEW, $domain, $domain->UserID);
         $Invoice->Description = sprintf(_("%s domain name renewal for %s years"), $domain->GetHostName(), $period);
         $Invoice->Save();
         if ($Invoice->Status == INVOICE_STATUS::PENDING) {
             $userinfo = $this->DB->GetRow("SELECT * FROM users WHERE id=?", array($domain->UserID));
             $args = array("domain_name" => $domain->Name, "extension" => $domain->Extension, "invoice" => $Invoice, "expDays" => $days_before_expire, "client" => $userinfo, "renewal_date" => $domain->RenewalDate);
             mailer_send("renew_notice.eml", $args, $userinfo["email"], $userinfo["name"]);
             Application::FireEvent('DomainAboutToExpire', $domain, $days_before_expire);
         }
     }
 }
Esempio n. 3
0
        public function OnStartForking()
        {            
            global $TLDs, $modules_config;
            
        	Log::Log("Starting 'Renew' cronjob...", E_USER_NOTICE);
            
            $db = Core::GetDBInstance();
            $RegFactory = RegistryModuleFactory::GetInstance();
            $DbDomain = DBDomain::GetInstance();
            
            $this->ThreadArgs = array();
            
            // For each client send notice about expiring domains
            $sql = "SELECT id FROM users";
            foreach ($db->GetAll($sql) as $client_data)
            {
            	try
            	{
	            	$Client = Client::Load($client_data["id"]);
	            	
	            	$sql = "
						SELECT 
							d.id, d.name, d.TLD, d.end_date, 
							IF(dd.`key` IS NOT NULL, FROM_UNIXTIME(dd.`value`), DATE_SUB(end_date, INTERVAL 1 DAY)) AS last_renew_date 
						FROM domains d 
						LEFT JOIN domains_data dd ON (dd.domainid = d.id AND dd.`key` = 'RenewalDate') 
						WHERE d.status = '".DOMAIN_STATUS::DELEGATED."' AND d.userid = ? AND (TO_DAYS(end_date) - TO_DAYS(NOW()) BETWEEN 0 AND ?) AND renew_disabled != 1
						ORDER BY d.end_date ASC";
					$start_days = $Client->GetSettingValue(ClientSettings::EXPIRE_NOTIFY_START_DAYS);
	            	$domains_data = $db->GetAll($sql, array($Client->ID, $start_days ? $start_days : 60));
	            	
	            	// Send email to client
	            	if ($domains_data) 
	            	{
	            		$eml_args = array(
	            			"client_name" => $Client->Name,
	            			"domains" => array()
	            		);
	            		foreach ($domains_data as $domain_data)
	            		{
	            			$eml_args["domains"][] = array(
	            				"name" => "{$domain_data["name"]}.{$domain_data["TLD"]}",
	            				"expire_date" => date("Y-m-d", strtotime($domain_data["end_date"])),
	            				"last_renew_date" => date("Y-m-d", strtotime($domain_data["last_renew_date"]))
	            			);
	            		}
	            		mailer_send("bulk_renew_notice.eml", $eml_args, $Client->Email, $Client->Name);
	            	}
	            	
	            	foreach ($domains_data as $domain_data)
	            	{
	            		$Domain = $DbDomain->Load($domain_data['id']);
	            		
	            		 // Find more then 60 days invoice
	            		 // Legacy from old notification system.
	            		 // FIXME: Need to create a better solution to finding unpaid invoices for upgoing renew 
						$dtNearest = date("Y-m-d", $Domain->ExpireDate - 60*24*60*60);
						$invoiceid = $db->GetOne("SELECT id FROM invoices 
							WHERE userid=? AND itemid=? AND purpose=? AND dtcreated >= ?", 
							array($Domain->UserID, $Domain->ID, INVOICE_PURPOSE::DOMAIN_RENEW, $dtNearest)
						);

							
						// Generate invoice
						if (!$invoiceid && !$Domain->RenewDisabled)
						{				
							$Registry = $RegFactory->GetRegistryByExtension($Domain->Extension);
							$config = $Registry->GetManifest()->GetSectionConfig();
							$period = (int)$config->domain->renewal->min_period;
							$Domain->Period = $period;
							$DbDomain->Save($Domain);

							try
							{
								$Invoice = new Invoice(INVOICE_PURPOSE::DOMAIN_RENEW, $Domain->ID, $Domain->UserID);
								$Invoice->Description = sprintf(_("%s domain name renewal for %s years"), $Domain->GetHostName(), $period);
								$Invoice->Cancellable = 1;
								$Invoice->Save();
								
								if ($Invoice->Status == INVOICE_STATUS::PENDING)
								{
									$diff_days = ceil(($Domain->ExpireDate - time())/(60*60*24));
									Application::FireEvent('DomainAboutToExpire', $Domain, $diff_days);
								}
							}
							catch(Exception $e)
							{
								Log::Log("Cannot create renew invoice. Caught: {$e->getMessage()}", E_USER_ERROR);
							}
						}
	            	}
            	}
            	catch (Exception $e)
            	{
            		Log::Log("Caught: {$e->getMessage()}", E_USER_ERROR);
            	}
            	
            }
            
            /*
			$supported_extensions = $RegFactory->GetExtensionList();
			// For all supported TLDs
            foreach ($supported_extensions as $ext)
            {
            	$Registry = $RegFactory->GetRegistryByExtension($ext);
            	
            	
            	$config = $Registry->GetManifest()->GetSectionConfig();
				$days = $config->domain->renewal->notifications->period;
				$biggest_period = (int)$days[0];
				
				
				
				
				// For each notification 
				foreach($days as $expireDays)
				{
					$expireDays = (int)$expireDays;
					
					$domains = $db->GetAll("
						SELECT dom.* FROM domains AS dom 
						LEFT JOIN domains_data AS ext 
						ON dom.id = ext.domainid AND ext.`key` = 'RenewalDate'
						WHERE dom.TLD = ? 
						AND dom.status = ? 
						AND TO_DAYS(IF 
						(
							ext.`key` IS NOT NULL AND TO_DAYS(FROM_UNIXTIME(ext.`value`)) < TO_DAYS(dom.end_date),
							FROM_UNIXTIME(ext.`value`),
							dom.end_date 
						)) - TO_DAYS(NOW()) = ?
					", array(
						$ext, DOMAIN_STATUS::DELEGATED, $expireDays
					));

					// For each domain
					foreach($domains as $domain_info)
					{
						try
						{
							$Domain = DBDomain::GetInstance()->Load($domain_info['id']);
							
							$dtNearest = date("Y-m-d", strtotime($domain_info["end_date"]) - $biggest_period*24*60*60);
							$invoiceid = $db->GetOne("SELECT id FROM invoices 
								WHERE userid=? AND itemid=? AND purpose=? AND status=? AND dtcreated >= ?", 
								array($Domain->UserID, $Domain->ID, INVOICE_PURPOSE::DOMAIN_RENEW, INVOICE_STATUS::PENDING, $dtNearest)
							);
							
							// Generate invoice
							if (!$invoiceid && !$Domain->RenewDisabled)
							{				
								
								$period = (int)$config->domain->renewal->min_period;
								$Domain->Period = $period;
								DBDomain::GetInstance()->Save($Domain);
								 
								try
								{
									$Invoice = new Invoice(INVOICE_PURPOSE::DOMAIN_RENEW, $Domain->ID, $Domain->UserID);
									$Invoice->Description = sprintf(_("%s domain name renewal for %s years"), $Domain->GetHostName(), $period);
									$Invoice->Cancellable = 1;
									$Invoice->Save();
									
									if ($Invoice->Status == INVOICE_STATUS::PENDING)
									{
										$userinfo = $db->GetRow("SELECT * FROM users WHERE id=?", array($Domain->UserID));
										
										//print "send notification and invoice about {$Domain->GetHostName()} to {$userinfo['email']}\n";									
										
										$args = array(
											"domain_name"	=> $Domain->Name, 
											"extension"		=> $Domain->Extension,
											"invoice"		=> $Invoice,
											"expDays"		=> $expireDays,
											"client"		=> $userinfo,
											"renewal_date"  => $Domain->RenewalDate
										);
										mailer_send("renew_notice.eml", $args, $userinfo["email"], $userinfo["name"]);
	
										Application::FireEvent('DomainAboutToExpire', $Domain, $expireDays);
									}
								}
								catch(Exception $e)
								{
									$errmsg = $e->getMessage();
								}
							}
							else
							{
								$userinfo = $db->GetRow("SELECT * FROM users WHERE id=?", array($Domain->UserID));
								//print "send notification about {$Domain->GetHostName()} to {$userinfo['email']}\n";
								$args = array(
									"domain_name"	=> $Domain->Name, 
									"extension"		=> $Domain->Extension,
									"expDays"		=> $expireDays,
									'client' 		=> $userinfo,
									"renewal_date"  => $Domain->RenewalDate
								);
								mailer_send("renew_notice.eml", $args, $userinfo["email"], $userinfo["name"]);
							}
						} 
						catch (Exception $e)
						{
							Log::Log("First domains loop. Caught: ".$e->getMessage(), E_USER_ERROR);
						}
					}
				}
            }
            */

            
			// For auto-renew registries the day before expiration date 
			// send to unpaid domains delete command and mark them as expired
			Log::Log("Going to process expiring tomorrow domains in 'auto-renew' registries", E_USER_NOTICE);			
			$days_before = 1;
			$del_date = strtotime("+$days_before day");
			$delete_report = array();
			$domains = $db->GetAll("SELECT dom.id, dom.name, dom.TLD FROM domains AS dom 
				LEFT JOIN domains_data AS ext ON dom.id = ext.domainid AND ext.`key` = 'RenewalDate'
				LEFT JOIN invoices AS i ON (dom.id = i.itemid AND i.purpose = 'Domain_Renew')
				WHERE dom.status = ? 
				AND TO_DAYS(IF
				(
					ext.`key` IS NOT NULL AND TO_DAYS(FROM_UNIXTIME(ext.`value`)) < TO_DAYS(dom.end_date),
					FROM_UNIXTIME(ext.`value`),
					dom.end_date 
				)) - TO_DAYS(NOW()) = ?	AND ((i.status = ? AND TO_DAYS(NOW()) - TO_DAYS(i.dtcreated) <= 60) OR i.status IS NULL)",
				array(DOMAIN_STATUS::DELEGATED, $days_before, INVOICE_STATUS::PENDING));
				
			foreach ($domains as $domain_info)
			{
				try
				{
					$Domain = $DbDomain->Load($domain_info["id"]);
					$Registry = $RegFactory->GetRegistryByExtension($domain_info["TLD"]);
					$RegistryOptions = $Registry->GetManifest()->GetRegistryOptions();
					$auto_renewal = (int)$RegistryOptions->ability->auto_renewal;
					$scheduled_delete = (int)$RegistryOptions->ability->scheduled_delete;
					
					if ($auto_renewal)
					{
						if (CONFIG::$AUTO_DELETE)
						{
							try
							{
								// For 'auto-renew + scheduled delete' send scheduled delete
								if ($scheduled_delete)
								{
									Log::Log(sprintf("Send scheduled delete to domain '%s' at '%s'", 
											$Domain->GetHostName(), date("Y-m-d", $del_date)), E_USER_NOTICE);
									
									$Registry->DeleteDomain($Domain, $del_date);
								}
								// For 'auto-renew' only send direct delete
								else
								{
									Log::Log(sprintf("Send direct delete to domain '%s'", 
											$Domain->GetHostName()), E_USER_NOTICE);
									$Registry->DeleteDomain($Domain);
								}
								
								$this->MarkAsExpired($Domain);
							}
							catch (Exception $e)
							{
								Log::Log(sprintf("Cannot delete expiring domain '%s'. %s", 
										$Domain->GetHostName(), $e->getMessage()), E_USER_ERROR);
							}								
						}
						else
						{
							Log::Log(sprintf("Domain %s need to be deleted. Send it to admin court", 
									$Domain->GetHostName()), E_USER_NOTICE);
							
							// Send to the administrator court
							$db->Execute("UPDATE domains SET delete_status = ? WHERE id = ?",
									array(DOMAIN_DELETE_STATUS::AWAIT, $Domain->ID));
							$userinfo = $db->GetRow("SELECT * FROM users WHERE id = ?", array($Domain->UserID));
							$delete_report[] = array
							(
								"domain" => $Domain->GetHostName(),
								"user" => "{$userinfo["name"]}({$userinfo["email"]})"
							);
						}
					}
				}
				catch (Exception $e)
				{
					Log::Log(sprintf("Cannot load expiring domain '%s'. %s", 
							"{$domain_info["name"]}.{$domain_info["TLD"]}", $e->getMessage()), E_USER_ERROR);
				}
			}
			// Notify admin about expiring domains need to be deleted
			if ($delete_report)
			{
				$args = array(
					"date" => date("Y-m-d", $del_date), 
					"report" => $delete_report, 
					"confirm_url" => CONFIG::$SITE_URL . "/admin/domains_await_delete_confirmation.php"
				);
				
				mailer_send("root_domains_await_delete.eml", $args, CONFIG::$EMAIL_ADMIN, CONFIG::$EMAIL_ADMINNAME);
			}
			
			
			// For all registries mark domain as expired at expiration date
			Log::Log("Going to process expiring today domains", E_USER_NOTICE);
			$domains = $db->GetAll("SELECT id, name, TLD FROM domains 
					WHERE TO_DAYS(end_date) = TO_DAYS(NOW()) AND status = ? AND delete_status != ?",
					array(DOMAIN_STATUS::DELEGATED, DOMAIN_DELETE_STATUS::AWAIT));
			
			foreach ($domains as $domain_info)
			{
				try
				{
					$Domain = $DbDomain->Load($domain_info["id"]);
					
					$this->MarkAsExpired($Domain);
				}
				catch (Exception $e)
				{
					Log::Log(sprintf("Cannot load expired domain '%s'. %s", 
							"{$domain_info["name"]}.{$domain_info["TLD"]}", $e->getMessage()), E_USER_ERROR);
				}
			}

			
			// Cleanup database from expired and transferred domains (more then 60 days)
			Log::Log("Going to cleanup database from transferred and expired domains (more then 60 days)", E_USER_NOTICE);
			$domains = $db->GetAll("
					SELECT * FROM domains 
					WHERE (status=? OR status=?) AND 
					((TO_DAYS(NOW()-TO_DAYS(end_date)) >= 60) OR (TO_DAYS(NOW()-TO_DAYS(dtTransfer)) >= 60))", 
					array(DOMAIN_STATUS::TRANSFERRED, DOMAIN_STATUS::EXPIRED));
					
			foreach ($domains as $domain_info)
			{
				try
				{
					Log::Log("Delete {$domain_info["name"]}.{$domain_info["TLD"]} from database. "
						. "(start_date={$domain_info["start_date"]}, end_date={$domain_info["end_date"]}, status={$domain_info["status"]})", 
						E_USER_NOTICE);
					$Domain = $DbDomain->Load($domain_info['id']);
					$DbDomain->Delete($Domain);
				}
				catch (Exception $ignore) 
				{
					Log::Log("Catch ignored exception. {$ignore->getMessage()}", E_USER_NOTICE);
				}
			}
			
			
			// Notify customers about low balance
			Log::Log("Going to notify customers about their low balance", E_USER_NOTICE);
			$user_ids = $db->GetAll("SELECT userid FROM user_settings 
					WHERE `key` = '".ClientSettings::LOW_BALANCE_NOTIFY."' AND `value` = '1'");
			foreach ($user_ids as $id) 
			{
				try 
				{
					$id = $id["userid"];
					$Client = Client::Load($id);
					$amount = (float)$db->GetOne("SELECT `total` FROM balance WHERE clientid = ?", array($id));
					$min_amount = (float)$Client->GetSettingValue(ClientSettings::LOW_BALANCE_VALUE);
					if ($amount < $min_amount)
					{
						mailer_send("low_balance_notice.eml", array(
							"client" => array("name" => $Client->Name),
							"amount" => number_format($min_amount, 2),
							"currency" => CONFIG::$CURRENCYISO
						), $Client->Email, $Client->Name);
					}
				}
				catch (Exception $e)
				{
					Log::Log("Cannot notify customer about his low balance. Error: {$e->getMessage()}", E_USER_ERROR);
					
				}
			}
        }
Esempio n. 4
0
	    			$Domain = DBDomain::GetInstance()->Save($Domain);
	    		} 
	    		catch (Exception $e)
	    		{
	    			Log::Log($e->getMessage(), E_USER_ERROR);
	    			$exception->AddMessage(_('Cannot save domain'));
	    			throw $exception;
	    		}
	    		
	    		try
	    		{			    			    
                	$Invoice = new Invoice(INVOICE_PURPOSE::DOMAIN_CREATE,$Domain->ID,$_SESSION['userid']);
                	$Invoice->Description = sprintf(_("%s domain name registration for %s year(s)"), 
                		$Domain->GetHostName(), $Domain->Period
                	);
                	$Invoice->Save();
	    		}
	    		catch(Exception $e)
	    		{
	    			$exception->AddMessage(sprintf(_("Cannot create invoice: %s"), $e->getMessage()));
    				throw $exception;	
	    		}
				
				$_SESSION["domaininfo"]["extension"] = false;
				$_SESSION["regdomain"] = false;
				$_SESSION["dInfo"] = false;
				$_SESSION["invTotal"] = false;
				$_SESSION["invID"] = false;
				$_SESSION["invDescription"] = false;
				$_SESSION["gate"] = false;
				$_SESSION["success_payment_redirect_url"] = "domains_view.php";
Esempio n. 5
0
        $res = $Registry->DomainCanBeRegistered($Domain)->Result;
    } catch (Exception $e) {
        throw new ApplicationException(sprintf(_("Cannot check availability of %s. %s")));
    }
    if ($res == true) {
        throw new ApplicationException(sprintf(_("Domain %s not registered"), $Domain->GetHostName()));
    }
    // Save expiration date
    $Domain->CreateDate = strtotime($expiredate);
    // See if we have to issue invoice for this client
    if (Client::Load($_SESSION['userid'])->GetSettingValue('bill_for_domain_preorder') != 1) {
        $Domain->Status = DOMAIN_STATUS::AWAITING_PREREGISTRATION;
        DBDomain::GetInstance()->Save($Domain);
    } else {
        $Domain->Status = DOMAIN_STATUS::AWAITING_PAYMENT;
        $Domain = DBDomain::GetInstance()->Save($Domain);
        $Invoice = new Invoice(INVOICE_PURPOSE::PREREGISTRATION_DROPCATCHING, $Domain->ID, $_SESSION['userid']);
        $Invoice->Description = sprintf(_("Domain name %s pre-registration"), $Domain->GetHostName());
        $invoices[] = $Invoice->Save()->ID;
    }
    if (count($err) == 0) {
        if (count($invoices) != 0) {
            $okmsg = _("Please pay the generated invoices below to add domains to pre-registration queue");
            CoreUtils::Redirect("checkout.php?string_invoices=" . implode(",", $invoices));
        } else {
            $okmsg = _("Domain successfully added to pre-registration queue");
            CoreUtils::Redirect("domains_view.php");
        }
    }
}
include_once "src/append.inc.php";
 /**
  * Executor
  *
  * @throws UpdateDomainContactTask_Exception
  */
 public function Run($userid = null)
 {
     try {
         $Factory = RegistryModuleFactory::GetInstance();
         $Registry = $Factory->GetRegistryByExtension($this->Domain->Extension);
         $Manifest = $Registry->GetManifest();
         if ($userid && $this->Domain->UserID != $userid) {
             throw new UpdateDomainContactAction_Exception(_("You don't have permissions for manage this domain"), UpdateDomainContactAction_Exception::DOMAIN_NOT_BELONGS_TO_USER);
         }
         $OldContact = $this->Domain->GetContact($this->contact_type);
         if ($this->NewContact && $this->NewContact->UserID != $this->Domain->UserID) {
             throw new UpdateDomainContactAction_Exception(_("You don't have permissions for using this contact"), UpdateDomainContactAction_Exception::CONTACT_NOT_BELONGS_TO_USER);
         }
         $trade = $Manifest->GetRegistryOptions()->ability->trade == '1';
         if ($this->contact_type != CONTACT_TYPE::REGISTRANT || !$trade) {
             try {
                 $Registry->UpdateDomainContact($this->Domain, $this->contact_type, $OldContact, $this->NewContact);
                 return $this->Domain->HasPendingOperation(Registry::OP_UPDATE) ? UpdateDomainContactAction_Result::PENDING : UpdateDomainContactAction_Result::OK;
             } catch (Exception $e) {
                 throw new UpdateDomainContactAction_Exception(sprintf(_("Cannot change contact. Reason: %s"), $e->getMessage()));
             }
         } else {
             // Execute trade when:
             // - Trade invoice is paid
             // - Previous trade failed
             if ($this->Domain->IncompleteOrderOperation == INCOMPLETE_OPERATION::DOMAIN_TRADE || $this->Invoice && $this->Invoice->Status == INVOICE_STATUS::PAID) {
                 $this->Domain->SetContact($this->NewContact, CONTACT_TYPE::REGISTRANT);
                 $this->Domain->IncompleteOrderOperation = null;
                 $extra["requesttype"] = "ownerChange";
                 try {
                     $trade = $Registry->ChangeDomainOwner($this->Domain, 1, $extra);
                     return $this->Domain->HasPendingOperation(Registry::OP_TRADE) ? UpdateDomainContactAction_Result::PENDING : UpdateDomainContactAction_Result::OK;
                 } catch (Exception $e) {
                     $this->Domain->IncompleteOrderOperation = INCOMPLETE_OPERATION::DOMAIN_TRADE;
                     if ($this->Invoice) {
                         $this->Invoice->ActionStatus = INVOICE_ACTION_STATUS::FAILED;
                         $this->Invoice->ActionFailReason = $e->getMessage();
                     }
                     throw new UpdateDomainContactAction_Exception(sprintf(_("Cannot change contact. Reason: %s"), $e->getMessage()));
                 }
             } else {
                 // Issue an invoice for trade operation
                 $invoiceid = $this->Db->GetOne("SELECT * FROM invoices WHERE status=? AND itemid=? AND purpose=?", array(INVOICE_STATUS::PENDING, $this->Domain->ID, INVOICE_PURPOSE::DOMAIN_TRADE));
                 if (!$invoiceid) {
                     $this->Domain->SetExtraField("NewRegistrantCLID", $this->NewContact->CLID);
                     DBDomain::GetInstance()->Save($this->Domain);
                     $Invoice = new Invoice(INVOICE_PURPOSE::DOMAIN_TRADE, $this->Domain->ID, $userid);
                     $Invoice->Description = sprintf(_("%s domain name trade"), $this->Domain->GetHostName());
                     $Invoice->Save();
                     $this->Invoice = $Invoice;
                     return UpdateDomainContactAction_Result::INVOICE_GENERATED;
                 } else {
                     throw new UpdateDomainContactAction_Exception(_("Another domain trade is already initiated"));
                 }
             }
         }
     } catch (Exception $e) {
         throw new UpdateDomainContactAction_Exception($e->getMessage());
     }
 }
Esempio n. 7
0
 $invoice->date = date('Y-n-d H:i:s');
 if (isset($_SESSION['user']['id'])) {
     $invoice->user = $_SESSION['user']['id'];
 } else {
     $invoice->user = $guest;
 }
 $invoice->total = $totalamont;
 $invoice->currency = $_SESSION['currency_unit'];
 $invoice->voucher = '';
 $invoice->reference = $result;
 $invoice->date_in = $_SESSION['date-in'];
 $invoice->date_out = $_SESSION['date-out'];
 $invoice->hotel = 0;
 $invoice->description = json_encode($passengers);
 $invoice->status = 0;
 $invc_num = $invoice->Save();
 //var_dump($_POST['invoice']);exit;
 if ($invc_num) {
     // add invoice detail
     foreach ($_POST['invoice'] as $detail) {
         $invcdtl = new InvoiceDetail();
         $invcdtl->invoice = $invc_num;
         $invcdtl->room = $detail['id'];
         $invcdtl->room_title = '';
         $invcdtl->adult = 0;
         $invcdtl->child = 0;
         $invcdtl->amount = $detail['price'];
         $invcdtl->save();
     }
 } else {
     $app = new AppController();