saving form data on checkout
This commit is contained in:
40
index.php
40
index.php
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Bramus\Router\Router;
|
||||
use RedBeanPHP\R;
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
require __DIR__ . '/src/functions.php';
|
||||
@@ -12,12 +13,14 @@ $dotenv->required([
|
||||
'EVENT_TICKET_PRICE',
|
||||
'ENHANCER_TICKET_PRICE',
|
||||
'DB_HOST',
|
||||
'DB_NAME',
|
||||
'DB_USER',
|
||||
'DB_PASS',
|
||||
'POSTMARK_API_KEY',
|
||||
]);
|
||||
|
||||
$router = new Router();
|
||||
$r = R::setup('mysql:host=' . $_SERVER['DB_HOST'] . ';dbname=' . $_SERVER['DB_NAME'], $_SERVER['DB_USER'], $_SERVER['DB_PASS']);
|
||||
|
||||
// Custom 404 Handler
|
||||
$router->set404(function () {
|
||||
@@ -51,6 +54,43 @@ $router->post('/', function () {
|
||||
include 'views/common/footer.php';
|
||||
});
|
||||
|
||||
$router->post('/checkout', function () {
|
||||
//todo this is duplicated and should be handled by an object.
|
||||
// POST variables
|
||||
$originalTicketQty = $eventTicketQty = getInteger($_POST['eventTicketQty']); // Store original ticket quantity
|
||||
$ticketEnhancerQty = getInteger($_POST['ticketEnhancerQty']);
|
||||
|
||||
// Calculate totals
|
||||
$additionalContribution = convertPossibleFloatToCents($_POST['additionalContribution']);
|
||||
list($tableTicketQty, $eventTicketQty) = eventPricing($eventTicketQty);
|
||||
$eventTicketPrice = convertPossibleFloatToCents($eventTicketQty * $_SERVER['EVENT_TICKET_PRICE']);
|
||||
$tableTicketPrice = convertPossibleFloatToCents($tableTicketQty * $_SERVER['TABLE_TICKET_PRICE']);
|
||||
$ticketEnhancerPrice = convertPossibleFloatToCents($ticketEnhancerQty * $_SERVER['ENHANCER_TICKET_PRICE']);
|
||||
|
||||
// Sum the cart totals
|
||||
$cartTotal = $eventTicketPrice + $tableTicketPrice + $ticketEnhancerPrice + $additionalContribution;
|
||||
|
||||
$order = R::dispense('orders');
|
||||
$order->ticket_quantity = $originalTicketQty;
|
||||
$order->ticket_cents = $eventTicketPrice + $tableTicketPrice;
|
||||
$order->enhancer_quantity = $ticketEnhancerQty;
|
||||
$order->enhancer_cents = $ticketEnhancerPrice;
|
||||
$order->additional_cents = $additionalContribution;
|
||||
$order->total_cents = $cartTotal;
|
||||
$order->first_name = $_POST['firstName'];
|
||||
$order->last_name = $_POST['lastName'];
|
||||
$order->email = $_POST['email'];
|
||||
$order->address = $_POST['address'];
|
||||
$order->city = $_POST['city'];
|
||||
$order->state = $_POST['state'];
|
||||
$order->zip = $_POST['zip'];
|
||||
$order->payment_type = $_POST['paymentMethod'];
|
||||
$order->stripe_token = '1234';
|
||||
$order->uuid = $_POST['firstName'];
|
||||
$id = R::store($order);
|
||||
var_dump($id);
|
||||
});
|
||||
|
||||
|
||||
// Run it!
|
||||
$router->run();
|
||||
Reference in New Issue
Block a user