aboutsummaryrefslogtreecommitdiff
path: root/classes/Offer.php
diff options
context:
space:
mode:
authorCamil Staps2016-07-28 09:37:48 +0200
committerCamil Staps2016-07-28 09:47:04 +0200
commit4f84eb2b09bf51eabdc29b5eeec101e0260b1cb7 (patch)
tree82722787d4018373720c66933f475bb2b1708c92 /classes/Offer.php
parentSplit Calculatable in trait and interface (diff)
Braintree integration: first version
Diffstat (limited to 'classes/Offer.php')
-rw-r--r--classes/Offer.php21
1 files changed, 20 insertions, 1 deletions
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) {
@@ -57,6 +57,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
*
* @return contact The contact