'object'
];
protected $hidden = ['detail'];
public function user()
{
return $this->belongsTo(User::class);
}
public function gateway()
{
return $this->belongsTo(Gateway::class, 'method_code', 'code');
}
public function methodName(){
if ($this->method_code < 5000) {
$methodName = @$this->gatewayCurrency()->name;
}else{
$methodName = 'Google Pay';
}
return $methodName;
}
public function scopeSuccess($query)
{
return $query->where('status', Status::PAYMENT_SUCCESS);
}
public function statusBadge(): Attribute
{
return new Attribute(function(){
$html = '';
if($this->status == Status::PAYMENT_PENDING){
$html = ''.trans('Pending').'';
}
elseif($this->status == Status::PAYMENT_SUCCESS && $this->method_code >= 1000 && $this->method_code <= 5000){
$html = ''.trans('Approved').'
'.diffForHumans($this->updated_at).'';
}
elseif($this->status == Status::PAYMENT_SUCCESS && ($this->method_code < 1000 || $this->method_code >= 5000)){
$html = ''.trans('Succeed').'';
}
elseif($this->status == Status::PAYMENT_REJECT){
$html = ''.trans('Rejected').'
'.diffForHumans($this->updated_at).'';
}else{
$html = ''.trans('Initiated').'';
}
return $html;
});
}
// scope
public function gatewayCurrency()
{
return GatewayCurrency::where('method_code', $this->method_code)->where('currency', $this->method_currency)->first();
}
public function baseCurrency()
{
return @$this->gateway->crypto == Status::ENABLE ? 'USD' : $this->method_currency;
}
public function scopePending($query)
{
return $query->where('method_code','>=',1000)->where('status', Status::PAYMENT_PENDING);
}
public function scopeRejected($query)
{
return $query->where('method_code','>=',1000)->where('status', Status::PAYMENT_REJECT);
}
public function scopeApproved($query)
{
return $query->where('method_code','>=',1000)->where('method_code','<',5000)->where('status', Status::PAYMENT_SUCCESS);
}
public function scopeSuccessful($query)
{
return $query->where('status', Status::PAYMENT_SUCCESS);
}
public function scopeInitiated($query)
{
return $query->where('status', Status::PAYMENT_INITIATE);
}
public function order()
{
return $this->belongsTo(Order::class);
}
}