/** * Process the result of webhook procession * * @param TinypassWebhookResult $webhookResult * * @throws Exception */ private function processWebhookResult(TinypassWebhookResult $webhookResult) { switch ($webhookResult->action()) { case TinypassWebhookResult::ACTION_UPDATE_CONTENT_KEY: $metaString = get_post_meta($webhookResult->id(), self::META_NAME, true); // Get content settings from post meta $contentSettings = TinypassContentSettings::fromArray($metaString); if ($contentSettings->chargeOption() != TinypassContentSettings::CHARGE_OPTION_ALGORITHMIC) { throw new Exception(__('Algorithmic keying is not enabled for this post', 'tinypass')); } // Set the key attribute to resulted from webhook processing $contentSettings->algorithmicKeyed($webhookResult->key()); // Save post meta add_post_meta($webhookResult->id(), self::META_NAME, $contentSettings->toArray(), true) or update_post_meta($webhookResult->id(), self::META_NAME, $contentSettings->toArray()); header('HTTP/1.1 200 OK'); exit(__('Keying rules updated', 'tinypass')); break; } }