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.

6 comments ↓

#1 Rene on 10.19.12 at 7:23 am

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?

#2 Veena Prashanth on 10.19.12 at 3:33 pm

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

#3 Rene on 10.20.12 at 1:03 am

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

#4 Kyle on 12.20.12 at 8:01 am

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.

#5 Rene on 12.20.12 at 8:21 am

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

#6 Kyle on 12.20.12 at 8:43 am

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

Leave a Comment