90 lines
2.5 KiB
PHP
90 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use Livewire\Component;
|
|
use App\Services\ApiService;
|
|
use Illuminate\Support\Facades\Session;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Jenssegers\Agent\Agent;
|
|
|
|
class PublicTopSuccessPage extends Component
|
|
{
|
|
public $loading = false;
|
|
public $status = '';
|
|
public $userInfo = null;
|
|
public $message = '';
|
|
public $paymentId = '';
|
|
public $token = '';
|
|
public $payerId = '';
|
|
|
|
protected $apiService;
|
|
|
|
public function boot(ApiService $apiService)
|
|
{
|
|
$this->apiService = $apiService;
|
|
}
|
|
|
|
public function mount()
|
|
{
|
|
$this->loading = true;
|
|
|
|
// Get query parameters from the request
|
|
$this->paymentId = request()->query('paymentId');
|
|
$this->token = request()->query('token');
|
|
$this->payerId = request()->query('PayerID');
|
|
|
|
$payload = [
|
|
'paymentId' => $this->paymentId,
|
|
'token' => $this->token,
|
|
'PayerID' => $this->payerId,
|
|
];
|
|
|
|
try {
|
|
$response = $this->apiService->post('paypalExecute', $payload);
|
|
|
|
if ($response && isset($response['status']) && $response['status'] === 200) {
|
|
$this->status = 200;
|
|
$this->userInfo = $response['data'];
|
|
Log::info('Top-up success', ['source' => 'PublicTopSuccessPage']);
|
|
}
|
|
} catch (\Exception $e) {
|
|
$this->status = $e->getCode() ?: 500;
|
|
$this->message = $e->getMessage();
|
|
Log::error('Top-up failed', ['error' => $e->getMessage(), 'source' => 'PublicTopSuccessPage']);
|
|
} finally {
|
|
$this->loading = false;
|
|
}
|
|
}
|
|
|
|
public function backHandler()
|
|
{
|
|
$agent = new Agent();
|
|
|
|
if ($agent->is('iOS')) {
|
|
// Trigger iOS native handler
|
|
$this->dispatchBrowserEvent('ios-top-up-failed');
|
|
} elseif ($agent->is('Android')) {
|
|
// Trigger Android native handler
|
|
$this->dispatchBrowserEvent('android-top-up-failed');
|
|
}
|
|
}
|
|
|
|
public function backHandlerSuccess()
|
|
{
|
|
$agent = new Agent();
|
|
|
|
if ($agent->is('iOS')) {
|
|
// Trigger iOS native handler
|
|
$this->dispatchBrowserEvent('ios-top-up-success');
|
|
} elseif ($agent->is('Android')) {
|
|
// Trigger Android native handler (corrected from Failed to Success)
|
|
$this->dispatchBrowserEvent('android-top-up-success');
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.public-top-success-page')->layout('layouts.app');
|
|
}
|
|
} |