<?php namespace Bixo\Payment\Actions; use Illuminate\Support\Carbon; use Illuminate\Support\Str; use Litepie\Actions\Concerns\AsAction; use Bixo\Payment\Models\Refund; class RefundAction { use AsAction; protected $model; protected $namespace = 'bixo.payment.refund'; protected $eventClass = \Bixo\Payment\Events\RefundAction::class; protected $action; protected $function; protected $request; public function handle(string $action, Refund $refund, array $request = []) { $this->action = $action; $this->request = $request; $this->model = $refund; $this->function = Str::camel($action); $this->executeAction(); return $this->model; } public function store(Refund $refund, array $request) { $attributes = $request; $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $refund = $refund->create($attributes); return $refund; } public function update(Refund $refund, array $request) { $attributes = $request; $refund->update($attributes); return $refund; } public function destroy(Refund $refund, array $request) { $refund->delete(); return $refund; } public function copy(Refund $refund, array $request) { $count = $request['count'] ?: 1; if ($count == 1) { $refund = $refund->replicate(); $refund->created_at = Carbon::now(); $refund->save(); return $refund; } for ($i = 1; $i <= $count; $i++) { $new = $refund->replicate(); $new->created_at = Carbon::now(); $new->save(); } return $refund; } }