From 3f28c67f9372387f3a5bc45d5352499d6f919afc Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 1 Aug 2016 00:08:05 +0200 Subject: Payment confirmation --- classes/Correspondence.php | 3 +++ classes/Payment.php | 24 ++++++++++++++++++++++++ include/pay.php | 10 +++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/classes/Correspondence.php b/classes/Correspondence.php index 80c4c87..e2a0771 100644 --- a/classes/Correspondence.php +++ b/classes/Correspondence.php @@ -109,6 +109,9 @@ class Correspondence extends FPDF { 'mail-offer' => [ 'en' => "Dear {{getContact-name}},\r\n\r\nPlease find attached your invoice. You can either pay by bank transfer, as indicated on the invoice, or using Paypal or a credit card on {{getPaymentUrl}}.\r\n\r\nThank you in advance,\r\n\r\n{{{invoice_name}}}", 'nl' => "Beste {{getContact-name}},\r\n\r\nBijgevoegd vindt u uw factuur. U kunt per bankoverschrijving betalen, zoals aangegeven op de factuur, of met Paypal of een credit card op {{getPaymentUrl}}.\r\n\r\nAlvast hartelijk dank,\r\n\r\n{{{invoice_name}}}"], + 'mail-offer-paid' => [ + 'en' => "Dear {{getOffer-getContact-name}},\r\n\r\nYour invoice at {{getOffer-getPaymentUrl}} has been paid.\r\n\r\nThank you,\r\n\r\n{{{invoice_name}}}", + 'nl' => "Beste {{getOffer-getContact-name}},\r\n\r\nUw factuur op {{getOffer-getPaymentUrl}} is betaald.\r\n\r\nHartelijk dank,\r\n\r\n{{{invoice_name}}}"], ]; /** @var $page_height The height of a page in millimeters */ diff --git a/classes/Payment.php b/classes/Payment.php index 4b8c12b..64b65ae 100644 --- a/classes/Payment.php +++ b/classes/Payment.php @@ -68,4 +68,28 @@ class Payment extends Model { return parent::mutator($key, $value); } } + + /** + * Make a mailer to send about this payment + * + * @return Mailer The mailer + */ + public function mailer() { + $mailer = new Mailer($this->pdo); + $mailer->setOffer($this->getOffer()); + + $mailer->Subject = 'Your invoice has been paid'; + $mailer->Body = Correspondence::__r('mail-offer-paid', $this->getOffer()->getContact()->language, $this); + + return $mailer; + } + + /** + * Send the payment notification to the offer's contact + * + * @return bool The result of Mailer::send + */ + public function send() { + return $this->mailer()->send(); + } } diff --git a/include/pay.php b/include/pay.php index 37dd1cc..69626ea 100644 --- a/include/pay.php +++ b/include/pay.php @@ -44,8 +44,10 @@ require('./header.php'); } if ($notFound || $offerKey != $_offer->payment_key) { echo "
The invoice could not be found.
"; - } elseif ($_offer->payment_key == '') { + } elseif (!$_offer->getPaymentEligibility()) { echo "
This invoice is not eligible for online payment.
"; + } elseif ($_offer->getPayment() != null) { + echo "
This invoice has already been paid.
"; } elseif (isset($_POST['payment_method_nonce'])) { $nonce = $_POST['payment_method_nonce']; $trans = Braintree_Transaction::sale([ @@ -62,13 +64,14 @@ require('./header.php'); foreach ($trans->errors->deepAll() as $error) { echo "{$error->attribute}: {$error->code} {$error->message}
"; } - echo 'Please try again, or contact us.'; + echo 'Please try again, or contact us.'; echo ''; } else { try { $payment = $_offer->createPayment(); $payment->braintree_id = $trans->transaction->id; - echo '
Thank you for your payment.
'; + $payment->send(); + echo '
Thank you for your payment. A confirmation has been sent to '.$_offer->getContact()->email.'.
'; } catch (Exception $e) { echo '
Your payment has been received, but could not be stored in our database. Please contact us.
'; } @@ -111,6 +114,7 @@ require('./header.php');
+
A confirmation will be sent to getContact()->email?>.