<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class MockPaymentController extends Controller
{
    public function approve(Request $request)
    {
        $callbackUrl = $request->query('callback_url');
        
        // If we have a callback URL from the frontend, use it.
        // We append status=success and mock data to simulate a successful PayPal return.
        if ($callbackUrl) {
            $separator = str_contains($callbackUrl, '?') ? '&' : '?';
            return redirect($callbackUrl . $separator . "status=success&token=MOCK_TOKEN&PayerID=MOCK_PAYER");
        }

        // Fallback for mobile apps or if no callback provided
        return redirect("https://example.com/success?return=true&token=MOCK_TOKEN&PayerID=MOCK_PAYER");
    }
}
