diff options
author | Camil Staps | 2016-07-28 09:37:48 +0200 |
---|---|---|
committer | Camil Staps | 2016-07-28 09:47:04 +0200 |
commit | 4f84eb2b09bf51eabdc29b5eeec101e0260b1cb7 (patch) | |
tree | 82722787d4018373720c66933f475bb2b1708c92 /classes | |
parent | Split Calculatable in trait and interface (diff) |
Braintree integration: first version
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Assignment.php | 8 | ||||
-rw-r--r-- | classes/Constants.php | 2 | ||||
-rw-r--r-- | classes/Discount.php | 8 | ||||
-rw-r--r-- | classes/Offer.php | 21 | ||||
-rw-r--r-- | classes/Payment.php | 2 |
5 files changed, 30 insertions, 11 deletions
diff --git a/classes/Assignment.php b/classes/Assignment.php index 27efb4a..2ceef94 100644 --- a/classes/Assignment.php +++ b/classes/Assignment.php @@ -24,8 +24,8 @@ /** * An interface to the assignment table in the database */ -class Assignment extends Model { - use Calculatable; +class Assignment extends Model implements Calculatable { + use StandardCalculatable; public $table = 'assignment', @@ -50,11 +50,11 @@ class Assignment extends Model { return $pd->text($this->description); } - protected function calculateSubtotal() { + public function calculateSubtotal() { return $this->hours * $this->price_per_hour; } - protected function calculateVAT() { + public function calculateVAT() { return $this->calculateSubtotal() * $this->VAT_percentage / 100; } } diff --git a/classes/Constants.php b/classes/Constants.php index 3ffadd7..fb2435d 100644 --- a/classes/Constants.php +++ b/classes/Constants.php @@ -80,5 +80,5 @@ class Constants { const password_cost = 10; /** @const version Version of BusinessAdmin. Don't change this yourself! */ - const version = '0.4.2'; + const version = '0.5'; } diff --git a/classes/Discount.php b/classes/Discount.php index 7216615..4084d43 100644 --- a/classes/Discount.php +++ b/classes/Discount.php @@ -24,8 +24,8 @@ /** * An interface to the discount table in the database */ -class Discount extends Model { - use Calculatable; +class Discount extends Model implements Calculatable { + use StandardCalculatable; public $table = 'discount', @@ -50,11 +50,11 @@ class Discount extends Model { return $pd->text($this->description); } - protected function calculateSubtotal() { + public function calculateSubtotal() { return - $this->value; } - protected function calculateVAT() { + public function calculateVAT() { return $this->calculateSubtotal() * $this->VAT_percentage / 100; } } 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 diff --git a/classes/Payment.php b/classes/Payment.php index e60539f..5bc08dc 100644 --- a/classes/Payment.php +++ b/classes/Payment.php @@ -27,7 +27,7 @@ class Payment extends Model { public $table = 'payment', - $fillable_columns = ['offerId', 'date']; + $fillable_columns = ['offerId', 'date', 'braintree_id']; /** * Get the offer that this payment is linked to |