Files
hoshpoint-backend/app/Services/WalletDepositService.php
soheil khaledabadi 46ae711a20 feat(api): add AI text-to-deck generation, wallet deposit structure, and profile/notification endpoints
Fills the gaps between the admin panel screens and the backend: a full
free-text + slide-count + language -> AI-generated presentation flow with
new slide-cloning logic in TemplateFillService, a "my presentations" list
endpoint, a swappable payment-gateway structure for wallet top-ups (fake
driver for now), and avatar upload / public-profile toggle / account
deletion / password change / notification preference endpoints.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-29 01:36:17 +03:30

62 lines
1.7 KiB
PHP

<?php
namespace App\Services;
use App\Contracts\PaymentGateway;
use App\Enums\PaymentGatewayDriver;
use App\Enums\WalletDepositStatus;
use App\Models\User;
use App\Models\WalletDeposit;
use Illuminate\Support\Facades\DB;
class WalletDepositService
{
public function __construct(
private readonly WalletService $walletService,
private readonly PaymentGateway $gateway,
) {}
/**
* @return array{deposit: WalletDeposit, payment_url: string}
*/
public function initiate(User $user, int $amount): array
{
$wallet = $this->walletService->createForUser($user);
$deposit = WalletDeposit::query()->create([
'wallet_id' => $wallet->id,
'amount' => $amount,
'status' => WalletDepositStatus::Pending,
'gateway' => PaymentGatewayDriver::Fake->value,
]);
$paymentUrl = $this->gateway->initiate($deposit);
return ['deposit' => $deposit, 'payment_url' => $paymentUrl];
}
/**
* @param array<string, mixed> $callbackPayload
*/
public function handleCallback(WalletDeposit $deposit, array $callbackPayload): bool
{
if ($deposit->status !== WalletDepositStatus::Pending) {
return $deposit->status === WalletDepositStatus::Paid;
}
if (! $this->gateway->verify($deposit, $callbackPayload)) {
$deposit->update(['status' => WalletDepositStatus::Failed]);
return false;
}
DB::transaction(function () use ($deposit): void {
$this->walletService->credit($deposit->wallet, $deposit->amount, 'شارژ کیف پول');
$deposit->update(['status' => WalletDepositStatus::Paid]);
});
return true;
}
}