10

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.

Click Here to Leave a Comment Below 10 comments
Rene - October 19, 2012

On which events does the unregister() method get called? For example if the product access date passes because the user has cancelled the subscription profile in PayPal it then makes sense that the user gets removed from the mailing list as well (mailchimp for example).

How can i call the plugin methods to work when the access date passes for users?

Reply
Veena Prashanth - October 19, 2012

Rene,

Great question.

Currently the only event that triggers the ‘unregister’ is when you manually ‘remove user’s access to product’ from dap manage user’s page.

That said, we are working on fully automating all cancellation flows, so upon cancellation, dap will reset the access end date to previous date (so the user will lose access immediately instead of user losing access at the end of current recurring cycle) and then dap will also trigger the call to unregister().

The ‘cancellation options’ will be configurable by the admin.
1) If admin sets it to ‘remove user’s access to product’, dap will remove access completely.
2) If admin sets it to ‘reset user’s AccessEndDate to previous date’ (so user will still have the product but can’t access content), then dap will not remove product but simply reset the access end date.
3) If admin sets it to ‘no action’, then dap wont do anything, and the user will automatically lose access at the end of current recurring cycle.

We expect to have this change complete in about 4-5 months (dap 4.5).

Thanks,
Veena

Reply
Rene - October 20, 2012

Ok, so for the time being i can clean the subscribers list with writing a cron script to take care of it.

Reply
Kyle - December 20, 2012

Is there anything I can call to get a users paypal email address? I tried using $dapuser->getPaypalEmail()) but it didn’t exist and I can’t see any reference to it above.

Reply
Rene - December 20, 2012

You can check Dap_User.class for possible user object methods. Maybe there’s something there.

Reply
Kyle - December 20, 2012

Thanks a lot, getPaypal_email() is what I needed.

Reply
Rob - June 5, 2014

Is DAP able to store any values returned by the third party API in a custom field for example? I need to call an API that creates a google doc and store the URL for the member.

Thanks

Reply
Veena Prashanth - June 5, 2014

Hi Rob,
>>Is DAP able to store any values returned by the third party API in a custom field for example? I need to call an API that creates a google doc and store the URL for the member. << The dap plugin framework can be extended to store data in dap but you will have to write custom code to do so in the plugin class file. It's not built into DAP. As it's custom code, we will not be able to help with it with standard dap support. If you want it developed for a custom fee, you can contact us via support ticket and we will let you know the cost. Thanks, Veena

Reply
Eric - November 16, 2014

This is very helpful for manipulating database info when a product is purchased or removed, but how would I manipulate a database (associated with a user) otherwise? Is there a function I can call to get a dap user’s ID?

Thanks for your help.

Reply
Veena Prashanth - December 6, 2014

>This is very helpful for manipulating database info when a product is purchased or removed, but how would I manipulate a database (associated with a user) otherwise? Is there a function I can call to get a dap user’s ID?<< You will find the 'php code snippet' to get the DAP User Id (from session object) in /dap/index.php. Thanks, Veena

Reply

Leave a Reply: