File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/Payment/Transaction.php
<?php
namespace App\Payment;
use App\Orders\Models\Order;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Mollie\Api\Types\PaymentStatus;
/**
* App\Payment\Transaction
*
* @property int $id
* @property int $order_id
* @property string $psp The name of the psp that was being used in the transaction. The same value as the payment_service_provider option in the payment config
* @property string|null $psp_payment_reference A reference from the psp identifying the transaction. In dutch: betalingskenmerk
* @property string $psp_id An id of the transaction at the PSP side
* @property int $amount Amount in cents. Should match order total
* @property string|null $currency_iso_4217_code Examples: EUR, USD, GBP
* @property string $status
* @property string|null $issuer_id An id of an issuer. Example: RABONL2U
* @property string|null $payment_method Example: IDEAL, Paypal, Bank Transfer NL
* @property string|null $account_reference Example: NLRABO0123456789 (iBAN)
* @property string|null $account_holder_name Example: A. Einstein
* @property string|null $acccount_brand Example: IDEAL, Paypal, Bank Transfer NL
* @property string|null $payment_link Example: www.examplepsp.org/payment/24584612. Url where user can pay this transaction
* @property string $ip The ip address of the one who payed the order
* @property string|null $error_code An error code supplied by the payment service provider
* @property \Illuminate\Support\Carbon|null $expire_date The date when the payment expires
* @property \Illuminate\Support\Carbon|null $payment_date When the payment was completed
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read Order $order
* @method static \Illuminate\Database\Eloquent\Builder|Transaction newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Transaction newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Transaction query()
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereAcccountBrand($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereAccountHolderName($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereAccountReference($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereAmount($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereCurrencyIso4217Code($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereErrorCode($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereExpireDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereIp($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereIssuerId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereOrderId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction wherePaymentDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction wherePaymentLink($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction wherePaymentMethod($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction wherePsp($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction wherePspId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction wherePspPaymentReference($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Transaction extends Model
{
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['payment_date', 'expire_date'];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'order_id',
'amount',
'psp_payment_reference',
'psp',
'psp_id',
'ip',
'currency_iso_4217_code',
'error_code',
'account_reference',
'account_holder_name',
'acccount_brand',
'issuer_id',
'payment_method',
'status',
'payment_link',
'expire_date',
'payment_date',
];
protected $table = 'order_transactions';
/**
* Returns the order this transaction belongs to
*
* @return BelongsTo
*/
public function order(): BelongsTo
{
return $this->belongsTo(Order::class);
}
/**
* Returns a status name for css that eventually will determine the color when this transaction is displayed.
*
* @return string
*/
public function statusColor(): string {
switch ($this->status) {
case TransactionStatus::EXPIRED:
case TransactionStatus::CANCELED:
case TransactionStatus::CANCELED_CUSTOMER:
case TransactionStatus::AUTHORISATION_REJECTED:
case TransactionStatus::AUTHORISATION_UNKNOWN:
case TransactionStatus::PAYMENT_UNKNOWN:
return 'negative';
case TransactionStatus::REFUNDED:
case TransactionStatus::CHARGEDBACK:
case TransactionStatus::PAYMENT_PAID:
return 'positive';
case TransactionStatus::AUTHORIZED:
case TransactionStatus::REFUND_PENDING:
case TransactionStatus::CANCEL_PENDING:
case TransactionStatus::PAYMENT_PENDING:
case TransactionStatus::CHARGEBACK_PENDING:
case TransactionStatus::AUTHORISATION_PENDING:
case TransactionStatus::REDIRECTED_USER_TO_PSP:
return 'pending';
case TransactionStatus::OPEN:
default:
return 'default';
}
}
}