diff --git a/.env.example b/.env.example index 5e97de1..7901d51 100644 --- a/.env.example +++ b/.env.example @@ -4,6 +4,10 @@ APP_KEY= APP_DEBUG=true APP_URL=http://localhost +CHARGE_FEES=false +DISABLE_WITHDRAWALS=true +DISABLE_REGISTRATION=true + LOG_CHANNEL=stack LOG_DEPRECATIONS_CHANNEL=null LOG_LEVEL=debug diff --git a/app/Console/Commands/BatchOnchainWithdrawals.php b/app/Console/Commands/BatchOnchainWithdrawals.php index eb1b216..8989c1a 100755 --- a/app/Console/Commands/BatchOnchainWithdrawals.php +++ b/app/Console/Commands/BatchOnchainWithdrawals.php @@ -40,6 +40,12 @@ class BatchOnchainWithdrawals extends Command */ public function handle() { + + if (env('DISABLE_WITHDRAWALS') == true) { + $this->info('Withdrawals are disabled, exiting'); + return Command::SUCCESS; + } + $onchainUsers = User::where('default_withdrawal_type', WithdrawalType::ONCHAIN)->where('onchain_address', '!=', null)->get(); $withdrawalUsers = $onchainUsers @@ -139,13 +145,16 @@ public function handle() 'user_id' => $user->id, ]); - $withdrawal->transaction()->create([ - 'amount' => $fee, - 'user_id' => $user->id, - 'type' => TransactionType::DEBIT, - 'status' => TransactionStatus::SETTLED, - 'is_fee' => true, - ]); + if (env('CHARGE_FEES') == true) { + $withdrawal->transaction()->create([ + 'amount' => $fee, + 'user_id' => $user->id, + 'type' => TransactionType::DEBIT, + 'status' => TransactionStatus::SETTLED, + 'is_fee' => true, + ]); + } + if ($user->notification_setting !== null && $user->notification_setting->withdrawal_success == true) { Notification::send($user, new WithdrawalSuccessNotification($withdrawal)); diff --git a/app/Console/Commands/WithdrawBalanceToLightning.php b/app/Console/Commands/WithdrawBalanceToLightning.php index a1b8ecb..e6f9c75 100755 --- a/app/Console/Commands/WithdrawBalanceToLightning.php +++ b/app/Console/Commands/WithdrawBalanceToLightning.php @@ -39,6 +39,12 @@ class WithdrawBalanceToLightning extends Command */ public function handle() { + + if (env('DISABLE_WITHDRAWALS') == true) { + $this->info('Withdrawals are disabled, exiting'); + return Command::SUCCESS; + } + $users = User::where('default_withdrawal_type', WithdrawalType::LIGHTNING->value) ->where('auto_withdraw', true) ->get(); diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index b8a9587..efc1f70 100755 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -22,6 +22,13 @@ class RegisteredUserController extends Controller */ public function store(Request $request) { + + if (env('DISABLE_REGISTRATION') == true) { + return response()->json([ + 'message' => 'Registration is disabled', + ], 422); + } + $request->validate([ 'email' => ['required', 'string', 'email', 'max:255', 'unique:' . User::class], 'password' => ['required', 'max:100', 'confirmed', Rules\Password::defaults()], diff --git a/app/Jobs/RecordTransactionJob.php b/app/Jobs/RecordTransactionJob.php index 7699fd1..c15e571 100755 --- a/app/Jobs/RecordTransactionJob.php +++ b/app/Jobs/RecordTransactionJob.php @@ -119,6 +119,10 @@ private function recordLightningTransaction($event) } } + if (env('CHARGE_FEES') == false) { + return; + } + $debit = $event->bitcoinable->transaction()->create([ 'user_id' => $event->bitcoinable->user()->first()->id, 'amount' => $this->getFee($amountPaid), @@ -161,6 +165,12 @@ private function recordOnchainTransaction($event) 'type' => TransactionType::CREDIT, ]); + Log::info('Created credit transaction ' . $credit->uuid . ' for ' . $event->bitcoinable->uuid); + + if (env('CHARGE_FEES') == false) { + return; + } + $debit = $event->bitcoinable->transaction()->create([ 'user_id' => $event->bitcoinable->user()->first()->id, 'amount' => $fee, diff --git a/app/Jobs/Withdrawal/DispatchLightningWithdrawalsJob.php b/app/Jobs/Withdrawal/DispatchLightningWithdrawalsJob.php index 6edda24..ac96842 100755 --- a/app/Jobs/Withdrawal/DispatchLightningWithdrawalsJob.php +++ b/app/Jobs/Withdrawal/DispatchLightningWithdrawalsJob.php @@ -39,6 +39,11 @@ public function __construct(Collection $users) */ public function handle() { + if (env('DISABLE_WITHDRAWALS') == true) { + Log::info('Withdrawals are disabled, exiting'); + return; + } + foreach ($this->users as $user) { if ( $user->lightning_address &&