Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/Feature/Billing/CreditPackWebhookHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Billing\Webhooks\CreditPackWebhookHandler;
use App\Contracts\Billing\CreditLedger;
use App\Models\CreditTransaction;
use App\Models\User;

it('grants credits after successful credit pack checkout', function () {
Expand All @@ -28,6 +29,38 @@
expect(app(CreditLedger::class)->balance($user))->toBe($balanceBefore + 500);
});

it('stores stripe metadata on credit pack purchase transaction', function () {
config()->set('billing.credit_packs.small.stripe_price_id', 'price_small');

$user = User::factory()->create();

$event = fakeStripeCheckoutCompletedEvent([
'event_id' => 'evt_meta_1',
'checkout_session_id' => 'cs_meta_1',
'payment_intent_id' => 'pi_meta_1',
'user_id' => $user->id,
'pack_key' => 'small',
'pack_credits' => 500,
'price_id' => 'price_small',
]);

app(CreditPackWebhookHandler::class)->handleCheckoutSessionCompleted($event);

$transaction = CreditTransaction::query()
->where('user_id', $user->id)
->where('reason', 'credit_pack_purchase')
->firstOrFail();

expect($transaction->metadata_json)->toMatchArray([
'pack_key' => 'small',
'pack_credits' => 500,
'stripe_event_id' => 'evt_meta_1',
'stripe_checkout_session_id' => 'cs_meta_1',
'stripe_payment_intent_id' => 'pi_meta_1',
'stripe_price_id' => 'price_small',
]);
});

it('does not grant credits twice for duplicate credit pack checkout event', function () {
config()->set('billing.credit_packs.small.stripe_price_id', 'price_small');

Expand Down