aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2016-08-01 00:08:05 +0200
committerCamil Staps2016-08-01 00:08:05 +0200
commit3f28c67f9372387f3a5bc45d5352499d6f919afc (patch)
tree75f359a414b8f60236925cd6da3932dd582db256
parentEasier emails (diff)
Payment confirmation
-rw-r--r--classes/Correspondence.php3
-rw-r--r--classes/Payment.php24
-rw-r--r--include/pay.php10
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 "<div class='form-group alert alert-danger'>The invoice could not be found.</div>";
- } elseif ($_offer->payment_key == '') {
+ } elseif (!$_offer->getPaymentEligibility()) {
echo "<div class='form-group alert alert-danger'>This invoice is not eligible for online payment.</div>";
+ } elseif ($_offer->getPayment() != null) {
+ echo "<div class='form-group alert alert-info'>This invoice has already been paid.</div>";
} 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}<br/>";
}
- echo '<b>Please try again, or <a href="mailto:'.Constants::invoice_email.'">contact us</a>.</b>';
+ echo '<b>Please <a href="?id='.$_offer->id.'&key='.$_offer->payment_key.'">try again</a>, or <a href="mailto:'.Constants::invoice_email.'">contact us</a>.</b>';
echo '</div>';
} else {
try {
$payment = $_offer->createPayment();
$payment->braintree_id = $trans->transaction->id;
- echo '<div class="form-group alert alert-success">Thank you for your payment.</div>';
+ $payment->send();
+ echo '<div class="form-group alert alert-success">Thank you for your payment. A confirmation has been sent to <b>'.$_offer->getContact()->email.'</b>.</div>';
} catch (Exception $e) {
echo '<div class="form-group alert alert-warning">Your payment has been received, but could not be stored in our database. Please <a href="mailto:'.Constants::invoice_email.'">contact us</a>.</div>';
}
@@ -111,6 +114,7 @@ require('./header.php');
</div>
<form id="checkout" method="post" action="">
<div id="payment-form"></div>
+ <div class='form-group alert alert-info' style='margin-top:1em;'>A confirmation will be sent to <b><?=$_offer->getContact()->email?></b>.</div>
<input type="submit" class="btn btn-success btn-lg pull-right" value="Pay <?=$total?>"/>
</form>
<?php