mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
50 lines
2.1 KiB
PHP
50 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
|
use App\Models\Transaction;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class GroupForOrderV2Resource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$payment_transaction = Transaction::where('payment_reference', $this->reference)->first();
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'original_amount' => (float) $this->original_amount,
|
|
'original_currency' => new CurrencyResource($this->original_currency),
|
|
'issuer_name' => $this->issuerCompany->name,
|
|
'issuer_id' => $this->issuerCompany->id,
|
|
'amount' => (float) $this->amount,
|
|
'service_charge' => (float) $this->amount,
|
|
'currency' => new CurrencyResource($this->currency),
|
|
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'),
|
|
'currency_rate' => (float) $this->currency_rate,
|
|
'status' => $this->status,
|
|
'status_name' => ApprovalStatus::APPROVAL_STATUS_ID[$this->status],
|
|
'payment_method' => (int)$this->payment_method,
|
|
'payment_method_name' => ucwords(PaymentMethodType::PAYMENT_METHODS_ID[$this->payment_method]),
|
|
'payment_reference' => $this->reference,
|
|
'transactions_ids' => GroupTransactionsForOrderV2Resource::collection($this->groupTransactions),
|
|
'payment_transaction' => $payment_transaction ? [
|
|
'id' => $payment_transaction->id,
|
|
'status' => $payment_transaction->status,
|
|
'status_name' => ApprovalStatus::APPROVAL_STATUS_ID[$payment_transaction->status],
|
|
'bill_no' => $payment_transaction->bill_no,
|
|
'updated_at' => Carbon::parse($payment_transaction->updated_at)->format('d-m-Y h:i:s A'),
|
|
] : null
|
|
];
|
|
}
|
|
}
|