{"id":1321,"date":"2011-03-16T12:03:04","date_gmt":"2011-03-16T19:03:04","guid":{"rendered":"http:\/\/www.digitalaccesspass.com\/doc\/?p=1321"},"modified":"2014-03-01T22:35:01","modified_gmt":"2014-03-02T06:35:01","slug":"dap-plugin-framework","status":"publish","type":"post","link":"http:\/\/digitalaccesspass.com\/doc\/dap-plugin-framework\/","title":{"rendered":"DAP Plugin Framework"},"content":{"rendered":"<h3>How To Setup Notifications\/Triggers From DAP to 3rd Party APIs<\/h3>\n<p>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).<\/p>\n<p>In fact, we used the same framework to develop<a href=\"http:\/\/www.digitalaccesspass.com\/doc\/mailchimp-integration\/\"> <strong>DAP -&gt; Mailchimp integration<\/strong><\/a><strong> <\/strong>in DAP 4.1.<\/p>\n<p>Here&#8217;s the steps :<\/p>\n<p>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 &#8211; &gt; notify plugin field, use the following format to integrate the APIs\/class files.\u00a0 You can integrate multiple systems with DAP using this framework.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-1324\" title=\"DAP_plugin_integration\" src=\"http:\/\/www.digitalaccesspass.com\/doc\/wp-content\/uploads\/2011\/03\/DAP_plugin_integration.png\" alt=\"\" width=\"556\" height=\"328\" \/><\/p>\n<p>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\u00a0 APIs to register\/unregister users to another 3rd party service like GetResponse), then use this format in the notify plugins field above.<\/p>\n<p>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<\/p>\n<p>If you want DAP to call multiple APIs\/ Classes, then just create a comma seperated list of classes that DAP should notify.<br \/>\nclassname1: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,<br \/>\nclassname2:VALUE 1 you want to pass to the api: VALUE 2 you want to pass to the api,<br \/>\nclassname3:VALUE 1 you want to pass to the api<\/p>\n<p>Whatever values (VALUE1, VALUE2.. ) you put next to the class name (all values should be &#8220;:&#8221; separated), DAP will forward those params\/values to your APIs when a user is added to product or user is removed from product.<\/p>\n<p>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\u00a0 (just the way you notice a folder called mailchimp and under mailchimp a class file called mailchimp.class.php).<\/p>\n<p>So you will have something like this:<\/p>\n<p>\/dap\/plugins\/classname1\/classname1.class.php<\/p>\n<p>Here&#8217;s what you need to have in classname1.class.php ( skleton class implementation ) :<\/p>\n<p>&lt; ?php<\/p>\n<p>class classname1 {<\/p>\n<p>function classname1() \/\/ constructor<br \/>\n{   }<\/p>\n<p>\/\/======== USER REGISTRATION===========<\/p>\n<p>\/\/ this function is called by dap when a user is added to a product<\/p>\n<p>function register($userId, $productId, $params) {<\/p>\n<p>logToFile(&#8220;classname1.class.php: register(): &#8220;, LOG_INFO_DAP);<br \/>\n$dapuser = Dap_User::loadUserById($userId);<br \/>\n$email = trim($dapuser-&gt;getEmail());<br \/>\n$username = trim($dapuser-&gt;getUser_name());<br \/>\n$firstname = trim($dapuser-&gt;getFirst_name());<br \/>\n$lastname = trim($dapuser-&gt;getLast_name());<\/p>\n<p>$data = explode(&#8220;:&#8221;,$params);<\/p>\n<p>}<\/p>\n<p>function unregister($userId, $productId, $params)<br \/>\n{<br \/>\nlogToFile(&#8220;classname1.class.php: register(): &#8220;, LOG_INFO_DAP);<\/p>\n<p>$dapuser = Dap_User::loadUserById($userId);<br \/>\n$email = trim($dapuser-&gt;getEmail());<\/p>\n<p>$data = explode(&#8220;:&#8221;,$params);<\/p>\n<p>}<\/p>\n<p>}<br \/>\n?&gt;<\/p>\n<p><strong>NOTE: <\/strong><\/p>\n<p><strong>You MUST have same name methods (called register() and unregister() ) and the exact method signature as you see above.<\/strong><\/p>\n<p>You can\u00a0 call other methods\/functions from register\/unregister and\/or<\/p>\n<p>You can call 3rd party APIs from register\/unregister methods and\/or<\/p>\n<p>You can include other class files.<\/p>\n<p>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.<\/p>\n<p><strong>That&#8217;s it. <\/strong><\/p>\n<p>You can add a test user to a product in DAP (via dap admin -&gt; add users) and see if things work as expected.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[60,59,85,27,20,24,47,26],"tags":[],"_links":{"self":[{"href":"http:\/\/digitalaccesspass.com\/doc\/wp-json\/wp\/v2\/posts\/1321"}],"collection":[{"href":"http:\/\/digitalaccesspass.com\/doc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/digitalaccesspass.com\/doc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/digitalaccesspass.com\/doc\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/digitalaccesspass.com\/doc\/wp-json\/wp\/v2\/comments?post=1321"}],"version-history":[{"count":23,"href":"http:\/\/digitalaccesspass.com\/doc\/wp-json\/wp\/v2\/posts\/1321\/revisions"}],"predecessor-version":[{"id":1332,"href":"http:\/\/digitalaccesspass.com\/doc\/wp-json\/wp\/v2\/posts\/1321\/revisions\/1332"}],"wp:attachment":[{"href":"http:\/\/digitalaccesspass.com\/doc\/wp-json\/wp\/v2\/media?parent=1321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/digitalaccesspass.com\/doc\/wp-json\/wp\/v2\/categories?post=1321"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/digitalaccesspass.com\/doc\/wp-json\/wp\/v2\/tags?post=1321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}