. */ /** * An interface to the payment table in the database */ class Payment extends Model { /** {@inheritDoc} */ public $table = 'payment', $fillable_columns = ['offerId', 'date', 'braintree_id']; /** * Get the offer that this payment is linked to * * @return offer The offer */ public function getOffer() { return new Offer($this->pdo, $this->offerId); } /** * {@inheritDoc} * @param $key {@inheritDoc} * @param $value {@inheritDoc} */ protected function accessor($key, $value) { switch ($key) { case 'date': return strtotime($value); break; default: return parent::accessor($key, $value); } } /** * {@inheritDoc} * @param $key {@inheritDoc} * @param $value {@inheritDoc} */ protected function mutator($key, $value) { switch ($key) { case 'date': return is_string($value) ? $value : date('Y-m-d H:i:s', $value); break; default: 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(); } }