Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
koen12344 authored and koen12344 committed Mar 21, 2022
0 parents commit 6f74867
Show file tree
Hide file tree
Showing 26 changed files with 4,009 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

# PHP Composer dependencies:
/vendor/

# PHPStorm
/.idea/
phpunit.xml.dist

# Project files
README.md
/tests/
config.sample.php
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vendor
.phpunit.result.cache
testdata.txt
config.php
token_config.php
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions .idea/fs-mautic-hooks.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/phpunit.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
`fs-mautic-hooks` is a webhook receiver for [Freemius](https://freemius.com/) that will update [Mautic](https://www.mautic.org/) contacts on specified webhook events.

This is intended to be used with the [fs-mautic-sync](https://github.com/koen12344/fs-mautic-sync) initial sync script to set up the custom fields in Mautic and do an initial sync of the plugin users.

This script is formatted as a Google App Engine app but could be adapted to work on different serverless platforms (or just a good ole lamp server). Feel free to fork.

## Features
* Uses secure Mautic oAuth2 authentication
* Creates or updates Mautic contacts and companies when:
* A new plugin user is created
* The plugin is installed on a new site
* The plugin is deactivated/uninstalled
* The plugin plan is changed
* The user opts in/out of the beta program
* The user opts in/out of marketing emails
* The user is accepted as an affiliate
* The PHP, WordPress or plugin version are updated

## Requirements
* [gcloud cli](https://cloud.google.com/sdk/docs/install) must be installed in PATH
* App engine app [must be configured](https://cloud.google.com/sdk/gcloud/reference/app/create) in your cloud project

## Installation & usage
1. Clone the repository
2. Create a new `config.php` file in the root directory based on `config.sample.php`
3. Modify the `app.yaml` to suit your needs
4. Run `gcloud app deploy` to deploy the app to Google App Engine
5. Navigate to `https://path-to-your-app-engine-app.appspot.com/authorize` to initialize the oAuth flow
6. Add a new webhook in Freemius, pointing to `https://path-to-your-app-engine-app.appspot.com/?token=the-token-you-defined-in-config.php`

## Troubleshooting
* Try clearing the Mautic cache if the API is giving you issues
7 changes: 7 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
runtime: php74
service: freemius-hooks
#
handlers:
- url: /.*
script: auto
secure: always
17 changes: 17 additions & 0 deletions authorize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use FSWebhooks\TokenStorage\GoogleDataStore;

session_start();

$settings = require('config.php');

require_once "vendor/autoload.php";

$token_storage = new GoogleDataStore();
$mautic_auth = new \FSWebhooks\MauticAuth($token_storage, $settings['mautic']);

$auth = $mautic_auth->get_auth();
if($auth->isAuthorized()){
echo 'Everybody, come out, quick! Look at the lights! - Clark Griswold';
};
19 changes: 19 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"autoload": {
"psr-4": {"FSWebhooks\\": "src/"}
},
"autoload-dev": {
"psr-4": {
"FSWebhooks\\Tests\\": "tests/FSWebhooks/"
}
},
"require": {
"guzzlehttp/guzzle": "^6.3",
"ext-json": "*",
"mautic/api-library": "^3.0",
"google/cloud-datastore": "^1.13"
},
"require-dev": {
"phpunit/phpunit": "^8"
}
}
Loading

0 comments on commit 6f74867

Please sign in to comment.