Skip to content

Commit

Permalink
remove debug lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilal authored and Bilal committed Jul 21, 2018
1 parent 27dd512 commit 45ef88e
Showing 1 changed file with 0 additions and 19 deletions.
19 changes: 0 additions & 19 deletions src/Http/Controllers/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ class WebhookController extends Controller
*/
public function handleWebhook(Request $request)
{
Log::debug('handle start', ['req' => json_encode($request)]);

$payload = json_decode($request->getContent(), true);
Log::debug('payload', ['payload' => json_encode($payload)]);

// keep id of successfully managed events
$successfulEvents = [];
Expand All @@ -34,17 +31,13 @@ public function handleWebhook(Request $request)
? config('services.fastspring.hmac_secret')
: getenv('FASTSPRING_HMAC_SECRET');

Log::debug('hmac', ['hs' => $hmacSecret]);

// we try to be sure about
// message integrity and authentication of message
if ($hmacSecret) {
$signature = $request->header('X-FS-Signature');
Log::debug('signature', ['sig' => $signature]);

// generate signature to check
$generatedSignature = base64_encode(hash_hmac('sha256', $request->getContent(), $hmacSecret, true));
Log::debug('generated signature', ['gs' => $generatedSignature]);

// check if equals
if ($signature != $generatedSignature) {
Expand All @@ -57,20 +50,14 @@ public function handleWebhook(Request $request)

// iterate and trigger events
foreach ($payload['events'] as $event) {
Log::debug('event', ['event' => json_encode($event)]);

// prepare category event class names like OrderAny
$explodedType = explode('.', $event['type']);
$category = array_shift($explodedType);
$categoryEvent = '\Bgultekin\CashierFastspring\Events\\'.studly_case($category).'Any';
Log::debug('category', ['cat' => $category]);
Log::debug('categoryEvent', ['ce' => $categoryEvent]);

// prepare category event class names like activity
$activity = str_replace('.', ' ', $event['type']);
$activityEvent = '\Bgultekin\CashierFastspring\Events\\'.studly_case($activity);
Log::debug('activity', ['act' => $activity]);
Log::debug('activityEvent', ['ae' => $activityEvent]);

// there may be some exceptions on events
// so if anything goes bad its ID won't be added on the successfullEvents
Expand All @@ -80,8 +67,6 @@ public function handleWebhook(Request $request)
// check if the related event classes are exist
// there may be not handled events
if (!class_exists($categoryEvent) || !class_exists($activityEvent)) {
Log::debug('No event error');

throw new Exception('There is no event for '.$event['type']);
}

Expand Down Expand Up @@ -115,18 +100,14 @@ public function handleWebhook(Request $request)

// add event id to successful events
$successfulEvents[] = $event['id'];
Log::debug('success', ['id' => $event['id']]);
} catch (Exception $e) {
// log the exception
// and continue to iterate
Log::debug('try exception');

Log::error($e);
}
}

Log::debug('successfulEvents', ['se' => $successfulEvents]);

// return successful ids of events to mark them processed
return new Response(implode("\n", $successfulEvents), 202);
}
Expand Down

0 comments on commit 45ef88e

Please sign in to comment.