1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Models/PaymentHash.php

91 lines
2.3 KiB
PHP
Raw Normal View History

2020-08-25 15:06:38 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2020-08-25 15:06:38 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2020-08-25 15:06:38 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2020-08-25 15:06:38 +02:00
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
2023-03-08 08:33:42 +01:00
/**
* App\Models\PaymentHash
*
* @property int $id
2023-08-19 04:23:37 +02:00
* @property string $hash 32 char length AlphaNum
2023-08-08 10:56:31 +02:00
* @property float $fee_total
2023-03-08 08:33:42 +01:00
* @property int|null $fee_invoice_id
2023-08-15 16:23:18 +02:00
* @property \stdClass $data
2023-03-08 08:33:42 +01:00
* @property int|null $payment_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\Invoice|null $fee_invoice
* @property-read \App\Models\Payment|null $payment
* @method static \Illuminate\Database\Eloquent\Builder|PaymentHash newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|PaymentHash query()
* @mixin \Eloquent
*/
2020-08-25 15:06:38 +02:00
class PaymentHash extends Model
{
protected $guarded = ['id'];
2020-08-30 14:00:19 +02:00
2020-08-25 15:06:38 +02:00
protected $casts = [
'data' => 'object',
2020-08-25 15:06:38 +02:00
];
2023-10-26 04:57:44 +02:00
/**
* @class \App\Models\PaymentHash $this
* @property \App\Models\PaymentHash $data
* @property \App\Modes\PaymentHash $hash 32 char length AlphaNum
* @class \stdClass $data
* @property string $raw_value
*/
2023-08-15 16:23:18 +02:00
2023-08-07 06:50:08 +02:00
/**
2023-08-15 14:47:54 +02:00
* @return mixed
2023-08-07 06:50:08 +02:00
*/
2020-08-25 15:06:38 +02:00
public function invoices()
{
2020-10-22 15:24:18 +02:00
return $this->data->invoices;
2020-08-25 15:06:38 +02:00
}
2024-01-14 05:05:00 +01:00
2023-08-07 06:50:08 +02:00
/**
* @return float|null
*/
public function amount_with_fee()
{
return $this->data->amount_with_fee;
}
2020-10-13 14:28:30 +02:00
2023-08-07 06:50:08 +02:00
/**
* @return float
*/
2021-01-06 06:54:04 +01:00
public function credits_total()
{
return isset($this->data->credits) ? $this->data->credits : 0;
}
2023-08-07 06:50:08 +02:00
public function payment(): \Illuminate\Database\Eloquent\Relations\BelongsTo
2020-10-13 14:28:30 +02:00
{
return $this->belongsTo(Payment::class)->withTrashed();
}
2023-08-07 06:50:08 +02:00
public function fee_invoice(): \Illuminate\Database\Eloquent\Relations\BelongsTo
2020-10-13 14:28:30 +02:00
{
2022-03-04 23:21:17 +01:00
return $this->belongsTo(Invoice::class, 'fee_invoice_id', 'id')->withTrashed();
2020-10-13 14:28:30 +02:00
}
2021-07-26 17:03:28 +02:00
2021-07-29 15:13:38 +02:00
public function withData(string $property, $value): self
2021-07-26 17:03:28 +02:00
{
2023-08-15 16:23:18 +02:00
$this->data = array_merge((array) $this->data, [$property => $value]); // @phpstan-ignore-line
$this->save();// @phpstan-ignore-line
return $this; // @phpstan-ignore-line
2021-07-26 17:03:28 +02:00
}
2020-08-25 15:06:38 +02:00
}