implemented event package addons with filament resource, event-admin purchase path and notifications, showing up in purchase history
This commit is contained in:
83
tests/Feature/Tenant/EventAddonWebhookTest.php
Normal file
83
tests/Feature/Tenant/EventAddonWebhookTest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Tenant;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\EventPackage;
|
||||
use App\Models\EventPackageAddon;
|
||||
use App\Models\Package;
|
||||
use App\Notifications\Addons\AddonPurchaseReceipt;
|
||||
use App\Services\Addons\EventAddonWebhookService;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
class EventAddonWebhookTest extends TenantTestCase
|
||||
{
|
||||
public function test_webhook_applies_addon_and_marks_completed(): void
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
Config::set('package-addons.extra_guests', [
|
||||
'label' => 'Guests 100',
|
||||
'increments' => ['extra_guests' => 100],
|
||||
'price_id' => 'pri_guests',
|
||||
]);
|
||||
|
||||
$package = Package::factory()->endcustomer()->create([
|
||||
'max_guests' => 50,
|
||||
]);
|
||||
|
||||
$event = Event::factory()->for($this->tenant)->create([
|
||||
'status' => 'published',
|
||||
]);
|
||||
|
||||
$eventPackage = EventPackage::create([
|
||||
'event_id' => $event->id,
|
||||
'package_id' => $package->id,
|
||||
'purchased_price' => $package->price,
|
||||
'purchased_at' => now(),
|
||||
'used_photos' => 0,
|
||||
'used_guests' => 0,
|
||||
'gallery_expires_at' => now()->addDays(7),
|
||||
]);
|
||||
|
||||
$addon = EventPackageAddon::create([
|
||||
'event_package_id' => $eventPackage->id,
|
||||
'event_id' => $event->id,
|
||||
'tenant_id' => $this->tenant->id,
|
||||
'addon_key' => 'extra_guests',
|
||||
'quantity' => 1,
|
||||
'extra_guests' => 100,
|
||||
'status' => 'pending',
|
||||
'metadata' => [
|
||||
'addon_intent' => 'intent-123',
|
||||
],
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
'event_type' => 'transaction.completed',
|
||||
'data' => [
|
||||
'id' => 'txn_addon_1',
|
||||
'metadata' => [
|
||||
'addon_intent' => 'intent-123',
|
||||
'addon_key' => 'extra_guests',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$handler = app(EventAddonWebhookService::class);
|
||||
|
||||
$handled = $handler->handle($payload);
|
||||
|
||||
$this->assertTrue($handled);
|
||||
|
||||
$addon->refresh();
|
||||
$eventPackage->refresh();
|
||||
|
||||
$this->assertSame('completed', $addon->status);
|
||||
$this->assertSame('txn_addon_1', $addon->transaction_id);
|
||||
$this->assertSame(100, $eventPackage->extra_guests);
|
||||
|
||||
Notification::assertSentTimes(AddonPurchaseReceipt::class, 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user