aboutsummaryrefslogtreecommitdiff
path: root/include/offers.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/offers.php')
-rw-r--r--include/offers.php41
1 files changed, 13 insertions, 28 deletions
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>";
}
}