Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
86 lines (66 loc) · 2.26 KB
/
Copy pathindex.php
File metadata and controls
86 lines (66 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
error_reporting(E_ALL ^ E_NOTICE);
date_default_timezone_set("America/New_York");
require "vendor/autoload.php";
// Load local config if available
@include "config.local.php";
use Nette\Mail\Message;
use Nette\Mail\SendmailMailer;
Stripe::setApiKey(STRIPE_SECRET_KEY);
Flight::route("GET /", function() {
Flight::render("index", array(), "body_content");
Flight::render("layout");
});
Flight::route("POST /", function() {
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
$renderer = new \flight\template\View(__DIR__."/views");
// Determine values depending on membership type
switch($_POST["membership_type"]) {
case "Individual Membership":
$amount = "12500";
break;
case "Corporate Membership":
$amount = "25000";
break;
default:
Flight::render("index.php");
exit;
}
try {
Stripe_Charge::create(array(
"amount" => $amount,
"currency" => "CAD",
"description" => $_POST["membership_type"],
"card" => $_POST["stripeToken"],
"receipt_email" => $_POST["email_address"]
));
$mailer = new SendmailMailer;
// Send welcome email
$mail = new Message;
$mail->setFrom(MAIL_FROM)
->addTo($_POST["email_address"])
->setSubject("Welcome to Cowork Niagara")
->setHtmlBody($renderer->fetch("welcome_email.php"));
$mailer->send($mail);
// Send admin email
$mail = new Message;
$mail->setFrom(MAIL_FROM)
->addTo(ADMIN_EMAIL)
->setSubject("New Cowork Niagara Membership")
->setHtmlBody($renderer->fetch("admin_email.php"));
$mailer->send($mail);
// Signup newsletter if checked
Flight::redirect("/welcome");
}
catch (Stripe_CardError $e) {
$body = $e->getJsonBody();
$stripe_error = $body["error"]["message"];
Flight::render("index", array("stripe_error" => $stripe_error), "body_content");
Flight::render("layout");
}
});
Flight::route("GET /welcome", function() {
Flight::render("welcome", array(), "body_content");
Flight::render("layout");
});
Flight::start();