From 4f84eb2b09bf51eabdc29b5eeec101e0260b1cb7 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 28 Jul 2016 09:37:48 +0200 Subject: Braintree integration: first version --- include/offers-overview.php | 5 ++++- include/offers.php | 34 ++++++++++++++++++++++++++++------ include/pay.php | 24 +++++++++++------------- 3 files changed, 43 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/include/offers-overview.php b/include/offers-overview.php index 1118793..6d9bbc1 100644 --- a/include/offers-overview.php +++ b/include/offers-overview.php @@ -95,7 +95,10 @@ require_once('./login.php'); - + + + + "; } diff --git a/include/offers.php b/include/offers.php index 2aa150d..8be7530 100644 --- a/include/offers.php +++ b/include/offers.php @@ -32,11 +32,12 @@ require('./header.php'); //------------------------------------------------------------------------------ // Check for GET variables // - // ?id= View information of the offer with id - // ?toggle_accept= Toggle the accepted status of the offer with id - // ?generate_invoice= Generate an invoice for the offer with id - // ?trash_invoice= Trash the invoice file - // ?delete= Delete the offer with id + // ?id= View information of the offer with id + // ?toggle_accept= Toggle the accepted status of the offer with id + // ?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 + // ?delete= Delete the offer with id //------------------------------------------------------------------------------ // The header of the page @@ -69,7 +70,7 @@ require('./header.php'); try { $offer = new Offer($_pdo, $id); $offer->accepted = !$offer->accepted; - echo "
The status offer #{$offer->id} has been set to ".($offer->accepted ? "accepted" : "unaccepted").".
"; + echo "
The status of offer #{$offer->id} has been set to ".($offer->accepted ? "accepted" : "unaccepted").".
"; } catch (PDOException $e) { echo "
The status of the offer could not be changed due to a PDO error.
"; } catch (Exception $e) { @@ -79,6 +80,27 @@ require('./header.php'); echo ""; } + // Toggle offer payment eligibility + if (isset($_GET['toggle_payment_eligibility'])) { + echo "
"; + $id = (int) $_GET['toggle_payment_eligibility']; + try { + $offer = new Offer($_pdo, $id); + if ($offer->getPaymentEligibility()) { + $offer->payment_key = null; + } else { + $offer->payment_key = Offer::getRandomPaymentKey(); + } + echo "
The offer #{$offer->id} is now ".($offer->getPaymentEligibility() ? "eligible" : "ineligible")." for online payment.
"; + } catch (PDOException $e) { + echo "
The online payment eligibility could not be changed due to a PDO error.
"; + } catch (Exception $e) { + echo "
The offer with id {$id} could not be found.
"; + } + + echo "
"; + } + // Generate invoice if (isset($_GET['generate_invoice'])) { echo "
"; diff --git a/include/pay.php b/include/pay.php index 596251c..37dd1cc 100644 --- a/include/pay.php +++ b/include/pay.php @@ -42,10 +42,10 @@ require('./header.php'); $notFound = true; } } - if ($notFound || $offerKey != $_offer->key) { - ?> -
The invoice could not be found.
- payment_key) { + echo "
The invoice could not be found.
"; + } elseif ($_offer->payment_key == '') { + echo "
This invoice is not eligible for online payment.
"; } elseif (isset($_POST['payment_method_nonce'])) { $nonce = $_POST['payment_method_nonce']; $trans = Braintree_Transaction::sale([ @@ -91,23 +91,21 @@ require('./header.php'); foreach ($_offer->getItems() as $item) { $i++; echo ''; - echo " + echo " {$item->title}
{$item->getHTMLDescription()}
"; - echo "".Constants::invoice_valuta."{$item->calculate(Calculatable::SUBTOTAL)}"; - echo "{$item->VAT_percentage}%"; - echo "".Constants::invoice_valuta."{$item->calculate(Calculatable::TOTAL)}"; + echo "".Constants::invoice_valuta."{$item->calculate(Calculatable::SUBTOTAL)}"; + echo "{$item->VAT_percentage}%"; + echo "".Constants::invoice_valuta."{$item->calculate(Calculatable::TOTAL)}"; echo ''; } ?> - Subtotal + Totals - - - Total - + +
-- cgit v1.2.3