Added license webhook logs

This commit is contained in:
Julien Nahum 2023-11-01 20:17:39 +01:00
parent dc5a828b8e
commit 04a367d120
1 changed files with 20 additions and 1 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\Webhook;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\License; use App\Models\License;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Validation\UnauthorizedException; use Illuminate\Validation\UnauthorizedException;
@ -14,6 +15,7 @@ class AppSumoController extends Controller
$this->validateSignature($request); $this->validateSignature($request);
if ($request->test) { if ($request->test) {
Log::info('[APPSUMO] test request received', $request->toArray());
return $this->success([ return $this->success([
'message' => 'Webhook received.', 'message' => 'Webhook received.',
'event' => $request->event, 'event' => $request->event,
@ -21,6 +23,8 @@ class AppSumoController extends Controller
]); ]);
} }
Log::info('[APPSUMO] request received', $request->toArray());
// Call the right function depending on the event using match() // Call the right function depending on the event using match()
match ($request->event) { match ($request->event) {
'activate' => $this->handleActivateEvent($request), 'activate' => $this->handleActivateEvent($request),
@ -45,6 +49,7 @@ class AppSumoController extends Controller
]); ]);
$licence->meta = $request->json()->all(); $licence->meta = $request->json()->all();
$licence->save(); $licence->save();
Log::info('[APPSUMO] activating license', $request->toArray());
} }
private function handleChangeEvent($request) private function handleChangeEvent($request)
@ -58,13 +63,23 @@ class AppSumoController extends Controller
'status' => License::STATUS_INACTIVE, 'status' => License::STATUS_INACTIVE,
]); ]);
Log::info('[APPSUMO] De-activating license', [
'license_key' => $request->prev_license_key,
'license_id' => $oldLicense->id,
]);
// Create new license // Create new license
License::create([ $license = License::create([
'license_key' => $request->license_key, 'license_key' => $request->license_key,
'license_provider' => 'appsumo', 'license_provider' => 'appsumo',
'status' => License::STATUS_ACTIVE, 'status' => License::STATUS_ACTIVE,
'meta' => $request->json()->all(), 'meta' => $request->json()->all(),
]); ]);
Log::info('[APPSUMO] creating new license',
[
'license_key' => $license->license_key,
'license_id' => $license->id,
]);
} }
private function handleDeactivateEvent($request) private function handleDeactivateEvent($request)
@ -77,6 +92,10 @@ class AppSumoController extends Controller
$oldLicense->update([ $oldLicense->update([
'status' => License::STATUS_INACTIVE, 'status' => License::STATUS_INACTIVE,
]); ]);
Log::info('[APPSUMO] De-activating license', [
'license_key' => $request->prev_license_key,
'license_id' => $oldLicense->id,
]);
} }
private function validateSignature(Request $request) private function validateSignature(Request $request)