feat: revenue cat
CI / 🧪 Tests Laravel (push) Successful in 2m24s
CI / 🐳 Build & Push Image (push) Successful in 1m13s

This commit is contained in:
2026-08-12 16:00:11 +02:00
parent 31633cfd2c
commit 29e85589b0
55 changed files with 703 additions and 2363 deletions
+26 -18
View File
@@ -3,7 +3,6 @@
use App\Actions\ReviewIdentityVerification;
use App\Enums\IdentityVerificationStatus;
use App\Enums\UserRole;
use App\Listeners\HandleStripeWebhook;
use App\Models\IdentityVerificationRequest;
use App\Models\User;
use App\Notifications\CertificationReviewedNotification;
@@ -11,6 +10,7 @@ use App\Notifications\EngagementReminderNotification;
use App\Notifications\NewFollowerNotification;
use App\Notifications\PaymentFailedNotification;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Storage;
use Laravel\Sanctum\Sanctum;
@@ -68,28 +68,36 @@ it('notifies the user when certification is reviewed', function () {
Notification::assertSentTo($user, CertificationReviewedNotification::class);
});
it('notifies a user only once when a failed invoice webhook is replayed', function () {
it('notifies a user only once when a RevenueCat billing issue is replayed', function () {
Notification::fake();
$user = User::factory()->create(['stripe_id' => 'cus_failed_payment']);
$event = (object) [
'payload' => [
'id' => 'evt_failed_payment',
'type' => 'invoice.payment_failed',
'data' => [
'object' => [
'id' => 'in_failed_payment',
'customer' => 'cus_failed_payment',
'amount_due' => 999,
'currency' => 'eur',
'lines' => ['data' => []],
],
config()->set('billing.revenuecat.secret_key', 'rc-secret');
config()->set('billing.revenuecat.webhook_authorization', 'Bearer rc-webhook');
$user = User::factory()->create();
Http::fake([
"api.revenuecat.com/v1/subscribers/{$user->id}" => Http::response([
'subscriber' => [
'entitlements' => [],
'subscriptions' => [],
],
]),
]);
$event = [
'event' => [
'id' => 'rc-billing-issue',
'type' => 'BILLING_ISSUE',
'app_user_id' => $user->id,
'product_id' => 'monthly',
'entitlement_ids' => ['bowli Pro'],
'environment' => 'PRODUCTION',
],
];
$listener = app(HandleStripeWebhook::class);
$listener->handle($event);
$listener->handle($event);
$this->withHeader('Authorization', 'Bearer rc-webhook')
->postJson('/api/webhooks/revenuecat', $event)
->assertOk();
$this->withHeader('Authorization', 'Bearer rc-webhook')
->postJson('/api/webhooks/revenuecat', $event)
->assertOk();
Notification::assertSentToTimes($user, PaymentFailedNotification::class, 1);
});