From cbf48a859e769d3fb85b532566573c30c677951c Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Fri, 8 Mar 2019 13:45:30 -0600 Subject: [PATCH] email receipt --- composer.json | 3 +- composer.lock | 309 ++++++++++++++++++++++- index.php | 63 ++++- src/.env.example | 2 + views/emails/email.php | 554 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 926 insertions(+), 5 deletions(-) create mode 100644 views/emails/email.php diff --git a/composer.json b/composer.json index f5dd0fd..3ef5ca0 100644 --- a/composer.json +++ b/composer.json @@ -4,6 +4,7 @@ "bramus/router": "~1.4", "gabordemooij/redbean": "^5.2", "stripe/stripe-php": "^6.30", - "ramsey/uuid": "^3.8" + "ramsey/uuid": "^3.8", + "wildbit/postmark-php": "^2.6" } } diff --git a/composer.lock b/composer.lock index 59ac821..0029188 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2e797d36de3e030f472e3cf3ce1f7a3a", + "content-hash": "54987e4155122b56b46a3afd2bad87c0", "packages": [ { "name": "bramus/router", @@ -94,6 +94,189 @@ ], "time": "2018-10-26T09:06:03+00:00" }, + { + "name": "guzzlehttp/guzzle", + "version": "6.3.3", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", + "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.4", + "php": ">=5.5" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", + "psr/log": "^1.0" + }, + "suggest": { + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.3-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2018-04-22T15:46:56+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "v1.3.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2016-12-20T10:07:11+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.5.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "9f83dded91781a01c63574e387eaa769be769115" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/9f83dded91781a01c63574e387eaa769be769115", + "reference": "9f83dded91781a01c63574e387eaa769be769115", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0", + "ralouphie/getallheaders": "^2.0.5" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "time": "2018-12-04T20:46:45+00:00" + }, { "name": "paragonie/random_compat", "version": "v9.99.99", @@ -189,6 +372,96 @@ ], "time": "2015-07-25T16:39:46+00:00" }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "2.0.5", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/5601c8a83fbba7ef674a7369456d12f1e0d0eafa", + "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "phpunit/phpunit": "~3.7.0", + "satooshi/php-coveralls": ">=1.0" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "time": "2016-02-11T07:05:27+00:00" + }, { "name": "ramsey/uuid", "version": "3.8.0", @@ -436,6 +709,40 @@ "environment" ], "time": "2019-01-30T10:43:17+00:00" + }, + { + "name": "wildbit/postmark-php", + "version": "2.6.0", + "source": { + "type": "git", + "url": "https://github.com/wildbit/postmark-php.git", + "reference": "70162fe99ac0a80e599f76ae84e4b6e655081e04" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wildbit/postmark-php/zipball/70162fe99ac0a80e599f76ae84e4b6e655081e04", + "reference": "70162fe99ac0a80e599f76ae84e4b6e655081e04", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "~6.0", + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "4.4.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "Postmark\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "The officially supported client for Postmark (http://postmarkapp.com)", + "time": "2018-07-24T22:40:23+00:00" } ], "packages-dev": [], diff --git a/index.php b/index.php index 9798d6e..603f0e8 100644 --- a/index.php +++ b/index.php @@ -26,6 +26,9 @@ $dotenv->required([ 'STRIPE_API_PUBLIC_KEY', ]); +$_SERVER['receipt-url'] = $_SERVER['HTTP_HOST']."/thank-you/"; +$_SERVER['manage-url'] = $_SERVER['HTTP_HOST']."/manage/"; + $router = new Router(); $r = R::setup('mysql:host=' . $_SERVER['DB_HOST'] . ';dbname=' . $_SERVER['DB_NAME'], $_SERVER['DB_USER'], $_SERVER['DB_PASS']); @@ -36,7 +39,7 @@ $router->set404(function () { }); // Static route: / (homepage) -$router->get('/', function(){ +$router->get('/', function () { $settings = \RedBeanPHP\R::load('settings', 1); $tickets = $settings->value; @@ -49,7 +52,7 @@ $router->get('/', function(){ include 'views/common/footer.php'; }); -$router->get('/notify', function(){ +$router->get('/notify', function () { include 'views/common/head.php'; include 'views/notify.php'; include 'views/common/footer.php'; @@ -160,6 +163,60 @@ $router->post('/checkout', function () { unset($guest, $uuid); } + $client = new Postmark\PostmarkClient($_SERVER['POSTMARK_API_KEY']); + + /** + $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']); + $cabanaReservation = $_POST['cabanaReservation'] > 0 ? convertPossibleFloatToCents($_SERVER['CABANA_PRICE']) : 0; + + */ + $orderedItems = []; + if ($eventTicketQty > 0) { + array_push($orderedItems, ['description' => $eventTicketQty . ' x Dinner tickets', 'amount' => '$' . number_format(($eventTicketPrice / 100), 2)]); + } + if ($tableTicketQty > 0) { + array_push($orderedItems, ['description' => $eventTicketQty . ' x Table', 'amount' => '$' . number_format(($tableTicketPrice / 100), 2)]); + } + if ($ticketEnhancerQty > 0) { + array_push($orderedItems, ['description' => $ticketEnhancerQty . ' x Packs of ticket enhancers', 'amount' => '$' . number_format(($ticketEnhancerPrice / 100), 2)]); + } + if ($cabanaReservation > 0) { + array_push($orderedItems, ['description' => 'Cabana reservation', 'amount' => '$' . number_format(($cabanaReservation / 100), 2)]); + } + if ($additionalContribution > 0) { + array_push($orderedItems, ['description' => 'Additional contribution', 'amount' => '$' . number_format(($additionalContribution / 100), 2)]); + } + + // Check if payment was made with Stripe + if (isset($stripeCustomerToken)) { + $paymentMethod = 'credit_payment'; + $paymentNote = $stripeCustomerToken; + }else{ + $paymentMethod = 'check_payment'; + $paymentNote = true; + } + + $client->sendEmailWithTemplate( + $_SERVER['POSTMARK_FROM'], + $order->email, + $_SERVER['POSTMARK_TEMPLATE'], + [ + 'name' => $order->first_name, + 'product_name' => 'Dinner in the Woods ' . date('Y'), + 'date' => date('m-d-Y'), + 'receipt_id' => $order->id, + 'receipt_details' => $orderedItems, + 'total' => '$' . number_format(($order->total_cents / 100), 2), + 'action_manage_guests_url' => '//'.$_SERVER['manage-url'] . $order->uuid, + 'action_receipt_url' => '//'.$_SERVER['receipt-url'] . $order->uuid, + $paymentMethod => $paymentNote + ] + ); + header('Location: /thank-you/' . $redirectUuid->toString()); }); @@ -209,7 +266,7 @@ $router->post('/manage/{uuid}', function ($uuid) { } } - header('Location: /manage/'. $uuid . '?alert=success'); + header('Location: /manage/' . $uuid . '?alert=success'); }); // Run it! diff --git a/src/.env.example b/src/.env.example index fd80508..b586629 100644 --- a/src/.env.example +++ b/src/.env.example @@ -8,5 +8,7 @@ DB_NAME="ditw" DB_USER="root" DB_PASS="root" POSTMARK_API_KEY="special" +POSTMARK_TEMPLATE="identifier_for_template" +POSTMARK_FROM="sender@email.com" STRIPE_API_SECRET_KEY="sk" STRIPE_API_PUBLIC_KEY="pk" \ No newline at end of file diff --git a/views/emails/email.php b/views/emails/email.php new file mode 100644 index 0000000..9d1bd59 --- /dev/null +++ b/views/emails/email.php @@ -0,0 +1,554 @@ + + + + + + + + + *|MC:SUBJECT|* + + + + + + +
+ + + + +
+ + + + + + + + + + + + +
+ + + + + +
+ + + + + + + + +
+ + +
+ + + +
+ + + + + +
+ + + + + + + + +
+ + Hello all!
+
+ The countdown to Dinner in the Woods is on -- We have just four weeks until the event! 
+
+ In preparation for the evening, please take a look at your table reservation and update your dinner party preferences; 
+   +
+ + + +
+ + + + + +
+ + + + + + +
+ Update Your Dinner Preferences +
+
+ + + + + +
+ + + + + + + + +
+ + Please update your table information with the names of your guests, their email addresses and any dietary restrictions.
+
+ Dinner in the Woods is the primary fundraiser for our wonderful school. Our goal this year is to raise $40,000, which will be key to supporting Phase 2 of our building campaign: building our machine shed for our school property.
+
+ We have a fantastic evening of delicious food, music and dancing, and exciting auction items for you to enjoy. Your support is so important to us and we thank you for spending June 2nd with us!
+
+ Watch your email for a few more updates as we approach the event!
+
+ Sincerely,
+ Dinner in the Woods committee & everyone from Nature's Classroom Institute & Montessori School +

+ +
+ + + +
+ + + + + +
+ + + + + + + + +
+ + Copyright © *|CURRENT_YEAR|* *|LIST:COMPANY|*, All rights reserved.
+ *|IFNOT:ARCHIVE_PAGE|* *|LIST:DESCRIPTION|*
+
+ Our mailing address is:
+ *|HTML:LIST_ADDRESS_HTML|* *|END:IF|*
+
+ Want to change how you receive these emails?
+ You can update your preferences or unsubscribe from this list.
+
+ *|IF:REWARDS|* *|HTML:REWARDS|* *|END:IF|* +
+ + + +
+ + +
+
+ + \ No newline at end of file