Skip to content

Commit

Permalink
Include plugin version info in every request, reorganize hooks, add t…
Browse files Browse the repository at this point in the history
…rial hooks
  • Loading branch information
koen12344 authored and koen12344 committed May 6, 2022
1 parent 6f74867 commit 2136fa2
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
runtime: php74
service: freemius-hooks
service: default
#
handlers:
- url: /.*
Expand Down
126 changes: 91 additions & 35 deletions src/MauticHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(
[
Expand All @@ -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(
[
Expand All @@ -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(
[
Expand All @@ -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']);
Expand All @@ -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(
[
Expand All @@ -170,6 +253,8 @@ public function user_beta_program_opted_out(){
);
}

// -- Affiliate hooks

public function affiliate_approved(){
$this->create_or_update_contact(
[
Expand All @@ -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();
}
}

0 comments on commit 2136fa2

Please sign in to comment.