DAP Plugin Framework
How To Setup Notifications/Triggers From DAP to 3rd Party APIs
We have now created a plugin framework that will allow DAP to trigger calls to 3rd party services when a user is added to a product (subscription/registration event) or when a user loses access to product (unsubscribe/unregister event).
In fact, we used the same framework to develop DAP -> Mailchimp integration in DAP 4.1.
Here’s the steps :
1) If you want DAP to trigger calls to the APIs/methods you wrote upon an addUserToProduct event or removeUserFromProduct event in DAP, then in the DAP products page – > notify plugin field, use the following format to integrate the APIs/class files. You can integrate multiple systems with DAP using this framework.
Say you want to integrate classname1 (that has the necessary APIs to register/unregister users to 3rd party service like Mailchimp ) and classname 2 (that has the necessary APIs to register/unregister users to another 3rd party service like GetResponse), then use this format in the notify plugins field above.
classname1:VALUE 1 you want to pass to the api: VALUE 2 you want to pass to the api: VALUE 3 you want to pass to the api
If you want DAP to call multiple APIs/ Classes, then just create a comma seperated list of classes that DAP should notify.
classname1:VALUE 1 you want to pass to the api: VALUE 2 you want to pass to the api: VALUE 3 you want to pass to the api,
classname2:VALUE 1 you want to pass to the api: VALUE 2 you want to pass to the api,
classname3:VALUE 1 you want to pass to the api
Whatever values (VALUE1, VALUE2.. ) you put next to the class name (all values should be “:” separated), DAP will forward those params/values to your APIs when a user is added to product or user is removed from product.
To integrate say classname1 which consists of the methods/apis to talk to your 3rd party services, create a folder called classname1 under /dap/plugins folder. Then under the classname1 folder, create a php script called classname1.class.php (just the way you notice a folder called mailchimp and under mailchimp a class file called mailchimp.class.php).
So you will have something like this:
/dap/plugins/classname1/classname1.class.php
Here’s what you need to have in classname1.class.php ( skleton class implementation ) :
< ?php
class classname1 {
function classname1() // constructor
{ }
//======== USER REGISTRATION===========
// this function is called by dap when a user is added to a product
function register($userId, $productId, $params) {
logToFile(“classname1.class.php: register(): “, LOG_INFO_DAP);
$dapuser = Dap_User::loadUserById($userId);
$email = trim($dapuser->getEmail());
$username = trim($dapuser->getUser_name());
$firstname = trim($dapuser->getFirst_name());
$lastname = trim($dapuser->getLast_name());
$data = explode(“:”,$params);
}
function unregister($userId, $productId, $params)
{
logToFile(“classname1.class.php: register(): “, LOG_INFO_DAP);
$dapuser = Dap_User::loadUserById($userId);
$email = trim($dapuser->getEmail());
$data = explode(“:”,$params);
}
}
?>
NOTE:
You MUST have same name methods (called register() and unregister() ) and the exact method signature as you see above.
You can call other methods/functions from register/unregister and/or
You can call 3rd party APIs from register/unregister methods and/or
You can include other class files.
Whatever values you pass (VALUE1, VALUE2 etc) via notify plugin, you can access those values in these methods. The values are available in the $params array.
That’s it.
You can add a test user to a product in DAP (via dap admin -> add users) and see if things work as expected.