File: /home/xedaptot/be.naniguide.com/tests/Unit/Cashier/DTO/PaymentIntentDtoTest.php
<?php
namespace Tests\Unit\Cashier\DTO;
use Tests\TestCase;
use App\Cashier\DTO\PaymentIntent;
use App\Cashier\DTO\Payer;
use App\Cashier\DTO\SubscriptionSpec;
class PaymentIntentDtoTest extends TestCase
{
private function payer(): Payer
{
return new Payer(
uid: 'cust_uid',
name: 'Alice',
email: '[email protected]',
phone: '+1-555',
billingName: 'Alice Smith',
billingAddress: '1 Way',
billingCountryCode: 'US',
);
}
public function test_one_off_intent_has_no_subscription_spec()
{
$intent = new PaymentIntent(
uid: 'intent_uid',
amount: 29.99,
currency: 'USD',
description: 'Pay invoice INV-1',
paymentGatewayId: 'gw_uid',
payer: $this->payer(),
subscription: null,
);
$this->assertFalse($intent->isSubscription());
$this->assertNull($intent->subscription);
}
public function test_subscription_intent_carries_remote_plan_id()
{
$intent = new PaymentIntent(
uid: 'intent_uid',
amount: 19.99,
currency: 'USD',
description: 'Subscribe Pro',
paymentGatewayId: 'gw_uid',
payer: $this->payer(),
subscription: new SubscriptionSpec(remotePlanId: 'price_xyz'),
);
$this->assertTrue($intent->isSubscription());
$this->assertSame('price_xyz', $intent->subscription->remotePlanId);
}
public function test_metadata_defaults_to_empty_array()
{
$intent = new PaymentIntent(
uid: 'i', amount: 1.0, currency: 'USD', description: 'd',
paymentGatewayId: 'gw', payer: $this->payer(), subscription: null,
);
$this->assertSame([], $intent->metadata);
}
}