38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class PaymentTransactionResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
$data = [
|
|
'uuid' => $this->uuid,
|
|
'provider' => $this->provider,
|
|
'provider_payment_id' => $this->provider_payment_id,
|
|
'amount' => (float) $this->amount,
|
|
'currency' => $this->currency,
|
|
'status' => $this->status,
|
|
'return_url' => $this->return_url,
|
|
'created_at' => $this->created_at?->toIso8601String(),
|
|
];
|
|
|
|
if ($this->provider === 'stripe' && is_array($this->raw_payload)) {
|
|
$clientSecret = $this->raw_payload['client_secret'] ?? null;
|
|
|
|
if (is_string($clientSecret) && $clientSecret !== '') {
|
|
$data['stripe'] = [
|
|
'payment_intent_id' => $this->provider_payment_id,
|
|
'client_secret' => $clientSecret,
|
|
'publishable_key' => config('services.stripe.key'),
|
|
];
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|