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 --- classes/Offer.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'classes/Offer.php') diff --git a/classes/Offer.php b/classes/Offer.php index 815f626..8fa9ba7 100644 --- a/classes/Offer.php +++ b/classes/Offer.php @@ -27,7 +27,7 @@ class Offer extends Model{ public $table = 'offer', - $fillable_columns = ['contactId', 'start_date', 'end_date', 'invoice_date', 'accepted', 'invoice_fileId']; + $fillable_columns = ['contactId', 'start_date', 'end_date', 'invoice_date', 'accepted', 'invoice_fileId', 'payment_key']; protected function accessor($key, $value) { switch ($key) { @@ -56,6 +56,25 @@ class Offer extends Model{ } } + /** + * A random max-63-char string that can be used as payment_key + * + * @return string The random string + */ + public static function getRandomPaymentKey() { + return preg_replace('/[^\w]+/', '', + base64_encode(openssl_random_pseudo_bytes(45))); + } + + /** + * Get whether the offer is eligible for online payment or not + * + * @return bool True iff it is eligible + */ + public function getPaymentEligibility() { + return $this->payment_key != ''; + } + /** * Get the contact that this offer is linked to * -- cgit v1.2.3