diff --git a/.env.example b/.env.example index 7d6ab47..34660fa 100644 --- a/.env.example +++ b/.env.example @@ -50,6 +50,7 @@ MONERO_RPC_PORT=18082 MONERO_RPC_SSL=false MONERO_VENDOR_PAYMENT_REQUIRED_AMOUNT=0.4 MONERO_VENDOR_PAYMENT_MINIMUM_AMOUNT=0.04 +MONERO_VENDOR_PAYMENT_REFUND_PERCENTAGE=80 MONERO_ADDRESS_EXPIRATION_TIME=1440 # Marketplace Settings diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 72440da..c445c47 100755 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -978,20 +978,80 @@ public function denyVendorApplication(VendorPayment $application) } try { + \DB::beginTransaction(); + + // Get refund percentage from config + $refundPercentage = config('monero.vendor_payment_refund_percentage'); + if ($refundPercentage <= 0) { + throw new \Exception('Refund percentage must be greater than zero'); + } + + // Calculate refund amount + $refundAmount = $application->total_received * ($refundPercentage / 100); + + // Get random verified return address + $returnAddress = $application->user->returnAddresses() + ->where('is_verified', true) + ->inRandomOrder() + ->first(); + + if (!$returnAddress) { + throw new \Exception('No verified return address found for user'); + } + + // First update application status $application->update([ 'application_status' => 'denied', 'admin_response_at' => now() ]); - Log::info("Vendor application denied for user {$application->user_id}"); + try { + // Initialize WalletRPC with increased timeout + $config = config('monero'); + $walletRPC = new \MoneroIntegrations\MoneroPhp\walletRPC( + $config['host'], + $config['port'], + $config['ssl'], + 30000 // 30 second timeout + ); + + // Process refund + $result = $walletRPC->transfer([ + 'address' => $returnAddress->monero_address, + 'amount' => $refundAmount, + 'priority' => 1 + ]); + + // Update refund details only if transfer successful + $application->update([ + 'refund_amount' => $refundAmount, + 'refund_address' => $returnAddress->monero_address + ]); + + $refundMessage = "Refund of {$refundAmount} XMR has been processed."; + } catch (\Exception $e) { + Log::error('Error processing refund: ' . $e->getMessage()); + $refundMessage = "Application denied but refund failed. Please process refund manually."; + + // Still update refund details for manual processing + $application->update([ + 'refund_amount' => $refundAmount, + 'refund_address' => $returnAddress->monero_address + ]); + } + + \DB::commit(); + + Log::info("Vendor application denied for user {$application->user_id}. Refund processed: {$refundAmount} XMR to address {$returnAddress->monero_address}"); return redirect()->route('admin.vendor-applications.show', $application) - ->with('success', 'Application denied successfully.'); + ->with('success', "Application denied successfully. " . $refundMessage); } catch (\Exception $e) { + \DB::rollBack(); Log::error('Error denying vendor application: ' . $e->getMessage()); return redirect()->back() - ->with('error', 'An error occurred while processing the application.'); + ->with('error', 'An error occurred while processing the application and refund.'); } } diff --git a/app/Models/VendorPayment.php b/app/Models/VendorPayment.php index ad23f8b..ba4eaea 100755 --- a/app/Models/VendorPayment.php +++ b/app/Models/VendorPayment.php @@ -23,11 +23,14 @@ class VendorPayment extends Model 'application_status', 'application_images', 'application_submitted_at', - 'admin_response_at' + 'admin_response_at', + 'refund_amount', + 'refund_address' ]; protected $casts = [ 'total_received' => 'decimal:12', + 'refund_amount' => 'decimal:12', 'expires_at' => 'datetime', 'payment_completed' => 'boolean', 'application_images' => 'json', diff --git a/config/monero.php b/config/monero.php old mode 100644 new mode 100755 index d55b882..afac591 --- a/config/monero.php +++ b/config/monero.php @@ -6,5 +6,6 @@ 'ssl' => env('MONERO_RPC_SSL', false), 'vendor_payment_required_amount' => env('MONERO_VENDOR_PAYMENT_REQUIRED_AMOUNT', 0.4), 'vendor_payment_minimum_amount' => env('MONERO_VENDOR_PAYMENT_MINIMUM_AMOUNT', 0.04), + 'vendor_payment_refund_percentage' => env('MONERO_VENDOR_PAYMENT_REFUND_PERCENTAGE', 80), /*This value must never be set to zero.*/ 'address_expiration_time' => env('MONERO_ADDRESS_EXPIRATION_TIME', 1440), ]; diff --git a/database/migrations/2025_01_01_000007_create_vendor_payment_subaddresses_table.php b/database/migrations/2025_01_01_000007_create_vendor_payment_subaddresses_table.php index 4c79178..7108a10 100755 --- a/database/migrations/2025_01_01_000007_create_vendor_payment_subaddresses_table.php +++ b/database/migrations/2025_01_01_000007_create_vendor_payment_subaddresses_table.php @@ -24,6 +24,8 @@ public function up() $table->json('application_images')->nullable(); // Store up to 4 image paths $table->timestamp('application_submitted_at')->nullable(); $table->timestamp('admin_response_at')->nullable(); + $table->decimal('refund_amount', 20, 12)->nullable(); + $table->string('refund_address')->nullable(); $table->boolean('payment_completed')->default(false); }); } diff --git a/resources/views/admin/vendor-applications/show.blade.php b/resources/views/admin/vendor-applications/show.blade.php index 4530fef..2f7cd6a 100644 --- a/resources/views/admin/vendor-applications/show.blade.php +++ b/resources/views/admin/vendor-applications/show.blade.php @@ -59,6 +59,20 @@

+ + @if($application->application_status === 'denied' && $application->refund_amount) +
+

Refund Details

+
+

+ Refund Amount: {{ $application->refund_amount }} XMR +

+

+ Refund Address: {{ $application->refund_address }} +

+
+
+ @endif @endif
diff --git a/resources/views/become-vendor/index.blade.php b/resources/views/become-vendor/index.blade.php index dcaa594..32824d4 100755 --- a/resources/views/become-vendor/index.blade.php +++ b/resources/views/become-vendor/index.blade.php @@ -57,6 +57,11 @@

Congratulations! Your application has been accepted. You can now access the vendor features.

@else

Unfortunately, your application has been denied. You cannot submit a new application at this time.

+ @if($vendorPayment->refund_amount) +
+

A refund of {{ $vendorPayment->refund_amount }} XMR has been sent to your return address.

+
+ @endif @endif
@endif