aboutsummaryrefslogtreecommitdiff
path: root/include/pay.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/pay.php')
-rw-r--r--include/pay.php135
1 files changed, 135 insertions, 0 deletions
diff --git a/include/pay.php b/include/pay.php
new file mode 100644
index 0000000..596251c
--- /dev/null
+++ b/include/pay.php
@@ -0,0 +1,135 @@
+<?php
+/**
+ * BusinessAdmin: administrative software for small companies
+ * Copyright (C) 2015 Camil Staps (ViviSoft)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+require_once('./index.php');
+require('./header.php');
+?>
+
+<div class="container">
+ <div class="row">
+ <div class="col-md-10 col-md-offset-1">
+ <div class="panel panel-default payment-panel">
+ <div class="panel-heading">
+ <h3 class="panel-title">Pay<i class="fa fa-credit-card fa-fw fa-lg pull-right"></i></h3>
+ </div>
+ <div class="panel-body">
+ <?php
+ if (!isset($_REQUEST['id']) || !isset($_REQUEST['key'])) {
+ $notFound = true;
+ } else {
+ $offerId = $_REQUEST['id'];
+ $offerKey = $_REQUEST['key'];
+ $notFound = false;
+ try {
+ $_offer = new Offer($_pdo, $offerId);
+ } catch (Exception $e) {
+ $notFound = true;
+ }
+ }
+ if ($notFound || $offerKey != $_offer->key) {
+ ?>
+ <div class='form-group alert alert-danger'>The invoice could not be found.</div>
+ <?php
+ } elseif (isset($_POST['payment_method_nonce'])) {
+ $nonce = $_POST['payment_method_nonce'];
+ $trans = Braintree_Transaction::sale([
+ 'amount' => (string) $_offer->calculate(Calculatable::TOTAL),
+ 'paymentMethodNonce' => $nonce,
+ 'options' => [
+ 'submitForSettlement' => true
+ ]
+ ]);
+
+ if (!$trans->success) {
+ echo '<div class="form-group alert alert-danger">';
+ echo '<h4>Your transaction could not be completed:</h4>';
+ foreach ($trans->errors->deepAll() as $error) {
+ echo "{$error->attribute}: {$error->code} {$error->message}<br/>";
+ }
+ echo '<b>Please try again, or <a href="mailto:'.Constants::invoice_email.'">contact us</a>.</b>';
+ echo '</div>';
+ } else {
+ try {
+ $payment = $_offer->createPayment();
+ $payment->braintree_id = $trans->transaction->id;
+ echo '<div class="form-group alert alert-success">Thank you for your payment.</div>';
+ } catch (Exception $e) {
+ echo '<div class="form-group alert alert-warning">Your payment has been received, but could not be stored in our database. Please <a href="mailto:'.Constants::invoice_email.'">contact us</a>.</div>';
+ }
+ }
+ } else {
+ $subtotal = Constants::invoice_valuta . $_offer->calculate(Calculatable::SUBTOTAL);
+ $total = Constants::invoice_valuta . $_offer->calculate(Calculatable::TOTAL);
+ ?>
+ <div>
+ <div class='form-group alert alert-info'>Welcome to the checkout environment. Please review the invoice carefully.</div>
+ <table class="table table-bordered table-striped">
+ <tr style="border-bottom:2px solid #666;">
+ <th>Description</th>
+ <th>Price excl.</th>
+ <th>VAT</th>
+ <th>Price incl.</th>
+ </tr>
+ <?php
+ $i = 0;
+ foreach ($_offer->getItems() as $item) {
+ $i++;
+ echo '<tr>';
+ echo "<td class='col-max-width'>
+ <b><a href='#collapse-item-$i' data-toggle='collapse'>{$item->title}</a></b>
+ <div class='collapse' id='collapse-item-$i'>{$item->getHTMLDescription()}</div>
+ </td>";
+ echo "<td class='col-min-width'>".Constants::invoice_valuta."{$item->calculate(Calculatable::SUBTOTAL)}</td>";
+ echo "<td class='col-min-width'>{$item->VAT_percentage}%</td>";
+ echo "<td class='col-min-width'>".Constants::invoice_valuta."{$item->calculate(Calculatable::TOTAL)}</td>";
+ echo '</tr>';
+ }
+ ?>
+ <tr style="border-top:2px solid #666;">
+ <th colspan="3" class="text-right">Subtotal</th>
+ <td><?=$subtotal?></td>
+ </tr>
+ <tr>
+ <th colspan="3" class="text-right">Total</th>
+ <td><?=$total?></td>
+ </tr>
+ </table>
+ </div>
+ <form id="checkout" method="post" action="">
+ <div id="payment-form"></div>
+ <input type="submit" class="btn btn-success btn-lg pull-right" value="Pay <?=$total?>"/>
+ </form>
+ <?php
+ }
+ ?>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
+
+<script src="https://js.braintreegateway.com/js/braintree-2.27.0.min.js"></script>
+<script type="text/javascript">
+ var clientToken = "<?=Braintree_ClientToken::generate()?>";
+ braintree.setup(clientToken, "dropin", { container: "payment-form" });
+</script>
+
+<?php
+require('./footer.php');
+?>