public function getMoney() { $db = JFactory::getDBO(); $time = time() + 86400; $q = "SELECT * FROM #__business WHERE timeExpired < '" . $time . "' AND subscriptionid <> ''"; $db->setQuery($q); $businessList = $db->loadObjectList(); foreach ($businessList as $business) { if ($business->numMonthPayment == 1) { $expired = strtotime('+1 month', $business->timeExpired); $productName = "Måndligt abonnement"; $productPrice = 349; } else { $expired = strtotime('+1 year', $business->timeExpired); $productName = "Årligt abonnement"; $productPrice = 3490; } $epay_params = array(); $epay_params['merchantnumber'] = "6284736"; $epay_params['subscriptionid'] = $business->subscriptionid; $epay_params['orderid'] = "ML" . time(); $epay_params['amount'] = ($productPrice + $productPrice * 0.25) * 100; $epay_params['currency'] = "208"; $epay_params['instantcapture'] = "0"; $epay_params['fraud'] = "0"; $epay_params['transactionid'] = "-1"; $epay_params['pbsresponse'] = "-1"; $epay_params['epayresponse'] = "-1"; $client = new SoapClient('https://ssl.ditonlinebetalingssystem.dk/remote/subscription.asmx?WSDL'); $result = $client->authorize($epay_params); if ($result->authorizeResult == true) { $db = JFactory::getDBO(); $db->setQuery("UPDATE #__business SET timeExpired = '" . $expired . "', transactionPayment = '" . $result->transactionid . "' WHERE id = " . $business->id); $db->execute(); $db->setQuery("SELECT email, name FROM #__users WHERE id = " . $business->userId); $user = $db->loadObject(); /*$html = '<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Myloyal</title> </head> <body style="font-family: Arial, Helvetica, Verdana; font-size: 16px; line-height: 1.8em; color:#303030; position:relative;-webkit-text-size-adjust:none; padding:0; margin:0;"> <div id="page" width="100%" style="padding: 10px; border: 1px solid #ccc; margin: 20px;"> <h1 style="font-size: 30px;">FAKTURA</h1> <table width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="20%" style="padding: 5px; border: 1px solid #ccc;"><strong>Ordrenummer:</strong></td> <td style="padding: 5px; border: 1px solid #ccc;"><strong>'.sprintf("%'.05d\n", $business->userId).'</strong></td> </tr> <tr> <td style="padding: 5px; border: 1px solid #ccc;"> <strong>E-mail:</strong></td> <td style="padding: 5px; border: 1px solid #ccc;"> <strong>'.$user->email.'</strong></td> </tr> </table> <h2>Kundeoplysninger:</h2> <table width="100%" cellspacing="0" cellpadding="0"> <tr> <td style="padding: 5px; border: 1px solid #ccc;" width="20%">CVR:</td> <td style="padding: 5px; border: 1px solid #ccc;">'.$business->cvrNumber.'</td> </tr> <tr> <td style="padding: 5px; border: 1px solid #ccc;" width="20%">Navn:</td> <td style="padding: 5px; border: 1px solid #ccc;">'.$user->name.'</td> </tr> <tr> <td style="padding: 5px; border: 1px solid #ccc;">Telefon nr.:</td> <td style="padding: 5px; border: 1px solid #ccc;">'.$business->phone.'</td> </tr> <tr> <td style="padding: 5px; border: 1px solid #ccc;">Firmanavn:</td> <td style="padding: 5px; border: 1px solid #ccc;">'.$business->businessName.'</td> </tr> </table> <table width="100%" cellspacing="0" cellpadding="0"> <thead> <tr> <th width="70%">Produkt</th> <th>Pris i alt</th> </tr> </thead> <tbody> <tr> <td width="50%" style="padding: 5px; border: 1px solid #ccc;">'.$productName.'</td> <td style="text-align: right; padding: 5px; border: 1px solid #ccc;">'.$productPrice.' DKK</td> </tr> <tr> <td style="text-align: right; padding: 5px; border: 1px solid #ccc;">Heraf moms:</td> <td style="text-align: right; padding: 5px; border: 1px solid #ccc;">'.number_format($productPrice*0.25, 2, ".", ",").' DKK</td> </tr> <tr> <td style="text-align: right; padding: 5px; border: 1px solid #ccc;"><strong>TOTAL INKL. MOMS:</strong></td> <td style="text-align: right; padding: 5px; border: 1px solid #ccc;"><strong>'.number_format($productPrice+($productPrice*0.25), 2, ".", ",").' DKK</strong></td> </tr> <tr> <td style="padding: 5px; border: 1px solid #ccc;" colspan="2"> <p style="text-align: center; font-size: 12px;">© 2015 MYLOYAL APS - BIRKEVANG 20C, 3500 VÆRLØSE - TLF. +45 6048 3972 - EMAIL INFO@MYLYOAL.DK - CVR. 37100196 - UDVIKLET AF AZ WEB</p> </td> </tr> </tbody> </table> </div> </body> </html>';*/ $html = '<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Myloyal</title> </head> <body style="font-family: Arial, Helvetica, Verdana; font-size: 16px; line-height: 1.8em; color:#303030; position:relative;-webkit-text-size-adjust:none; padding:0; margin:0;"> <h1 style="margin: 15px auto; width: 260px;"><img src="logo.png" alt=""></h1> <div id="page" width="100%" style="padding: 10px; margin: 20px;"> <table width="100%" cellspacing="0" cellpadding="0"> <tr> <td style="padding: 10px;"><strong>' . $business->cvrNumber . '<br> ' . $business->address . '<br> ' . $business->phone . '<br> CVR-nr. ' . $business->businessName . '</strong></td> <td style="padding: 10px; text-align: right;"><strong>MyLoyal Aps<br> Birkevang 20c<br> 3500 Værløse<br><br> Tlf. +45 6048 3972<br> E-mail: info@myloyal.dk<br> CVR-nr. 37100196</strong></td> </tr> </table> <h1 style="font-size: 30px;">FAKTURA</h1> <table width="100%" cellspacing="0" cellpadding="0"> <thead> <tr> <th style="text-align: left; padding: 10px;">Årlig abonnemenet gældende fra og til: ' . date("d/m/Y", $business->timeExpired) . ' - ' . date("d/m/Y", $expired) . '</th> <th style="padding: 10px;">Ordrenummer: ' . sprintf("%'.05d\n", $business->userId) . '</th> <th style="text-align: right; padding: 10px;">Betalingsdato: ' . date("d/m/Y") . '</th> </tr> </thead> <tbody> <tr> <td style="padding: 10px; border-top: 1px solid #000;">Beskrivelse</td> <td style="padding: 10px; border-top: 1px solid #000;"></td> <td style="text-align: right; padding: 10px; border-top: 1px solid #000;">Pris i alt</td> </tr> <tr> <td style="padding: 10px; border-top: 1px solid #000;">' . $productName . '</td> <td style="padding: 10px; border-top: 1px solid #000;"></td> <td style="text-align: right; padding: 10px; border-top: 1px solid #000;">' . $productPrice . ' DKK</td> </tr> <tr> <td colspan="2" style="text-align: right; padding: 10px; border-top: 1px solid #000;">25% moms :</td> <td style="text-align: right; padding: 10px; border-top: 1px solid #000;">' . number_format($productPrice * 0.25, 2, ".", ",") . ' DKK</td> </tr> <tr> <td></td> <td style="text-align: right; padding: 10px; border-top: 1px solid #000; border-bottom: 1px solid #000;"><strong>TOTAL INKL. MOMS:</strong></td> <td style="text-align: right; padding: 10px; border-top: 1px solid #000; border-bottom: 1px solid #000;"><strong>' . number_format($productPrice + $productPrice * 0.25, 2, ".", ",") . ' DKK</strong></td> </tr> </tbody> </table> </div> </body> </html>'; $app = JFactory::getApplication(); $mailfrom = $app->get('mailfrom'); $fromname = $app->get('fromname'); $mail = JFactory::getMailer(); $mail->addRecipient($user->email); $mail->AddCC('*****@*****.**'); $mail->setSender(array($mailfrom, $fromname)); $mail->setSubject('Bekræftet ordre ' . sprintf("%'.05d\n", $business->userId)); $mail->isHTML(true); $mail->setBody($html); $sent = $mail->Send(); } else { print_r($result); exit; } } }
function epay_invoice_creation_pre_email($vars) { global $cc_encryption_hash; logActivity("epay_invoice_creation_pre_email: " . $vars['invoiceid']); //Fetch invoice data $values["invoiceid"] = $vars['invoiceid']; $invoice_result = localAPI("getinvoice", $values, null); //Should this invoice be payed with ePay if ($invoice_result['paymentmethod'] == "epay") { $gateway = getGatewayVariables("epay"); //Get client $client_query = mysql_query("SELECT id, currency, gatewayid, disableautocc, AES_DECRYPT(cardnum, MD5('" . $cc_encryption_hash . $invoice_result['userid'] . "')) as cardnum FROM tblclients WHERE id = " . $invoice_result['userid']); $client_result = mysql_fetch_array($client_query); //Set subscription ID $subscriptionid = $client_result['gatewayid']; //Get currency $currency_query = select_query("tblcurrencies", "id, code", array("id" => $client_result['currency'])); $currency_result = mysql_fetch_array($currency_query); $currency_code = convertToEpayCurrency($currency_result["code"]); logActivity("epay_invoice_creation_pre_email: " . $currency_code); //Process if autocc is not disabled if ($client_result['disableautocc'] != "on" && $subscriptionid > 0) { $fee = 0; logActivity("epay_invoice_creation_pre_email: " . $invoice_result['total'] * 100); logActivity("epay_invoice_creation_pre_email: " . $gateway["subscriptionfee"]); //Calculate transaction fee if ($gateway["subscriptionfee"] == "on") { logActivity("epay_invoice_creation_pre_email card: " . $client_result["cardnum"]); $epay_params = array(); $epay_params['merchantnumber'] = $gateway["merchantnumber"]; $epay_params['cardno_prefix'] = substr($client_result["cardnum"], 0, 6); $epay_params['amount'] = $invoice_result['total'] * 100; $epay_params['currency'] = $currency_code; $epay_params['acquirer'] = "0"; $epay_params['fee'] = "0"; $epay_params['cardtype'] = "ALL"; $epay_params['cardtypetext'] = "-1"; $epay_params['epayresponse'] = "-1"; $soap = new SoapClient('https://ssl.ditonlinebetalingssystem.dk/remote/payment.asmx?WSDL'); $soap_fee_result = $soap->getcardinfo($epay_params); $fee = $soap_fee_result->fee; logActivity("epay_invoice_creation_pre_email fee: " . $fee); } //Autorize transaction $epay_params = array(); $epay_params['merchantnumber'] = $gateway["merchantnumber"]; $epay_params['subscriptionid'] = $subscriptionid; $epay_params['orderid'] = $vars['invoiceid']; $epay_params['amount'] = $invoice_result['total'] * 100 + $fee; $epay_params['currency'] = $currency_code; if ($gateway["captureonduedate"] == "no" or array_key_exists("SERVER_ADDR", $_SERVER)) { $epay_params['instantcapture'] = "1"; } else { $epay_params['instantcapture'] = "0"; } $epay_params['fraud'] = "0"; $epay_params['transactionid'] = "-1"; $epay_params['pbsresponse'] = "-1"; $epay_params['epayresponse'] = "-1"; $soap = new SoapClient('https://ssl.ditonlinebetalingssystem.dk/remote/subscription.asmx?WSDL'); $soap_authorize_result = $soap->authorize($epay_params); //Transaction OK if ($soap_authorize_result->authorizeResult == true) { //Apply fee to invoice if ($fee > 0) { $values_fee["invoiceid"] = $vars['invoiceid']; $values_fee["newitemdescription"] = array("Payment Fee"); $values_fee["newitemamount"] = array($fee / 100); $values_fee["newitemtaxed"] = array("0"); $result_fee = localAPI("updateinvoice", $values_fee, null); logActivity("epay_invoice_creation_pre_email fee result: " . $result_fee["result"]); } //Add payment to invoice $transactionid = $soap_authorize_result->transactionid; if ($gateway["captureonduedate"] == "no" or array_key_exists("SERVER_ADDR", $_SERVER)) { addInvoicePayment($vars['invoiceid'], $transactionid, $invoice_result['total'] + $fee / 100, $fee / 100, "epay"); } else { //Add to capture queue mysql_query("INSERT INTO tblepay (invoiceid, txnid) VALUES ('" . $vars['invoiceid'] . "', " . $transactionid . ")"); } } else { //Could not authorize transaction //Log and let WHMCS handle further processing logActivity("epay_invoice_creation_pre_email: PBS: " . $soap_authorize_result->pbsresponse . " ePay: " . $soap_authorize_result->epayresponse); } } } }