diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/offers-view.php | 40 | ||||
-rw-r--r-- | include/offers.php | 41 |
2 files changed, 51 insertions, 30 deletions
diff --git a/include/offers-view.php b/include/offers-view.php index ec579b6..1455e43 100644 --- a/include/offers-view.php +++ b/include/offers-view.php @@ -57,7 +57,7 @@ $_offer = new Offer($_pdo, $_id); </tr>"; } if (count($assignments) == 0) { - echo "<tr><td colspan='6'>There are no assignments in the database. Why not start with creating one, below?</td></tr>"; + echo "<tr><td colspan='5'>There are no assignments in the database. Why not start with creating one, below?</td></tr>"; } ?> </tbody> @@ -99,7 +99,7 @@ $_offer = new Offer($_pdo, $_id); </tr>"; } if (count($discounts) == 0) { - echo "<tr><td colspan='6'>There are no discounts in the database. Why not start with creating one, below?</td></tr>"; + echo "<tr><td colspan='4'>There are no discounts in the database. Why not start with creating one, below?</td></tr>"; } ?> </tbody> @@ -108,6 +108,42 @@ $_offer = new Offer($_pdo, $_id); </div> </div> <div class="col-md-6"> + <div class="panel panel-default"> + <div class="panel-heading">Payments</div> + <div class="panel-body table-responsive"> + <table class="table table-bordered table-striped"> + <thead> + <tr> + <th>#</th> + <th>Braintree ID</th> + <th>Braintree status</th> + <th>Tools</th> + </tr> + </thead> + <tbody> + <?php + $payment = $_offer->getPayment(); + $payments = [$payment]; + foreach ($payments as $payment) { + echo "<tr> + <td>{$payment->id}</td> + <td>{$payment->braintree_id}</td> + <td>{$payment->braintree_status}</td> + <td class='col-min-width'> + <a title='Refresh' href='?id={$_offer->id}&refresh_payment={$payment->id}' class='btn btn-info btn-circle fa fa-refresh'></a> + </td> + </tr>"; + } + if (count($payments) == 0) { + echo "<tr><td colspan='4'>There are no payments in the database. Why not start with creating one, below?</td></tr>"; + } + ?> + </tbody> + </table> + </div> + </div> +</div> +<div class="col-lg-12"> <div class="panel panel-default" id="panel-timeline"> <div class="panel-heading"> <i class="fa fa-clock-o fa-fw"></i> Timeline diff --git a/include/offers.php b/include/offers.php index e06a4eb..165d88f 100644 --- a/include/offers.php +++ b/include/offers.php @@ -37,7 +37,7 @@ require('./header.php'); // ?toggle_payment_eligibility=<id> Toggle the payment eligibility of the offer with id <id> // ?generate_invoice=<id> Generate an invoice for the offer with id <id> // ?trash_invoice=<id> Trash the invoice file - // ?send_invoice=<id> Send invoice to contact + // ?refesh_payment=<id> Refresh the Braintree status of a payment // ?delete=<id> Delete the offer with id <id> //------------------------------------------------------------------------------ @@ -48,10 +48,8 @@ require('./header.php'); $offer = new Offer($_pdo, $id); $offer->accepted = !$offer->accepted; $alert = "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The status of offer #{$offer->id} has been set to <i>".($offer->accepted ? "accepted" : "unaccepted")."</i>.</div>"; - } catch (PDOException $e) { - $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The status of the offer could not be changed due to a PDO error.</div>"; } catch (Exception $e) { - $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id {$id} could not be found.</div>"; + $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The acceptance status of offer {$id} could not be changed: {$e->getMessage()}.</div>"; } } @@ -66,10 +64,8 @@ require('./header.php'); $offer->payment_key = Offer::getRandomPaymentKey(); } $alert = "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer #{$offer->id} is now <i>".($offer->getPaymentEligibility() ? "eligible" : "ineligible")."</i> for online payment.</div>"; - } catch (PDOException $e) { - $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The online payment eligibility could not be changed due to a PDO error.</div>"; } catch (Exception $e) { - $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id {$id} could not be found.</div>"; + $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The payment eligibility of offer {$id} could not be changed: {$e->getMessage()}.</div>"; } } @@ -80,10 +76,8 @@ require('./header.php'); $offer = new Offer($_pdo, $id); $file = $offer->generateInvoice(); $alert = "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} is generated: <a class='alert-link' href='{$file->getFilenameURI()}' target='_blank'>{$file->filename}</a></div>"; - } catch (PDOException $e) { - $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} could not be generated due to a PDO error.</div>"; } catch (Exception $e) { - $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be generated.</div>"; + $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be generated: {$e->getMessage()}.</div>"; } } @@ -98,27 +92,20 @@ require('./header.php'); } else { $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be trashed.</div>"; } - } catch (PDOException $e) { - $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} could not be trashed due to a PDO error.</div>"; } catch (Exception $e) { - $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be trashed.</div>"; + $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be trashed: {$e->getMessage()}.</div>"; } } - // Send invoice - if (isset($_GET['send_invoice'])) { - $id = (int) $_GET['send_invoice']; + // Refresh payment + if (isset($_GET['refresh_payment'])) { + $id = (int) $_GET['refresh_payment']; try { - $offer = new Offer($_pdo, $id); - if ($offer->send()) { - $alert = "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer {$id} has been sent to {$offer->getContact()->email}.</div>"; - } else { - $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice could not be sent due to an unknown error.</div>"; - } - } catch (PDOException $e) { - $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice could not be sent due to a PDO error.</div>"; + $payment = new Payment($_pdo, $id); + $payment->refreshBraintreeStatus(); + $alert = "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The payment's status has been updated to <b>{$payment->braintree_status}</b>.</div>"; } catch (Exception $e) { - $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id {$id} could not be found.</div>"; + $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The payment could not be refreshed due to an exception: {$e->getMessage()}.</div>"; } } @@ -132,10 +119,8 @@ require('./header.php'); } else { $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer #{$offer->id} could not be removed. Perhaps it's already removed?</div>"; } - } catch (PDOException $e) { - $alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer could not be removed due to a PDO error.</div>"; } catch (Exception $e) { - $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id {$id} could not be found.</div>"; + $alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id {$id} could not be deleted: {$e->getMessage()}.</div>"; } } |