PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Hooks for API integration?

s2Member Plugin. A Membership plugin for WordPress®.

Hooks for API integration?

Postby stefanogaruti » November 16th, 2011, 9:46 am

I'm planning to develop a (sort of) plugin to integrate S2Member with ZOHO invoice (https://invoice.zoho.com/) via ZOHO API (http://www.zoho.com/invoice/api/index.html).

As first step I would like to create a new "Customer" in ZOHO Invoice any time a new user register on S2Member. Later I'll add the possibility to create a new Invoice any time a user make a payment.

I would use the S2Member API/notification fields, but the ZOHO's API requires this actions to be POST and not GET.

Can you please point me to the equivalend action hooks for those API/notification events so I can hook in with my code?

Do you know of any other way to do this? And/or any other developer who already has done someting similar

Thank you

Stefano
User avatar
stefanogaruti
Experienced User
Experienced User
 
Posts: 11
Joined: July 26, 2010

Re: Hooks for API integration?

Postby Bruce C » November 16th, 2011, 11:46 am

Hi,

I believe you may be able to use the user_register hook to accomplish this instead of going directly through the s2Member API.

If you look, WordPress will give you the id for the new user, so all you will need to do is get the user data ( includes data from the wp_users and wp_usermeta tables ), and then populate the other fields with s2Member user meta.

Something like this:

Code: Select all
<?php
function get_s2_usermeta ($id)
   {
      //Get the user data <http://codex.wordpress.org/Function_Reference/get_userdata/>
      $user = get_userdata ($id);
      //Usermeta value for s2Member registration IP Address
      $registration_ip = get_user_meta ($id, 'wp_s2member_registration_ip');
      //usermeta value for s2Member Login Counter ( Not useful for this )
      $logins = get_user_meta ($id, 'wp_s2member_login_counter');
   }
add_action ('user_register', 'get_s2_usermeta');
?>
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Hooks for API integration?

Postby Cristián Lávaque » November 18th, 2011, 1:25 am

You could use the Notifications API with a script that GETs the notification and then POSTs it to ZOHO. Would that work for you?
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Hooks for API integration?

Postby stefanogaruti » November 18th, 2011, 6:59 am

Thanks!
Yes Cristian, it would works... but really isn't there an action hook?

An action hook for each of the notification fields/events could allow to plugins developer to extend S2Member with a lot of other application that maybe requires more tha a simple GET url

Stefano
User avatar
stefanogaruti
Experienced User
Experienced User
 
Posts: 11
Joined: July 26, 2010

Re: Hooks for API integration?

Postby Cristián Lávaque » November 21st, 2011, 2:56 am

I found "ws_plugin__s2member_before_new_user_notification". viewtopic.php?f=40&t=13011&src_doc_v=111105#src_doc_line_175

But I'll email Jason asking him about it for any tips that could help you. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Hooks for API integration?

Postby Jason Caldwell » November 21st, 2011, 2:09 pm

Thanks for the excellent questions.
As first step I would like to create a new "Customer" in ZOHO Invoice any time a new user register on S2Member. Later I'll add the possibility to create a new Invoice any time a user make a payment.

I would use the S2Member API/notification fields, but the ZOHO's API requires this actions to be POST and not GET.
I would try to stick with s2Member's API Notifications on this. You will save yourself some time and everything is better documented for this approach. Trying to use lots of Hooks in this regard can become too complex, and is subject to change slightly in future releases of s2Member.

For instance, you might use s2Member's Signup and Payment Notifications for your needs in this case. For further details, please check your Dashboard here: s2Member -> API Notifications.

The difference between GET/POST is easy to overcome. If your 3rd party service needs to receive POST data instead of GET, connect s2Member's API Notifications to a proxy script of your own, which receives the GET vars, and POSTs them to your 3rd party service in the way it needs them.

Code: Select all
<?php
$_3rd_party_service 
= /* Change this. */ "http://3rd-party-service.com/api";
$response = curlpsr ($_3rd_party_service, http_build_query (trim_deep (stripslashes_deep ($_GET))));
/*
---- Do NOT edit anything below, unless you know what you're doing. --------------------------------------------------------*/
/*
Recursive function that trims deeply.
*/
function trim_deep ($value = FALSE)
    {
        return is_array ($value) ? array_map ("trim_deep", $value) : trim ((string)$value);
    }
/*
Recursive function that strips slashes deeply.
*/
function stripslashes_deep ($value = FALSE)
    {
        return is_array ($value) ? array_map ("stripslashes_deep", $value) : stripslashes ((string)$value);
    }
/*
cURL operation for posting data and reading response.
*/
function curlpsr ($url = FALSE, $postvars = array (), $max_con_secs = 20, $max_stream_secs = 20, $headers = array ())
    {
        if (($url = trim ($url)) && ($c = curl_init ()))
            {
                if (is_array ($postvars)) /* Because cURL can't deal with complex arrays. */
                    /* Since cURL can't deal with complex arrays, we force this to a query string. */
                    $postvars = http_build_query ($postvars);
                /**/
                curl_setopt_array ($c, /* Configure options. */
                array (CURLOPT_URL => $url, CURLOPT_POST => true,/**/
                CURLOPT_CONNECTTIMEOUT => $max_con_secs, CURLOPT_TIMEOUT => $max_stream_secs, /* Initial connection & stream seconds. */
                CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $headers, CURLOPT_POSTFIELDS => $postvars,/**/
                CURLOPT_FOLLOWLOCATION => ($follow = (!ini_get ("safe_mode") && !ini_get ("open_basedir"))), CURLOPT_MAXREDIRS => (($follow) ? 5 : 0),/**/
                CURLOPT_ENCODING => "", CURLOPT_VERBOSE => false, CURLOPT_FAILONERROR => true, CURLOPT_FORBID_REUSE => true, CURLOPT_SSL_VERIFYPEER => false));
                /**/
                $o = trim (curl_exec ($c));
                /**/
                curl_close($c);
            }
        /**/
        return (!empty ($o)) ? $o : false;
    }
?>
3rd-party.zip
(991 Bytes) Downloaded 73 times

s2Member® / Hot Tip: ( s2Installs.com! )

Recommended by s2Member® Lead Developer (Jason Caldwell). Their rate for a standard installation is $125. They're highly trained. Just request their service!

Need Help? Post A New Job!

It's free. Your Job will appear here, and @ jobs.wordpress.net. It will be displayed for a period of 21 days; or until you take it off, whichever comes first. Good luck!
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Hooks for API integration?

Postby stefanogaruti » November 22nd, 2011, 3:25 am

Jason, Cristian
Thank you for your help.
I'll go this way and will let you know the results ;-)

Stefano
User avatar
stefanogaruti
Experienced User
Experienced User
 
Posts: 11
Joined: July 26, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 1 guest

cron