added beads and fixes for paddle checkout
This commit is contained in:
@@ -8,6 +8,9 @@ use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use App\Services\Checkout\CheckoutSessionService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CheckoutSessionStatusTest extends TestCase
|
||||
@@ -54,4 +57,74 @@ class CheckoutSessionStatusTest extends TestCase
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_session_status_recovers_completed_paddle_transaction(): void
|
||||
{
|
||||
$tenant = Tenant::factory()->create();
|
||||
$user = User::factory()->for($tenant)->create([
|
||||
'pending_purchase' => true,
|
||||
]);
|
||||
$package = Package::factory()->create([
|
||||
'type' => 'endcustomer',
|
||||
'price' => 99,
|
||||
]);
|
||||
|
||||
/** @var CheckoutSessionService $sessions */
|
||||
$sessions = app(CheckoutSessionService::class);
|
||||
$session = $sessions->createOrResume($user, $package, [
|
||||
'tenant' => $tenant,
|
||||
]);
|
||||
$sessions->selectProvider($session, CheckoutSession::PROVIDER_PADDLE);
|
||||
$session->forceFill([
|
||||
'provider_metadata' => [
|
||||
'paddle_checkout_id' => 'chk_123',
|
||||
],
|
||||
])->save();
|
||||
|
||||
config()->set([
|
||||
'paddle.api_key' => 'test-key',
|
||||
'paddle.base_url' => 'https://paddle.test',
|
||||
'paddle.environment' => 'sandbox',
|
||||
]);
|
||||
|
||||
Http::fake([
|
||||
'https://paddle.test/*' => Http::response([
|
||||
'data' => [
|
||||
[
|
||||
'id' => 'txn_123',
|
||||
'status' => 'completed',
|
||||
'details' => [
|
||||
'totals' => [
|
||||
'currency_code' => 'EUR',
|
||||
'total' => ['amount' => 9900],
|
||||
],
|
||||
],
|
||||
'custom_data' => [
|
||||
'checkout_session_id' => $session->id,
|
||||
],
|
||||
],
|
||||
],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
Mail::fake();
|
||||
Notification::fake();
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = $this->getJson(route('checkout.session.status', $session));
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('status', CheckoutSession::STATUS_COMPLETED);
|
||||
|
||||
$this->assertDatabaseHas('checkout_sessions', [
|
||||
'id' => $session->id,
|
||||
'status' => CheckoutSession::STATUS_COMPLETED,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('package_purchases', [
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user