type); $event_action = array_pop($event_type_parts); $event_entity = implode(".", $event_type_parts); // Handle the event switch($event_entity) { case "invoice": { /** @var \Stripe\Invoice $invoice */ $invoice = $event->data->object; $stripe_customer = $stripe->customers->retrieve($invoice->customer); $location = Location::queryOne(["stripe_customer_id" => $stripe_customer->id]); if(!$location) { goto HTTP_OK; } switch($event_action) { case "payment_succeeded": { $test_id = $invoice->metadata->test_id ?? null; if($test_id) { $test = Test::get($test_id); $test->dts_paid = DB::dts(); $test->commit(); } break; } } break; } default: http_response_code(400); exit(); } } catch(UnexpectedValueException $e) { // Invalid payload http_response_code(400); exit(); } catch(SignatureVerificationException $e) { http_response_code(400); exit(); } catch(Exception $e) { http_response_code(400); die($e->getMessage()); } HTTP_OK: http_response_code(200); exit;