| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Models; |
| 4 |
|
| 5 |
class Transaction extends Model |
| 6 |
{ |
| 7 |
/** |
| 8 |
* The table associated with the model. |
| 9 |
* |
| 10 |
* @var string |
| 11 |
*/ |
| 12 |
protected $table = 'fluentform_transactions'; |
| 13 |
|
| 14 |
/** |
| 15 |
* A transaction belongs to a form. |
| 16 |
* |
| 17 |
* @return \FluentForm\Framework\Database\Orm\Relations\BelongsTo |
| 18 |
*/ |
| 19 |
public function form() |
| 20 |
{ |
| 21 |
return $this->belongsTo(Form::class, 'form_id', 'id'); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* A transaction belongs to a submission. |
| 26 |
* |
| 27 |
* @return \FluentForm\Framework\Database\Orm\Relations\BelongsTo |
| 28 |
*/ |
| 29 |
public function submission() |
| 30 |
{ |
| 31 |
return $this->belongsTo(Submission::class, 'submission_id', 'id'); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* A transaction may belong to a subscription. |
| 36 |
* |
| 37 |
* @return \FluentForm\Framework\Database\Orm\Relations\BelongsTo |
| 38 |
*/ |
| 39 |
public function subscription() |
| 40 |
{ |
| 41 |
return $this->belongsTo(Subscription::class, 'subscription_id', 'id'); |
| 42 |
} |
| 43 |
|
| 44 |
public function scopeBySubmission($query, $submissionId) |
| 45 |
{ |
| 46 |
return $query->where('submission_id', $submissionId); |
| 47 |
} |
| 48 |
|
| 49 |
public function scopeByChargeId($query, $chargeId) |
| 50 |
{ |
| 51 |
return $query->where('charge_id', $chargeId); |
| 52 |
} |
| 53 |
|
| 54 |
public function scopeOnetime($query) |
| 55 |
{ |
| 56 |
return $query->where('transaction_type', 'onetime'); |
| 57 |
} |
| 58 |
|
| 59 |
public function scopeRefunds($query) |
| 60 |
{ |
| 61 |
return $query->where('transaction_type', 'refund'); |
| 62 |
} |
| 63 |
|
| 64 |
public function scopeSubscriptionType($query) |
| 65 |
{ |
| 66 |
return $query->where('transaction_type', 'subscription'); |
| 67 |
} |
| 68 |
|
| 69 |
public function scopePaid($query) |
| 70 |
{ |
| 71 |
return $query->whereIn('status', [ |
| 72 |
'paid', 'requires_capture', 'processing', 'partially-refunded', 'refunded' |
| 73 |
]); |
| 74 |
} |
| 75 |
} |
| 76 |
|