From 3393995db8c3f191f064d2f0729b1af5fb889ee6 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 1 Aug 2016 08:04:48 +0200 Subject: Easier accessor/mutator in Model; refreshing braintree statuses --- include/offers.php | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) (limited to 'include/offers.php') 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= Toggle the payment eligibility of the offer with id // ?generate_invoice= Generate an invoice for the offer with id // ?trash_invoice= Trash the invoice file - // ?send_invoice= Send invoice to contact + // ?refesh_payment= Refresh the Braintree status of a payment // ?delete= Delete the offer with id //------------------------------------------------------------------------------ @@ -48,10 +48,8 @@ require('./header.php'); $offer = new Offer($_pdo, $id); $offer->accepted = !$offer->accepted; $alert = "
The status of offer #{$offer->id} has been set to ".($offer->accepted ? "accepted" : "unaccepted").".
"; - } catch (PDOException $e) { - $alert = "
The status of the offer could not be changed due to a PDO error.
"; } catch (Exception $e) { - $alert = "
The offer with id {$id} could not be found.
"; + $alert = "
The acceptance status of offer {$id} could not be changed: {$e->getMessage()}.
"; } } @@ -66,10 +64,8 @@ require('./header.php'); $offer->payment_key = Offer::getRandomPaymentKey(); } $alert = "
The offer #{$offer->id} is now ".($offer->getPaymentEligibility() ? "eligible" : "ineligible")." for online payment.
"; - } catch (PDOException $e) { - $alert = "
The online payment eligibility could not be changed due to a PDO error.
"; } catch (Exception $e) { - $alert = "
The offer with id {$id} could not be found.
"; + $alert = "
The payment eligibility of offer {$id} could not be changed: {$e->getMessage()}.
"; } } @@ -80,10 +76,8 @@ require('./header.php'); $offer = new Offer($_pdo, $id); $file = $offer->generateInvoice(); $alert = "
The invoice for offer #{$offer->id} is generated: {$file->filename}
"; - } catch (PDOException $e) { - $alert = "
The invoice for offer #{$offer->id} could not be generated due to a PDO error.
"; } catch (Exception $e) { - $alert = "
The invoice for offer #{$id} could not be generated.
"; + $alert = "
The invoice for offer #{$id} could not be generated: {$e->getMessage()}.
"; } } @@ -98,27 +92,20 @@ require('./header.php'); } else { $alert = "
The invoice for offer #{$id} could not be trashed.
"; } - } catch (PDOException $e) { - $alert = "
The invoice for offer #{$offer->id} could not be trashed due to a PDO error.
"; } catch (Exception $e) { - $alert = "
The invoice for offer #{$id} could not be trashed.
"; + $alert = "
The invoice for offer #{$id} could not be trashed: {$e->getMessage()}.
"; } } - // 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 = "
The invoice for offer {$id} has been sent to {$offer->getContact()->email}.
"; - } else { - $alert = "
The invoice could not be sent due to an unknown error.
"; - } - } catch (PDOException $e) { - $alert = "
The invoice could not be sent due to a PDO error.
"; + $payment = new Payment($_pdo, $id); + $payment->refreshBraintreeStatus(); + $alert = "
The payment's status has been updated to {$payment->braintree_status}.
"; } catch (Exception $e) { - $alert = "
The offer with id {$id} could not be found.
"; + $alert = "
The payment could not be refreshed due to an exception: {$e->getMessage()}.
"; } } @@ -132,10 +119,8 @@ require('./header.php'); } else { $alert = "
The offer #{$offer->id} could not be removed. Perhaps it's already removed?
"; } - } catch (PDOException $e) { - $alert = "
The offer could not be removed due to a PDO error.
"; } catch (Exception $e) { - $alert = "
The offer with id {$id} could not be found.
"; + $alert = "
The offer with id {$id} could not be deleted: {$e->getMessage()}.
"; } } -- cgit v1.2.3