Files
tqw-vanilla/process.php
2025-10-05 22:17:20 +02:00

425 lines
20 KiB
PHP

<?php
ini_set('session.gc_maxlifetime', 3600);
session_set_cookie_params(3600);
session_start();
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
ini_set("error_reporting", E_ALL);
ini_set("display_errors", 1);
ini_set("date.timezone", "Europe/London");
//redirect for any illegall move
if( isset( $_SESSION["nocsrf"] ) && $_SESSION["nocsrf"] ){
if( !getData("nocsrf") || $_SESSION["nocsrf"] != getData("nocsrf") ){
$_SESSION["status_code"] = "error"; // all good;
$_SESSION["message"] = "Invalid form submitted. Incident has been reported"; // all good;
header("location:/index.php");
exit;
}
}else{
$_SESSION["status_code"] = "error"; // all good;
$_SESSION["message"] = "Invalid request. Incident has been reported"; // all good;
header("location:/index.php");
exit;
}
$aTestDbParam = array( 'host' => '127.0.0.1'
, 'dbname' => 'quranicway'
, 'username' => 'root'
, 'password' => 'r00t' );
$aLiveDbParam = array( 'host' => 'db724771930.db.1and1.com'
, 'dbname' => 'db724771930'
, 'username' => 'dbo724771930'
, 'password' => '3ZL1ykDeR8PQ%' );
$aStagingDbParam = array( 'host' => 'db725805720.db.1and1.com'
, 'dbname' => 'db725805720'
, 'username' => 'dbo725805720'
, 'password' => '1Qn*P2o!z3cq' );
$sSecretKey = "";
$sPublishableKey = "";
if( trim( $_SERVER["SERVER_NAME"], "www." ) == "thequranicway.com"){
$aDbParam = $aLiveDbParam;
$sSecretKey = "sk_live_MoAYU7lXhPn4PVI9qr90oy9S";
$sPublishableKey = "pk_live_k1BdkAnOH60PQ57FYtuOFOkn";
}elseif( trim( $_SERVER["SERVER_NAME"], "www." ) == "thequranicway.local"){
$aDbParam = $aTestDbParam;
$sSecretKey = "sk_test_lHUBMygZjvpIujQNDPSEowzI";
$sPublishableKey = "pk_test_j0rkHIjMGYZa7RsKc8qckCrO";
}elseif( trim( $_SERVER["SERVER_NAME"], "www." ) == "staging.thequranicway.com"){
$aDbParam = $aStagingDbParam;
$sSecretKey = "sk_test_lHUBMygZjvpIujQNDPSEowzI";
$sPublishableKey = "pk_test_j0rkHIjMGYZa7RsKc8qckCrO";
// $sSecretKey = "sk_live_MoAYU7lXhPn4PVI9qr90oy9S";
// $sPublishableKey = "pk_live_k1BdkAnOH60PQ57FYtuOFOkn";
}
set_include_path( get_include_path().PATH_SEPARATOR. '../library') ;
set_include_path( get_include_path().PATH_SEPARATOR. 'model') ;
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance() ;
require_once('vendor/autoload.php');
spl_autoload_register(function ($class){
$filename="model/$class.php";
if(!file_exists($filename))
{
return "file : $filename is not Exist on the Given Path";
}
require_once "model/$class.php";
});
function getData($sName){
if( isset($_POST[$sName] ) && $_POST[$sName] ){
return $_POST[$sName];
}else{
return false;
}
}
//Using Zend_Config to pass parameters into Db-connection
$oConfig = new Zend_Config( array( 'database' => array( 'adapter' => 'Pdo_Mysql'
, 'params' => $aDbParam ) ) );
$oDb = Zend_Db::factory( $oConfig->database);
try {
$stripe = array( "secret_key" => $sSecretKey
, "publishable_key" => $sPublishableKey );
\Stripe\Stripe::setApiKey($stripe['secret_key']);
$token = getData('stripeToken');
$email = getData('email');
$sDescriptionDelimited = getData('first_name')
. "||" . getData('last_name')
. "||" . getData('location')
. "||" . getData('postcode')
. "||" . getData("amount")/100
. "||" . Date("Y-m-d H:i:s")
;
$customer = \Stripe\Customer::create( array( "email" => $email
, "description" => "Registering for course @ ". getData("location")
, "source" => $token
));
$charge = \Stripe\Charge::create( array( 'customer' => $customer->id
, 'amount' => getData("amount")
// , 'amount' => 30
, 'currency' => 'gbp'
, "description" => $sDescriptionDelimited ) );
recordTransaction($charge);
sendBookingNotification( $charge);
$_SESSION["status_code"] = 1000; // all good;
header("location:/index.php");
} catch(\Stripe\Error\Card $e) {
// Since it's a decline, \Stripe\Error\Card will be caught
$body = $e->getJsonBody();
$err = $body['error'];
// print('Status is:' . $e->getHttpStatus() . "\n");
// print('Type is:' . $err['type'] . "\n");
// print('Code is:' . $err['code'] . "\n");
// // param is '' in this case
// print('Param is:' . $err['param'] . "\n");
// print('Message is:' . $err['message'] . "\n");
$_SESSION["status_code"] = "error"; // all good;
$_SESSION["message"] = $err['message']; // all good;
header("location:/index.php");
} catch (\Stripe\Error\RateLimit $e) {
// Too many requests made to the API too quickly
$_SESSION["status_code"] = "error"; // all good;
$_SESSION["message"] = "RateLimit:" . $e->getMessage();
header("location:/index.php");
} catch (\Stripe\Error\InvalidRequest $e) {
// Invalid parameters were supplied to Stripe's API
$_SESSION["status_code"] = "error"; // all good;
$_SESSION["message"] = "InvalidRequest: " . $e->getMessage();
header("location:/index.php");
} catch (\Stripe\Error\Authentication $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
$_SESSION["status_code"] = "error"; // all good;
$_SESSION["message"] = "Authentication: " . $e->getMessage();
header("location:/index.php");
} catch (\Stripe\Error\ApiConnection $e) {
// Network communication with Stripe failed
$_SESSION["status_code"] = "error"; // all good;
$_SESSION["message"] = "ApiConnection: " . $e->getMessage();
header("location:/index.php");
} catch (\Stripe\Error\Base $e) {
// Display a very generic error to the user, and maybe send
// yourself an email
$_SESSION["status_code"] = "error"; // all good;
$_SESSION["message"] = "Base: " . $e->getMessage();
header("location:/index.php");
}catch(Exception $e){
$_SESSION["status_code"] = "error"; // all good;
$_SESSION["message"] = "General: " . $e->getMessage();
header("location:/index.php");
}
function recordTransaction(\Stripe\Charge $oCharge ){
global $oDb;
$aData["first_name"] = getData("first_name");
$aData["last_name"] = getData("last_name");
$aData["email"] = getData("email");
$aData["postcode"] = getData("postcode");
$aData["course"] = getData('location');
$aData["individual"] = getData("individual");
$aData["couple"] = getData("couple");
$aData["group"] = getData("group");
$aData["total"] = getData("amount")/100;
$aData["paid"] = 1;
$aData["date"] = date("Y-m-d H:i:s");
Zend_Db_Table_Abstract::setDefaultAdapter($oDb);
$oBooking = new Booking() ;
$oBooking->insert($aData);
}
function sendBookingNotification( \Stripe\Charge $oCharge ){
$sDate = date("d/m/Y");
$sTxId = $oCharge->id;
$amount = $oCharge->amount;
$sName = getData("first_name");
$sLocation = getData('location');
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
// $mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = "smtp.1and1.com"; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'info@thequranicway.com'; // SMTP username
$mail->Password = 'LetM3!n2'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
//Recipients
$mail->setFrom('london@noesisinstitute.com', 'Noesis Institute');
$mail->addAddress(getData("email"), getData("first_name"). " " . getData("last_name")); // Add a recipient
$mail->addBCC('london@noesisinstitute.com', 'Noesis Institute'); // Add a recipient
$mail->addReplyTo('london@noesisinstitute.com', 'Noesis Institute');
//Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Thank you - Please Read Important information about your Booking';
$mail->Body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html style="font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="width=device-width" name="viewport" />
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>Billing e.g. invoices and receipts</title>
<style type="text/css">img {
max-width: 100%;
}
body {
-webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; line-height: 1.6em;
}
body {
background-color: #f6f6f6;
}
@media only screen and (max-width: 640px) {
body {
padding: 0 !important;
}
h1 {
font-weight: 800 !important; margin: 20px 0 5px !important;
}
h2 {
font-weight: 800 !important; margin: 20px 0 5px !important;
}
h3 {
font-weight: 800 !important; margin: 20px 0 5px !important;
}
h4 {
font-weight: 800 !important; margin: 20px 0 5px !important;
}
h1 {
font-size: 22px !important;
}
h2 {
font-size: 18px !important;
}
h3 {
font-size: 16px !important;
}
.container {
padding: 0 !important; width: 100% !important;
}
.content {
padding: 0 !important;
}
.content-wrap {
padding: 10px !important;
}
.invoice {
width: 100% !important;
}
}
</style>
</head>
<body bgcolor="#f6f6f6" itemscope="" itemtype="http://schema.org/EmailMessage" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; line-height: 1.6em; background-color: #f6f6f6; margin: 0;">
<table bgcolor="#f6f6f6" class="body-wrap" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; background-color: #f6f6f6; margin: 0;">
<tbody>
<tr style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0;" valign="top">&nbsp;</td>
<td class="container" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; display: block !important; max-width: 600px !important; clear: both !important; margin: 0 auto;" valign="top" width="600">
<div class="content" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; max-width: 600px; display: block; margin: 0 auto; padding: 20px;">
<table bgcolor="#fff" cellpadding="0" cellspacing="0" class="main" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; border-radius: 3px; background-color: #fff; margin: 0; border: 1px solid #e9e9e9;" width="100%">
<tbody>
<tr style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td align="center" class="content-wrap aligncenter" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: center; margin: 0; padding: 20px;" valign="top">
<table cellpadding="0" cellspacing="0" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;" width="100%">
<tbody>
<tr style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td class="content-block" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
<h1 align="center" class="aligncenter" style="font-family: \'Helvetica Neue\',Helvetica,Arial,\'Lucida Grande\',sans-serif; box-sizing: border-box; font-size: 32px; color: #000; line-height: 1.2em; font-weight: 500; text-align: center; margin: 40px 0 0;"><img alt="Noesis Institute" src="http://www.thequranicway.com/logo.png" style="width: 227px; height: 65px;" /></h1>
<h2 align="center" class="aligncenter" style="font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lucida Grande&quot;, sans-serif; box-sizing: border-box; font-size: 32px; color: rgb(0, 0, 0); line-height: 1.2em; font-weight: 500; text-align: center; margin: 40px 0px 0px;">Receipt</h2>
<h2 align="center" class="aligncenter" style="font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lucida Grande&quot;, sans-serif; box-sizing: border-box; font-size: 32px; color: rgb(0, 0, 0); line-height: 1.2em; font-weight: 500; text-align: center; margin: 40px 0px 0px;">&pound;'.number_format( $amount/100, 2).' Paid</h2>
<p style="text-align: left;"><strong>Name: </strong>'.$sName.'<br style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;" />
<strong>Transaction Id: </strong>'.$sTxId.'<br style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;" />
<strong>Booking Date: </strong>'.$sDate.'<br style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;" />
<strong>Location: </strong>'.$sLocation.'</p>
</td>
</tr>
<tr style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td class="content-block" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
<p style="text-align: left;">Assalaamualaikum wa Rahmatullahi wa Barakatuh,</p>
<p style="text-align: left;">JazakumAllahukhayran for your booking.&nbsp; We look forward to learning with you inshaAllah.</p>
<p style="text-align: left;">Registration for the course will be from 9:30am inshaAllah with teaching starting at 10am promptly. The Shaykh is known to have a lot of material MashaAllah we can all benefit from so do come on time so you can get maximum benefit inshaAllah.</p>
<p style="text-align: left;">We have some general information below of useful logistical matters for each city inshaAllah.</p>
<p style="text-align: left;">Please note that course handouts will be provided on the day. Noesis operate a strict policy of no recordings of their courses whether audio or video.</p>
<p style="text-align: left;">If you have any special dietary requirements please let us know as soon as possible so we can do our best to cater for you inshaAllah. &nbsp;We have been asked to pass on any requests to the catering team 14 days before the course so requests after this date cannot be guaranteed.</p>
<p style="text-align: left;">Lunch and light refreshments will be provided for the day. &nbsp;For children please refer to the emails that relate to the relevant service as the position may differ by age and City.</p>
<p style="text-align: left;">If you have any further questions please don&rsquo;t hesitate to get in touch inshaAllah.</p>
<p style="text-align: left;">Masalaama,</p>
<p style="text-align: left;"><strong>Noesis Team</strong></p>
<hr />
<p style="text-align: left;">Other courses you may also be interested in:</p>
<p style="text-align: left;">Saturday 17 March 2018 <a href="http://www.noesisinstitute.com/keeping-it-halal"><strong>Keeping it Halal: Social Interactions - Leeds</strong></a></p>
<hr />
<h3>Information about Mindful Muslims: Raising Ourselves, Raising a Generation</h3>
<p style="text-align: left;">Please email <a href="mailto:london@noesisinstitute.com">london@noesisinstitute.com</a> for all queries including costs and spaces regarding the parent and baby room, the cr&egrave;che aimed at 3-6 year olds and the youth programme for 7-11 year olds. Spaces are limited.</p>
<h3 style="text-align: left;">Manchester (Bury)</h3>
<p style="text-align: left;">The Village Hotel, Rochdale Road,Bury, BL9 7BQ (<a href="https://goo.gl/maps/MLx9fsnqKLw">map</a>)</p>
<p style="text-align: left;">Free parking on site</p>
<h3 style="text-align: left;">Cardiff</h3>
<p style="text-align: left;">Cardiff Metropolitan University, Cyncoed Campus (<a href="https://goo.gl/maps/HFeKpoTPofL2">map</a>)</p>
<h3 style="text-align: left;">London</h3>
<p style="text-align: left;">Read Academy, 34 Mansfield Road, Ilford IG1 3BD (<a href="https://goo.gl/maps/2Ca71ExoHLq">map</a>)</p>
<p style="text-align: left;">Free parking on side roads on yellow lines or parking at the exchange mall car park for around &pound;1.50 all day on a Sunday (a short walk away).</p>
</td>
</tr>
<tr style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td align="center" class="content-block aligncenter" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: center; margin: 0; padding: 0 0 20px;" valign="top">&nbsp;</td>
</tr>
<tr style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td align="center" class="content-block aligncenter" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: center; margin: 0; padding: 0 0 20px;" valign="top"><a href="http://www.noesisinstitute.com" target="_blank">Noesis Institute</a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<div class="footer" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; clear: both; color: #999; margin: 0; padding: 20px;">
<table style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;" width="100%">
<tbody>
<tr style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td align="center" class="aligncenter content-block" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 12px; vertical-align: top; color: #999; text-align: center; margin: 0; padding: 0 0 20px;" valign="top">Questions? Email <a href="mailto:london@noesisinstitute.com" style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 12px; color: #999; text-decoration: underline; margin: 0;">london@noesisinstitute.com</a></td>
</tr>
</tbody>
</table>
</div>
</div>
</td>
<td style="font-family: \'Helvetica Neue\',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0;" valign="top">&nbsp;</td>
</tr>
</tbody>
</table>
</body>
</html>
';
$mail->AltBody = 'Successfully charged £'.number_format( $amount/100, 2);
$mail->send();
} catch (Exception $e) {
$_SESSION["status_code"] = "error"; // all good;
$_SESSION["message"] = 'Message could not be sent. Mailer Error: '. $mail->ErrorInfo;
header("location:/index.php");
}
}