feat: revenue cat
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user