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-view.php | 40 ++++++++++++++++++++++++++++++++++++++-- include/offers.php | 41 +++++++++++++---------------------------- 2 files changed, 51 insertions(+), 30 deletions(-) (limited to 'include') 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); "; } if (count($assignments) == 0) { - echo "There are no assignments in the database. Why not start with creating one, below?"; + echo "There are no assignments in the database. Why not start with creating one, below?"; } ?> @@ -99,7 +99,7 @@ $_offer = new Offer($_pdo, $_id); "; } if (count($discounts) == 0) { - echo "There are no discounts in the database. Why not start with creating one, below?"; + echo "There are no discounts in the database. Why not start with creating one, below?"; } ?> @@ -108,6 +108,42 @@ $_offer = new Offer($_pdo, $_id);
+
+
Payments
+
+ + + + + + + + + + + getPayment(); + $payments = [$payment]; + foreach ($payments as $payment) { + echo " + + + + + "; + } + if (count($payments) == 0) { + echo ""; + } + ?> + +
#Braintree IDBraintree statusTools
{$payment->id}{$payment->braintree_id}{$payment->braintree_status} + +
There are no payments in the database. Why not start with creating one, below?
+
+
+
+
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= 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