blob: 37dd1cc00821600dc94e60fde40285ea819608d3 (
plain) (
blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
<?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->payment_key) {
echo "<div class='form-group alert alert-danger'>The invoice could not be found.</div>";
} elseif ($_offer->payment_key == '') {
echo "<div class='form-group alert alert-danger'>This invoice is not eligible for online payment.</div>";
} 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>
<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>".Constants::invoice_valuta."{$item->calculate(Calculatable::SUBTOTAL)}</td>";
echo "<td>{$item->VAT_percentage}%</td>";
echo "<td>".Constants::invoice_valuta."{$item->calculate(Calculatable::TOTAL)}</td>";
echo '</tr>';
}
?>
<tr style="border-top:2px solid #666;">
<th class="text-right">Totals</th>
<td><?=$subtotal?></td>
<td></td>
<td><b><?=$total?></b></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');
?>
|