user = User::factory()->create(); $this->wallet = Wallet::create([ 'user_id' => $this->user->id, 'balance' => 0, ]); Sanctum::actingAs($this->user); } #[Test] public function it_redirects_to_gateway_for_payment() { $response = $this->postJson('/api/v1/payment/redirect', [ 'amount' => 100000, 'description' => 'شارژ تستی', ]); $response->assertStatus(200) ->assertJson([ 'success' => true, 'is_mock' => true, ]) ->assertJsonStructure([ 'success', 'message', 'payment_url', 'transaction_id', 'authority', 'amount', 'is_mock', ]); } #[Test] public function it_validates_minimum_deposit_amount() { $response = $this->postJson('/api/v1/payment/redirect', [ 'amount' => 1000, 'description' => 'شارژ تستی', ]); $response->assertStatus(422) ->assertJsonValidationErrors(['amount']); } #[Test] public function it_prevents_payment_for_frozen_wallet() { $this->wallet->update(['is_frozen' => true]); $response = $this->postJson('/api/v1/payment/redirect', [ 'amount' => 100000, 'description' => 'شارژ تستی', ]); $response->assertStatus(403) ->assertJson(['message' => 'کیف پول شما مسدود است.']); } #[Test] public function it_completes_mock_payment_successfully() { $response = $this->postJson('/api/v1/payment/redirect', [ 'amount' => 100000, 'description' => 'شارژ تستی', ]); $response->assertStatus(200); $transactionId = $response->json('transaction_id'); $authority = $response->json('authority'); $transaction = WalletTransaction::findOrFail($transactionId); $this->assertEquals(TransactionStatus::PENDING, $transaction->status); $callbackResponse = $this->get("/api/v1/payment/callback?Authority={$authority}&Status=OK"); $callbackResponse->assertRedirect(); $transaction->refresh(); $this->assertEquals(TransactionStatus::COMPLETED, $transaction->status); $this->wallet->refresh(); $this->assertEquals(100000, $this->wallet->balance); } #[Test] public function it_checks_transaction_status() { $response = $this->postJson('/api/v1/payment/redirect', [ 'amount' => 100000, 'description' => 'شارژ تستی', ]); $transactionId = $response->json('transaction_id'); $checkResponse = $this->get("/api/v1/payment/check/{$transactionId}"); $checkResponse->assertStatus(200) ->assertJson([ 'transaction_id' => $transactionId, 'status_code' => TransactionStatus::PENDING->value, ]); } }