Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'core/init.php';
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- require 'vendor/autoload.php';
- \Stripe\Stripe::setApiKey(STRIPE_PRIVATE);
- $token = $_POST['stripeToken'];
- $email = $_POST['stripeEmail'];
- $user_id = $_POST['userid'];
- $phone = sanitize($_POST['phone']);
- $final_price = sanitize($_POST['final_price']);
- $final_price = round($final_price,2) *100;
- // $final_price = number_format($final_price,2) / 100;
- $tax= sanitize($_POST['tax']);
- $sub_total = sanitize($_POST['sub_total']);
- $description=sanitize($_POST['description']);
- $cart_id = sanitize($_POST['cart_id']);
- $portes = sanitize($_POST['portes']);
- $stripeBillingName = sanitize($_POST['stripeBillingName']);
- $stripeBillingAddressCountry = sanitize($_POST['stripeBillingAddressCountry']);
- // $stripeBillingAddressCountryCode = $_POST['stripeBillingAddressCountryCode'];
- $stripeBillingAddressZip = sanitize($_POST['stripeBillingAddressZip']);
- $stripeBillingAddressLine1 = sanitize($_POST['stripeBillingAddressLine1']);
- $stripeBillingAddressCity = sanitize($_POST['stripeBillingAddressCity']);
- // $stripeBillingAddressState = $_POST['stripeBillingAddressState'];
- $stripeShippingName = sanitize($_POST['stripeShippingName']);
- $stripeShippingAddressCountry = sanitize($_POST['stripeShippingAddressCountry']);
- // $stripeShippingAddressCountryCode = $_POST['stripeShippingAddressCountryCode'];
- $stripeShippingAddressZip = sanitize($_POST['stripeShippingAddressZip']);
- $stripeShippingAddressLine1 = sanitize($_POST['stripeShippingAddressLine1']);
- $stripeShippingAddressCity = sanitize($_POST['stripeShippingAddressCity']);
- // $stripeShippingAddressState = $_POST['stripeShippingAddressState'];
- $metadata = array(
- "cart_id" => $cart_id,
- "tax" => $tax,
- "sub_total"=>$sub_total,
- );
- $customer = \Stripe\Customer::create(array(
- 'email' => $email,
- 'source' => $token
- ));
- $charge = \Stripe\Charge::create(array(
- 'customer' => $customer->id,
- 'amount' => $final_price,
- 'currency' => CURRENCY,
- 'receipt_email' => $email,
- 'description' => $description,
- 'metadata' => $metadata
- ));
- //adjust the inventory qnt
- $itemQ =$db->query("SELECT * FROM cart where id = '$cart_id'");
- $itemR = mysqli_fetch_assoc($itemQ);
- $items= json_decode($itemR['items'], true);
- foreach ($items as $item) {
- $item_id = $item['id'];
- $productQ = $db->query("SELECT quantity from products where id ='{$item_id}'");
- $product = mysqli_fetch_assoc($productQ);
- $newQnt = $product['quantity'] - $item['quantity'];
- $db->query("UPDATE products set quantity ='{$newQnt}' where id = '{$item_id}'");
- }
- // this updates the cart
- $final_price = round($final_price,2) /100;
- $db->query("UPDATE cart SET paid = 1 where id = '{$cart_id}'");
- $db->query("INSERT into transactions (charge_id, cart_id, user_id, billing_name, billing_country, billing_zip, billing_address, billing_city, shipping_name, shipping_country, shipping_zip, shipping_address, shipping_city, sub_total, tax, grand_total, description, txn_type) values ('$charge->id','$cart_id','$user_id','$stripeBillingName','$stripeBillingAddressCountry','$stripeBillingAddressZip','$stripeBillingAddressLine1','$stripeBillingAddressCity','$stripeShippingName','$stripeShippingAddressCountry','$stripeShippingAddressZip','$stripeShippingAddressLine1','$stripeShippingAddressCity','$sub_total','$tax','$final_price','$description','$charge->object')");
- $domain = ($_SERVER['HTTP_HOST'] != 'localhost')? '.'.$_SERVER['HTTP_HOST']:false;
- setcookie(CART_COOKIE,'',1,"/",$domain,false);
- // include 'includes/head.php';
- // include 'includes/navigation.php';
- $final_price = round($final_price,2) *100;
- ?>
- <h1 class="text-center text-success">Thank You!</h1>
- <p>Your card has been successfully charged <?= money($final_price/100); ?>. You have been emailed a receipt. Please check your spam folder if is not in your inbox. Aditionally you can print this page as a receipt.</p>
- <p>Your receipt number is: <strong><?= $cart_id; ?></strong> </p>
- <p>Your order will be shipped to the address bellow.</p>
- <address class="">
- <?= $stripeShippingName.', '.$phone; ?><br>
- <?= $stripeShippingAddressCountry.', '.$stripeShippingAddressCity; ?><br>
- <?= $stripeShippingAddressLine1.', '.$stripeShippingAddressZip; ?>
- </address>
- <?php
- // $txnQuery = $db->query("SELECT * FROM transactions where id = '{$cart_id}'");
- // $txn = mysqli_fetch_assoc($txnQuery);
- // $cartid = $txn['cart_id'];
- $cartQuery=$db->query("SELECT * FROM cart where id = '{$cart_id}'");
- $cart = mysqli_fetch_assoc($cartQuery);
- $items = json_decode($cart['items'],true);
- $idArray = array();
- $products = array();
- foreach ($items as $item) {
- $idArray[]=$item['id'];
- }
- $ids = implode(',',$idArray);
- $productQ = $db->query(
- "SELECT i.id, i.title as 'title', c.id as 'cid', c.category as 'subcat', p.category as 'cat'
- from products i
- left join categories c on i.categories = c.id
- left join categories p on c.parent = p.id
- where i.id in ({$ids})
- ");
- while ($p = mysqli_fetch_assoc($productQ)) {
- foreach ($items as $item) {
- if ($item['id'] == $p['id']) {
- $x = $item;
- continue;
- }
- }
- $products[]=array_merge($x,$p);
- }
- $mail = new PHPMailer(true);
- //Tell PHPMailer to use SMTP
- $mail->isSMTP();
- //Enable SMTP debugging
- // 0 = off (for production use)
- // 1 = client messages
- // 2 = client and server messages
- $mail->SMTPDebug = 2;
- //Ask for HTML-friendly debug output
- $mail->Debugoutput = 'html';
- //Set the hostname of the mail server
- $mail->Host = 'smtp.gmail.com';
- // use
- // $mail->Host = gethostbyname('smtp.gmail.com');
- // if your network does not support SMTP over IPv6
- //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
- $mail->Port = 587;
- //Set the encryption system to use - ssl (deprecated) or tls
- $mail->SMTPSecure = 'tls';
- //Whether to use SMTP authentication
- $mail->SMTPAuth = true;
- //Username to use for SMTP authentication - use full email address for gmail
- $mail->Username = '***************@gmail.com';
- //Password to use for SMTP authentication
- $mail->Password = '***************';
- //Set who the message is to be sent from
- $mail->setFrom('from@example.com', 'First Last');
- //Set an alternative reply-to address
- $mail->addReplyTo('replyto@example.com', 'First Last');
- //Set who the message is to be sent to
- $mail->addAddress($email, 'John Doe');
- //Set the subject line
- $mail->Subject = 'PHPMailer GMail SMTP test';
- //Read an HTML message body from an external file, convert referenced images to embedded,
- //convert HTML into a basic plain-text alternative body
- //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
- //Replace the plain text body with one created manually
- $mail->Body = '
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <style>
- * {
- color:white;
- margin: 0;
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
- box-sizing: border-box;
- font-size: 14px;
- }
- img {
- max-width: 100%;
- }
- body {
- -webkit-font-smoothing: antialiased;
- -webkit-text-size-adjust: none;
- width: 100% !important;
- height: 100%;
- line-height: 1.6em;
- /* 1.6em * 14px = 22.4px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients */
- /*line-height: 22px;*/
- }
- table td {
- vertical-align: top;
- }
- /* -------------------------------------
- BODY & CONTAINER
- ------------------------------------- */
- body {
- background-color: #f6f6f6;
- }
- .body-wrap {
- background-color: #f6f6f6;
- width: 100%;
- }
- .container {
- display: block !important;
- max-width: 600px !important;
- margin: 0 auto !important;
- /* makes it centered */
- clear: both !important;
- }
- .content {
- max-width: 600px;
- margin: 0 auto;
- display: block;
- padding: 20px;
- }
- /* -------------------------------------
- HEADER, FOOTER, MAIN
- ------------------------------------- */
- .main {
- background-color: #4f4f4f;
- box-shadow: 1px 1px 10px 2px black;
- border: 1px solid #e9e9e9;
- border-radius: 3px;
- }
- .content-wrap {
- padding: 20px;
- }
- .content-block {
- padding: 0 0 20px;
- }
- .header {
- width: 100%;
- margin-bottom: 20px;
- }
- .footer {
- width: 100%;
- clear: both;
- color: #999;
- padding: 20px;
- }
- .footer p, .footer a, .footer td {
- color: #999;
- font-size: 12px;
- }
- /* -------------------------------------
- TYPOGRAPHY
- ------------------------------------- */
- h1, h2, h3 {
- font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
- color: #000;
- margin: 40px 0 0;
- line-height: 1.2em;
- font-weight: 400;
- }
- h1 {
- font-size: 32px;
- font-weight: 500;
- /* 1.2em * 32px = 38.4px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients */
- /*line-height: 38px;*/
- }
- h2 {
- font-size: 24px;
- /* 1.2em * 24px = 28.8px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients */
- /*line-height: 29px;*/
- }
- h3 {
- font-size: 18px;
- /* 1.2em * 18px = 21.6px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients */
- /*line-height: 22px;*/
- }
- h4 {
- font-size: 14px;
- font-weight: 600;
- }
- p, ul, ol {
- margin-bottom: 10px;
- font-weight: normal;
- }
- p li, ul li, ol li {
- margin-left: 5px;
- list-style-position: inside;
- }
- /* -------------------------------------
- LINKS & BUTTONS
- ------------------------------------- */
- a {
- color: #348eda;
- text-decoration: underline;
- }
- .btn-primary {
- text-decoration: none;
- color: #FFF;
- background-color: #348eda;
- border: solid #348eda;
- border-width: 10px 20px;
- line-height: 2em;
- /* 2em * 14px = 28px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients */
- /*line-height: 28px;*/
- font-weight: bold;
- text-align: center;
- cursor: pointer;
- display: inline-block;
- border-radius: 5px;
- text-transform: capitalize;
- }
- /* -------------------------------------
- OTHER STYLES THAT MIGHT BE USEFUL
- ------------------------------------- */
- .last {
- margin-bottom: 0;
- }
- .first {
- margin-top: 0;
- }
- .aligncenter {
- text-align: center;
- }
- .alignright {
- text-align: right;
- }
- .alignleft {
- text-align: left;
- }
- .clear {
- clear: both;
- }
- /* -------------------------------------
- ALERTS
- Change the class depending on warning email, good email or bad email
- ------------------------------------- */
- .alert {
- font-size: 16px;
- color: #fff;
- font-weight: 500;
- padding: 20px;
- text-align: center;
- border-radius: 3px 3px 0 0;
- }
- .alert a {
- color: #fff;
- text-decoration: none;
- font-weight: 500;
- font-size: 16px;
- }
- .alert.alert-warning {
- background-color: #FF9F00;
- }
- .alert.alert-bad {
- background-color: #D0021B;
- }
- .alert.alert-good {
- background-color: #68B90F;
- }
- /* -------------------------------------
- INVOICE
- Styles for the billing table
- ------------------------------------- */
- .invoice {
- margin: 40px auto;
- text-align: left;
- width: 80%;
- }
- .invoice td {
- padding: 5px 0;
- }
- .invoice .invoice-items {
- width: 100%;
- }
- .invoice .invoice-items td {
- border-top: #eee 1px solid;
- }
- .invoice .invoice-items .total td {
- border-top: 2px solid #333;
- border-bottom: 2px solid #333;
- font-weight: 700;
- }
- /* -------------------------------------
- RESPONSIVE AND MOBILE FRIENDLY STYLES
- ------------------------------------- */
- @media only screen and (max-width: 640px) {
- body {
- padding: 0 !important;
- }
- h1, h2, h3, 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>
- <table class="body-wrap">
- <tr>
- <td></td>
- <td class="container" width="600">
- <div class="content">
- <table class="main" width="100%" cellpadding="0" cellspacing="0">
- <tr>
- <td class="content-wrap aligncenter">
- <table width="100%" cellpadding="0" cellspacing="0">
- <tr>
- <img src="https://i.imgur.com/urrJz2x.png" alt="">
- </tr>
- <tr>
- <td class="content-block">
- <h1 class="aligncenter">You paid '.money($final_price/100).'</h1>
- </td>
- </tr>
- <tr>
- <td class="content-block aligncenter">
- <table class="invoice">
- <tr>
- <td>'.$stripeShippingName.'<br>'.$stripeShippingAddressCountry.', '.$stripeShippingAddressCity.'<br>'.$stripeShippingAddressLine1.', '.$stripeShippingAddressZip.'</td>
- </tr>
- <tr>
- <td>
- <table class="invoice-items" cellpadding="0" cellspacing="0">
- '
- foreach($products as $product){'
- <tr>
- <td>'.$product['title'].' x'.$product['quantity'].'</td>
- <td class="alignright">'.money($price['price']).'</td>
- </tr>
- '}'
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td class="content-block">
- <h2 class="aligncenter">Thank You for using CPUROCKS©</h2>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </div>
- </td>
- <td></td>
- </tr>
- </table>
- </html>
- ';
- $mail->IsHTML(true);
- $mail->AltBody = 'This is a plain-text message body';
- //send the message, check for errors
- if (!$mail->send()) {
- echo "Mailer Error: " . $mail->ErrorInfo;
- } else {
- echo "Message sent!";
- }
- ?>
- <?php
- include 'includes/footer.php';
- // echo '<h1>Successfully charged '. money($final_price/100) .'!</h1>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement