I would like to send api notification in json format. Read https://s2member.com/kb-article/building-an-api-notification-handler-webhook/ but i am not so good in converting php to json. How to return all user information in json. thanks
API notification in JSON format
Some how i achieve to encode json of user data in s2member
But now no idea of how when registration or payment etc occur, send this json in a url forexample (http://123.456.78.58:44005)/singleMethodName=JSONService___myfunctionofuserRegisteration. Any pro in here to solve my problem? i will be grateful. Thanks
The API Notifications that s2Member sends do not offer a JSON format option. All data is sent as a normal HTTP GET or POST request, which you can intercept if you’d like, and then convert the format.
<?php
$data_from_api_notification = $_REQUEST;
$json = json_encode($data_from_api_notification);
See also: Building an API Notification Handler (i.e., a Webhook) Using an MU Plugin file in WordPress
Thanks jaswsinc for your answer. If i am not wrong you mean in mu-plugin s2_registration_notification.php should look like this.
<?php
add_action('init', 's2_registration_notification');
function s2_registration_notification()
{
$user_detail[]= array(
"user_login" => get_user_field ("user_login"),
"user_email" => get_user_field ("user_email"),
"first_name" => get_user_field ("first_name"),
"last_name" => get_user_field ("last_name"),
"full_name" => get_user_field ("full_name"),
"display_name" => get_user_field ("display_name"),
"company_name" => get_user_field ("user_comp"),
"user_cifiscale" => get_user_field ("user_cfisc"),
"partita_iva" => get_user_field ("p_iva"),
"coupon_code" => get_user_field ("s2member_coupon_codes")
);
$json = wp_json_encode($user_detail, JSON_PRETTY_PRINT);
echo $json;
}
If so then what url can i insert in notification url field. If i am completely wrong, how can i reach to that point.
Thanks for your tips, they help us a lot.
or like this
<?php
add_action('init', 's2_registration_notification');
function s2_registration_notification()
{
if(isset($_POST['user_login'], $_POST['user_email'], $_POST['first_name'], $_POST['last_name'], $_POST['full_name'], $_POST['display_name']))
{
$user_login = (string)$_POST['user_login'];
$user_email = (string)$_POST['user_email'];
$first_name = (string)$_POST['first_name'];
$last_name = (string)$_POST['last_name'];
$full_name = (string)$_POST['full_name'];
$display_name = (string)$_POST['display_name'];
$user_login = get_user_field ("user_login");
$user_email = get_user_field ("user_email");
$first_name = get_user_field ("first_name");
$last_name = get_user_field ("last_name");
$full_name = get_user_field ("full_name");
$display_name = get_user_field ("display_name");
$user_detail[]= array($user_login, $user_email, $first_name, $last_name, $full_name, $display_name);
$json = wp_json_encode($user_detail, JSON_PRETTY_PRINT);
echo $json;
}
}
I am pretty confused with posting json through the url i have to insert in s2member’s notification field.
You’re on the right track, but once you receive the data, convert it to JSON, then you need to forward the JSON-formatted data to whatever URL needs to receive it; i.e., the step you’re missing looks something like this in code.
// ... what you have, then...
wp_remote_post('http://example.com/url/that/needs/JSON', [
'headers' => ['content-type' => 'application/json'],
'body' => $json,
]);
Tried a lot but still I am receiving nothing. While using the method mentioned in KB articles, i just receive (signup, registration and payment notification)non json format ONLY ONCE and the SECOND time i fill the form and submit it with totally different data i receive NOTHING. Yes my server respond 100% even on updates and it can receive any type of request.
If possible a working example would be great. Thanks
Please note: i changed the actual address of “website” "myip"and “server” for privacy reason and name those in the log files mywebsite & serverip & myip.
I just grab a portion of my log file name s2-http-api-debig.log :
LOG ENTRY: Wed Mar 8th, 2017 @ precisely 8:46 pm UTC
PHP v5.6.30 :: WordPress v4.7.3 :: s2Member v170221 :: s2Member Pro v170221
Memory 42.06 MB :: Real Memory 42.25 MB :: Peak Memory 42.16 MB :: Real Peak Memory 42.25 MB
www.mywebsite.net/?s2member_paypal_notify=1
User-Agent: s2Member v170221; http://www.mywebsite.net
Array
(
[state] => response
[transport_class] => Requests
[args] => Array
(
[method] => GET
[timeout] => 5
[redirection] => 5
[httpversion] => 1.1
[user-agent] => s2Member v170221; http://www.mywebsite.net
[reject_unsafe_urls] =>
[blocking] => 1
[headers] => Array
(
)
[cookies] => Array
(
)
[body] =>
[compress] =>
[decompress] => 1
[sslverify] => 1
[sslcertificates] => /web/htdocs/www.mywebsite.net/home/wp-includes/certificates/ca-bundle.crt
[stream] =>
[filename] =>
[limit_response_size] =>
[s2member] => 170221
[_redirection] => 5
)
[url] => http://serverip:49005/SingleMethodName=DomainManagementStripeService___DomainRegistration?s2_payment_notification=yes&user_id=&user_piva=&first_name=peter&user_ip=myip&subscr_id=sub_AFh3wzGRtSal1v
[response] => WP_Error Object
(
[errors] => Array
(
[http_request_failed] => Array
(
[0] => cURL error 28: Connection timed out after 5001 milliseconds
)
)
[error_data] => Array
(
)
)
)
Hi Jason,
Recently i realized that the notification is not working at all and i created a thread too. Api notification url is not working at all
Please take some time out of your precious time and help us in this issue.