From 2136fa210d587e924b189e9f1ee8712a40a3a867 Mon Sep 17 00:00:00 2001 From: koen12344 Date: Fri, 6 May 2022 14:57:26 +0200 Subject: [PATCH] Include plugin version info in every request, reorganize hooks, add trial hooks --- app.yaml | 2 +- src/MauticHooks.php | 126 ++++++++++++++++++++++++++++++++------------ 2 files changed, 92 insertions(+), 36 deletions(-) diff --git a/app.yaml b/app.yaml index 44cb668..8fb6714 100644 --- a/app.yaml +++ b/app.yaml @@ -1,5 +1,5 @@ runtime: php74 -service: freemius-hooks +service: default # handlers: - url: /.* diff --git a/src/MauticHooks.php b/src/MauticHooks.php index ca9db2f..91f8c33 100644 --- a/src/MauticHooks.php +++ b/src/MauticHooks.php @@ -77,6 +77,9 @@ protected function create_or_update_company($fields = []){ 'companyname' => !empty($install->title) ? $install->title : $install->url, 'companywebsite' => $install->url, 'plan' => $install->plan_id, + 'wordpress_version' => $install->platform_version, + 'php_version' => $install->programming_language_version, + 'plugin_version' => $install->version, 'freemius_install_id' => $install->id, ]; $data = array_merge($data, $fields); @@ -98,10 +101,45 @@ protected function create_or_update_company($fields = []){ * Freemius webhook handlers start here */ + // -- User hooks + public function user_created(){ $this->create_or_update_contact(); } + // -- Install hooks + + public function install_platform_version_updated(){ + $this->create_or_update_company( + [ + 'wordpress_version' => $this->request->data->to + ] + ); + } + + public function install_programming_language_version_updated(){ + $this->create_or_update_company( + [ + 'php_version' => $this->request->data->to + ] + ); + } + + public function install_version_upgraded(){ + $this->create_or_update_company( + [ + 'plugin_version' => $this->request->data->to + ] + ); + } + public function install_version_downgrade(){ + $this->install_version_upgraded(); + } + + public function install_installed(){ + $this->create_or_update_company(); + } + public function install_activated(){ $this->create_or_update_company( [ @@ -128,6 +166,37 @@ public function install_uninstalled(){ ); } + public function install_premium_activated(){ + $this->create_or_update_company( + [ + 'plan' => $this->request->objects->install->plan_id, + ] + ); + } + public function install_premium_deactivated(){ + $this->install_premium_activated(); + } + + + + public function install_trial_started(){ + $this->create_or_update_company( + [ + 'in_trial' => true, + 'trial_plan' => $this->request->data->trial_plan_id, + ] + ); + } + + public function install_trial_cancelled(){ + $this->create_or_update_company( + [ + 'in_trial' => false, + 'trial_plan' => false, + ] + ); + } + public function install_url_updated(){ $this->create_or_update_company( [ @@ -136,6 +205,16 @@ public function install_url_updated(){ ); } + public function install_title_updated(){ + $to = $this->request->data->to; + if(empty($to)){ return; } + $this->create_or_update_company( + [ + 'companyname' => $to, + ] + ); + } + public function install_plan_changed(){ $this->create_or_update_company( [ @@ -144,6 +223,8 @@ public function install_plan_changed(){ ); } + // -- Marketing hooks + public function user_marketing_opted_in(){ $contact = $this->create_or_update_contact(); $this->contact_api->removeDNC($contact['id']); @@ -154,6 +235,8 @@ public function user_marketing_opted_out(){ $this->contact_api->addDNC($contact['id']); } + // -- Beta tester hooks + public function user_beta_program_opted_in(){ $this->create_or_update_contact( [ @@ -170,6 +253,8 @@ public function user_beta_program_opted_out(){ ); } + // -- Affiliate hooks + public function affiliate_approved(){ $this->create_or_update_contact( [ @@ -185,40 +270,11 @@ public function affiliate_deleted(){ ] ); } + public function affiliate_blocked(){ + $this->affiliate_deleted(); + } + public function affiliate_unapproved(){ + $this->affiliate_deleted(); + } - public function affiliate_blocked(){ - $this->affiliate_deleted(); - } - - public function affiliate_unapproved(){ - $this->affiliate_deleted(); - } - - public function install_platform_version_updated(){ - $this->create_or_update_company( - [ - 'wordpress_version' => $this->request->data->to - ] - ); - } - - public function install_programming_language_version_updated(){ - $this->create_or_update_company( - [ - 'php_version' => $this->request->data->to - ] - ); - } - - public function install_version_upgraded(){ - $this->create_or_update_company( - [ - 'plugin_version' => $this->request->data->to - ] - ); - } - - public function install_version_downgrade(){ - $this->install_version_upgraded(); - } } \ No newline at end of file