Add wallet auto-withdraw threshold support for Ladill Mini.
Deploy Ladill Mini / deploy (push) Failing after 42s
Deploy Ladill Mini / deploy (push) Failing after 42s
Store per-user auto-withdraw amounts, expose them via the wallet API, and process withdrawals when balances reach the configured threshold after payments or on a schedule. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api\Mini;
|
||||
use App\Http\Controllers\Api\Concerns\CallsIdentityApi;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Billing\BillingClient;
|
||||
use App\Services\Mini\AutoWithdrawService;
|
||||
use App\Services\Notifications\MiniNotificationService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -18,6 +19,7 @@ class WalletController extends Controller
|
||||
public function __construct(
|
||||
private BillingClient $billing,
|
||||
private MiniNotificationService $notifications,
|
||||
private AutoWithdrawService $autoWithdraw,
|
||||
) {}
|
||||
|
||||
public function show(): JsonResponse
|
||||
@@ -33,12 +35,39 @@ class WalletController extends Controller
|
||||
Log::warning('Mini API wallet load failed', ['user' => $account->public_id, 'error' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
$settings = $account->getOrCreateQrSetting();
|
||||
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'currency' => 'GHS',
|
||||
'balance_minor' => $balanceMinor,
|
||||
'spent_minor' => (int) ($ledger['spent_minor'] ?? 0),
|
||||
'credited_minor' => (int) ($ledger['credited_minor'] ?? 0),
|
||||
'auto_withdraw_amount_minor' => $settings->auto_withdraw_amount_minor,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateAutoWithdraw(Request $request): JsonResponse
|
||||
{
|
||||
$account = ladill_account();
|
||||
|
||||
$data = $request->validate([
|
||||
'amount' => ['nullable', 'numeric', 'min:1', 'max:50000'],
|
||||
]);
|
||||
|
||||
$amountMinor = isset($data['amount']) ? (int) round((float) $data['amount'] * 100) : null;
|
||||
|
||||
$settings = $account->getOrCreateQrSetting();
|
||||
$settings->update(['auto_withdraw_amount_minor' => $amountMinor]);
|
||||
|
||||
if ($amountMinor !== null) {
|
||||
$this->autoWithdraw->attemptForUser($account);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'auto_withdraw_amount_minor' => $settings->fresh()->auto_withdraw_amount_minor,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user