File: /home/xedaptot/ai.naniguide.com/database/factories/PaymentIntentFactory.php
<?php
namespace Database\Factories;
use App\Model\Invoice;
use App\Model\PaymentGateway;
use App\Model\PaymentIntent;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class PaymentIntentFactory extends Factory
{
protected $model = PaymentIntent::class;
public function definition(): array
{
return [
'uid' => (string) Str::uuid(),
'invoice_id' => Invoice::factory(),
'payment_gateway_id' => PaymentGateway::factory(),
'amount' => 29.99,
'currency' => 'USD',
'description' => 'Pay invoice',
'status' => PaymentIntent::STATUS_PENDING,
'remote_reference_id' => null,
'metadata' => [],
'failed_reason' => null,
'succeeded_at' => null,
];
}
public function succeeded(): self
{
return $this->state(fn() => [
'status' => PaymentIntent::STATUS_SUCCEEDED,
'remote_reference_id' => 'pi_' . fake()->lexify('???????'),
'succeeded_at' => now(),
]);
}
public function requiresAction(): self
{
return $this->state(fn() => [
'status' => PaymentIntent::STATUS_REQUIRES_ACTION,
'remote_reference_id' => 'pi_' . fake()->lexify('???????'),
'metadata' => ['client_secret' => 'pi_secret_xxx'],
]);
}
public function failed(): self
{
return $this->state(fn() => [
'status' => PaymentIntent::STATUS_FAILED,
'failed_reason' => 'Your card was declined.',
]);
}
public function awaitingAdminApproval(): self
{
return $this->state(fn() => [
'status' => PaymentIntent::STATUS_AWAITING_ADMIN_APPROVAL,
'metadata' => ['claimed_at' => now()->toIso8601String()],
]);
}
public function forSubscription(string $remotePlanId = 'price_xyz'): self
{
return $this->state(fn() => [
'metadata' => ['remote_plan_id' => $remotePlanId],
]);
}
}