aboutsummaryrefslogtreecommitdiff
path: root/classes/Payment.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/Payment.php')
-rw-r--r--classes/Payment.php91
1 files changed, 60 insertions, 31 deletions
diff --git a/classes/Payment.php b/classes/Payment.php
index 64b65ae..bab55be 100644
--- a/classes/Payment.php
+++ b/classes/Payment.php
@@ -28,7 +28,8 @@ class Payment extends Model {
/** {@inheritDoc} */
public
$table = 'payment',
- $fillable_columns = ['offerId', 'date', 'braintree_id'];
+ $fillable_columns = ['offerId', 'date', 'braintree_id', 'braintree_status'],
+ $timestamps = ['date'];
/**
* Get the offer that this payment is linked to
@@ -40,36 +41,6 @@ class Payment extends Model {
}
/**
- * {@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
@@ -92,4 +63,62 @@ class Payment extends Model {
public function send() {
return $this->mailer()->send();
}
+
+ /**
+ * Refresh the Braintree status
+ *
+ * @return string|null The new status, or null if this Payment does not have a Braintree id
+ */
+ public function refreshBraintreeStatus() {
+ if (is_null($this->braintree_id)) {
+ return null;
+ }
+
+ $trans = Braintree_Transaction::find($this->braintree_id);
+ $this->braintree_status = $trans->status;
+ }
+
+ /**
+ * Is the Braintree transaction finished?
+ *
+ * @return bool|null True iff the Braintree transaction is finished, or null if this Payment does not have a Braintree id
+ */
+ public function isBraintreeFinished() {
+ if (is_null($this->braintree_id)) {
+ return null;
+ }
+
+ return in_array($this->braintree_status, [
+ Braintree_Transaction::AUTHORIZATION_EXPIRED,
+ Braintree_Transaction::GATEWAY_REJECTED,
+ Braintree_Transaction::FAILED,
+ Braintree_Transaction::PROCESSOR_DECLINED,
+ Braintree_Transaction::SETTLED,
+ Braintree_Transaction::VOIDED,
+ Braintree_Transaction::SETTLEMENT_DECLINED,
+ ]);
+ }
+
+ /**
+ * Is the Braintree transaction successful?
+ *
+ * A transaction can be successful if it is not yet finished.
+ *
+ * @return bool|null True iff the Braintree transaction is successful, or null if this Payment does not have a Braintree id
+ */
+ public function isBraintreeSuccessful() {
+ if (is_null($this->braintree_id)) {
+ return null;
+ }
+
+ return in_array($this->braintree_status, [
+ Braintree_Transaction::AUTHORIZING,
+ Braintree_Transaction::AUTHORIZED,
+ Braintree_Transaction::SETTLED,
+ Braintree_Transaction::SETTLING,
+ Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT,
+ Braintree_Transaction::SETTLEMENT_PENDING,
+ Braintree_Transaction::SETTLEMENT_CONFIRMED,
+ ]);
+ }
}