405 Not Allowed through SSL - PHP Ajax Mailchimp API Nginx - php

I've built a html web form that collects subscriber info through AJAX and process thru a php script, and send to mailchimp.
Form submission worked fine until SSL was added to the domain. I keep on getting 405 Not Allowed when I try to submit the form. And I couldn't figure out what went wrong. I have a feeling this has to do with the Nginx server configuration, but I'm no expert in this area and don't know where to look.
After some research, I came across a few posts discussing how 'Nginx does not allow POST to static content' which I'm not sure if it applies to my case because this issue only occurred after ssl was added (I'm using Nginx + php on Alicloud). Below are my codes:
<section id="mailchimp">
<div class="container">
<form id="form" method="POST" action="action.php">
<p class="sub-lead">* indicates required.</p>
<input type="email" name="EMAIL" id="form_email" placeholder="Email Address *" required="required">
<input type="text" name="FNAME" id="form_fname" placeholder="First Name *" required="required">
<input type="text" name="LNAME" id="form_lname" placeholder="Last Name *" required="required">
<input type="text" name="PHONE" id="form_phone" placeholder="Phone Number *" required="required">
<select name="ROOM" id="room">
<option value="" disabled selected>I am interested in...</option>
<option value="1 Bedroom">1 Bedroom</option>
<option value="2 Bedroom">2 Bedroom</option>
<option value="3 Bedroom">3 Bedroom</option>
</select>
<input type="checkbox" id="opt-in" name="opt-in" value="opt-in" required="required">Yes, I want to receive current & future projects info from the development team & its affiliates.<br>
<input type="submit" value="submit" id="submit">
<div id="signup-result"></div>
</form>
</div>
</section>
php
<?php
//fill in these values for with your own information
$api_key = 'xxxxxxxx-us16';
$datacenter = 'us16';
$list_id = 'xxxxxxxxx;
$email = $_POST['email'];
$fname = $_POST['first_name'];
$lname = $_POST['last_name'];
$phone = $_POST['phone'];
$room = $_POST['room'];
$country = $_POST['country'];
$status = 'subscribed';
if(!empty($_POST['status'])){
$status = $_POST['status'];
}
$url = 'https://'.$datacenter.'.api.mailchimp.com/3.0/lists/'.$list_id.'/members/';
$username = 'apikey';
$password = $api_key;
$data = array("email_address" => $email,
"status" => $status,
"merge_fields" => array(
"FNAME" => $fname,
"LNAME" => $lname,
"PHONE" => $phone,
"ROOM" => $room,
)
);
$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$api_key");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
?>
here's the ajax
// Mailchimp Form
$('#form').submit(function(e){
e.preventDefault();
//grab attributes and values out of the Form
var data = {
email: $('#form_email').val(),
first_name: $('#form_fname').val(),
last_name: $('#form_lname').val(),
phone: $('#form_phone').val(),
room: $('#room').val(),
};
var endpoint = $(this).attr('action');
//make the ajax request
$.ajax({
method: 'POST',
dataType: "json",
url: endpoint,
data: data
}).done(function(data){
if(data.id){
//successful adds will have an id attribute on the object
window.location='thankyou.html'
} else if (data.title == 'Member Exists') {
//MC wil send back an error object with "Member Exists" as the title
alert('It looks like you have already signed up with this email address. If you have any questions, please feel free to contact us by email or phone.');
} else {
//something went wrong with the API call
alert('Oops, we could not reach server at the moment, please try again later.');
}
}).fail(function(){
//the AJAX function returned a non-200, probably a server problem
alert('oh no, there has been a problem');
});
});

Related

MailChimp Add Subscriber using API 3.0 PHP

I am trying to add a php file that adds a new subscriber to my MailChimp list. Here is my form that SHOULD trigger the php file to add the new subscriber:
<form action="/scripts/freemonth_action.php" class="email_form_freemonth" method="post">
<h3>Get your first month free</h3>
<div class="form-group customised-formgroup"> <span class="icon-user"></span>
<input type="text" name="full_name" class="form-control" placeholder="Name">
</div>
<div class="form-group customised-formgroup"> <span class="icon-envelope"></span>
<input type="email" name="email" class="form-control" placeholder="Email">
</div>
<!--<div class="form-group customised-formgroup"> <span class="icon-telephone"></span>
<input type="text" name="phone" class="form-control" placeholder="Phone (optional)">
</div>-->
<div class="form-group customised-formgroup"> <span class="icon-laptop"></span>
<input type="text" name="website" class="form-control" placeholder="Website (optional)">
</div>
<!--<div class="form-group customised-formgroup"> <span class="icon-bubble"></span>
<textarea name="message" class="form-control" placeholder="Message"></textarea>
</div>-->
<div>
<br>
<button style="margin: 0 auto" type="submit" class="btn btn-fill full-width">GET FREE MONTH<span class="icon-chevron-right"></span></button>
</div>
</form>
And here is freemonth_action.php:
<?php
session_start();
if(isset($_POST['submit'])){
$name = trim($_POST['full_name']);
$email = trim($_POST['email']);
if(!empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL) === false){
// MailChimp API credentials
$apiKey = '6b610769fd3353643c7427db98d43ad6-us16';
$listID = '0cf013d1d9';
// MailChimp API URL
$memberID = md5(strtolower($email));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listID . '/members/' . $memberID;
// member information
$json = json_encode([
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => [
'NAME' => $name,
]
]);
// send a HTTP POST request with curl
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo json_encode($result);
// store the status message based on response code
if ($httpCode == 200) {
$_SESSION['msg'] = '<p style="color: #34A853">You have successfully subscribed to CodexWorld.</p>';
} else {
switch ($httpCode) {
case 214:
$msg = 'You are already subscribed.';
break;
default:
$msg = 'Some problem occurred, please try again.';
break;
}
$_SESSION['msg'] = '<p style="color: #EA4335">'.$msg.'</p>';
}
}else{
$_SESSION['msg'] = '<p style="color: #EA4335">Please enter valid email address.</p>';
}
}
I'm not even sure how to debug this, because when i do echo $result (or anything like that) I do not see anything on the page or logged to the console. I'm also open to any suggestions that use javascript as long as it is still the 3.0 API.
Your subscription code works fine. The reason you aren't seeing any result is because isset($_POST['submit']) looks for an element with the name 'submit' rather than the type 'submit'. Just add the name attribute to your button, and it should work for you:
<button style="margin: 0 auto" type="submit" name="submit" class="btn btn-fill full-width">GET FREE MONTH<span class="icon-chevron-right"></span></button>
Also, you should keep the API key secret so other people can't access your MailChimp account through the API. I'd recommend disabling your current key and creating a new one. See MailChimp's knowledgebase article about API Keys for more details.

(PHP) Web form inserting blank values into the database! Error - array(1) { [“g-recaptcha-response”]=> string(484)-

When sending information from my web form, it inserts blank values into the database. The auto increments on the ID work fine. When performing an Var Dump $_POST, I get this response:
array(1) { ["g-recaptcha-response"]=> string(484) + random letters and numbers
I am trying to pass three values into my database from the user. First Name. Last Name and Email. It checks the values on my web site and looks like the Google Recaptcha V2 is working the way it was intended. I think it has something to do with the Recaptcha PHP script is not passing it to my insert PHP script.
Any Ideas? Thanks for taking the time to help me out.
PHP:
<?php
function post_captcha($user_response) {
$fields_string = '';
$fields = array(
'secret' => '',
'response' => $user_response
);
foreach($fields as $key=>$value)
$fields_string .= $key . '=' . $value . '&';
$fields_string = rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
// Call the function post_captcha
$res = post_captcha($_POST['g-recaptcha-response']);
if (!$res['success']) {
// What happens when the CAPTCHA wasn't checked
echo '<p>Please Check the Security CAPTCHA Box.</p><br>';
} else {
// If CAPTCHA is successfully completed...
// Paste mail function or whatever else you want to happen here!
$dbhost = "localhost";
$dbname = "";
$dbusername = "";
$dbpassword = "";
try {
$link = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
$link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement = $link->prepare("INSERT INTO MailV2(Fname, Lname, Email) VALUES(:Fname, :Lname, :Email)");
$FirstName = $_POST['Fname'];
$LastName = $_POST['Lname'];
$Email = $_POST['Email'];
$statement->execute(array(
":Fname" => "$FirstName",
":Lname" => "$LastName",
":Email" => "$Email"));
// Echo Successful attempt
echo "<p Data added to database.</p></br></br>";
}
catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>
HTML:
<article class="contact-form">
<form action="" method="POST">
<div class="col-md-5 col-md-offset-1 contact-form-left">
<input class="Fname" type="text" placeholder="FIRST NAME*">
<input class="Lname" type="text" placeholder="LAST NAME*">
<input class="Email" type="email" placeholder="EMAIL*">
</div>
<div class="col-md-5 contact-form-right text-right">
<div class="g-recaptcha" data-sitekey=""></div>
<br>
<input type="submit" class="submit-btn" value="Subscribe">
</div>
</form>
</article>
In your html form, the name and email fields don't have a name attribute so they aren't included in the response.
Thanks KAF, I just realize that and fix it. I was so fixed on my php, I didn't notice it until I posted it here. It always the simple things.
Fixed HTML:
<article class="contact-form">
<form action="" method="POST">
<div class="col-md-5 col-md-offset-1 contact-form-left">
<input name="Fname" type="text" placeholder="FIRST NAME*">
<input name="Lname" type="text" placeholder="LAST NAME*">
<input name="Email" type="email" placeholder="EMAIL*">
</div>
<div class="col-md-5 contact-form-right text-right">
<div class="g-recaptcha" data-sitekey=""></div>
<br>
<input type="submit" class="submit-btn" value="Subscribe">
</div>
</form>
</article>

MailChimp group options select in php

I tried to find the answer for the last 5 hours but I finally caved in and am reaching out for help.
Basically, this code worked great until I needed to select a group option. I'm not sure if I'm creating my interests array properly, I may have to use 'merge_vars' but really would like some guidance before I spend another 5 hours blindly walking into walls.
Note for my group name I've been using the entire string "group[3117]"
Action.php
<?php
session_start();
if(isset($_POST['submit'])){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$interest = $_POST['group[3117]'];
if(!empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL) === false){
// MailChimp API credentials
$apiKey = '+ insert api key here +';
$listID = 'insert list id';
$interest = 'insert group name'; // YOUR INTEREST/GROUP ID
// MailChimp API URL
$memberID = md5(strtolower($email));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listID . '/members/' . $memberID;
// member information
$json = json_encode([
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => [
'FNAME' => $fname,
'LNAME' => $lname
],
'interests' => array(
$interest => true
),
]);
// send a HTTP POST request with curl
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// store the status message based on response code
if ($httpCode == 200) {
$_SESSION['msg'] = '<p style="color: #34A853">You have successfully subscribed to CodexWorld.</p>';
} else {
switch ($httpCode) {
case 214:
$msg = 'You are already subscribed.';
break;
default:
$msg = 'Some problem occurred, please try again.';
break;
}
$_SESSION['msg'] = '<p style="color: #EA4335">'.$msg.'</p>';
}
}else{
$_SESSION['msg'] = '<p style="color: #EA4335">Please enter valid email address.</p>';
}
}
// redirect to homepage
header('location:index.php');
Index.php
<?php session_start(); // place it on the top of the script ?>
<?php
$statusMsg = !empty($_SESSION['msg'])?$_SESSION['msg']:'';
unset($_SESSION['msg']);
echo $statusMsg;
?>
<form method="post" action="action.php">
<p><label>First Name: </label><input type="text" name="fname" /></p>
<p><label>Last Name: </label><input type="text" name="lname" /></p>
<p><label>Email: </label><input type="text" name="email" /></p>
<p><select name="group[3117]" class="REQ_CSS" id="mce-group[3117]">
<option value=""></option>
<option value="1">Los Angeles</option>
<option value="2">Seattle</option>
<option value="4">Portland</option> </p>
<p><input type="submit" name="submit" value="SUBSCRIBE"/></p>
</form>
Here's the solution, there's a lot of manual data entry but it works, if someone has an easier method please let me know.
Enter the MailChimp API playground. Select your list / subresources / interest-categories / interest name / subresources / interests / response . scroll down and there will be a unique "id" for interest. (ignore category id)
Here is the code, credit goes Mukesh Chapegan and CodexWorld
Name this page Action.php
<?php
$email = $_POST['email'];
$memberHash = md5($email);
$first_name = $_POST['fname'];
$last_name = $_POST['lname'];
$interest = $_POST['location'];
$api_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // YOUR API KEY
$server = 'us14.'; //last part of ur api key
$list_id = 'XXXXXXX'; // YOUR LIST ID
$auth = base64_encode( 'user:'.$api_key );
$data = array(
'apikey' => $api_key,
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => $first_name,
'LNAME' => $last_name
),
'interests' => array(
$interest => true
),
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'api.mailchimp.com/3.0/lists/'.$list_id.'/members/'.$memberHash);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic '.$auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$result = curl_exec($ch);
$result_obj = json_decode($result);
echo $result_obj->status;
echo '<br>';
echo '<pre>'; print_r($result_obj); echo '</pre>';
?>
Here is the HTML form. name this index.php
Note I named the select element to location and the option values to the interest id I obtained through the API playground.
<?php session_start(); // place it on the top of the script ?>
<?php
$statusMsg = !empty($_SESSION['msg'])?$_SESSION['msg']:'';
unset($_SESSION['msg']);
echo $statusMsg;
?>
<form method="post" action="action.php">
<p><label>First Name: </label><input type="text" name="fname" /></p>
<p><label>Last Name: </label><input type="text" name="lname" /></p>
<p><label>Email: </label><input type="text" name="email" /></p>
<p> <select name="location" class="REQ_CSS" id="mce-group[3117]">
<option value=""></option>
<option value="f3eb68268d">Los Angeles</option>
<option value="3204c60199">Seattle</option>
<option value="3c5b8d638a">Portland</option> </p>
</select>
<p><input type="submit" name="submit" value="SUBSCRIBE"/></p>
</form>
If this answer helps please upvote so it's easier to find. I looked for this solution for a very very long time and found a lot of questions but few answers.

Linking Mailchimp to Sign-Up Boxes

I am linking an e-mail sign-up and a post code (UK English for zip code) input box (see html code below) to an existing Mailchimp e-mail list. I have taken out the $apiKey, $listId and $submit_url identifiers from the code below. I have been able to successfully link the Mailchimp list to the e-mail input (so that e-mail address are populated when they are input in the Mailchimp list but I cannot figure out how to get post codes to automatically update in mailchimp list when they are input).
I am relatively new to php and would be so grateful for any help.
<div class="subscribe">
<form method="post" action="bokacsubscribe.php" role="form">
<input type="email" placeholder="Enter your e-mail address..." class="subscribe-input" name="email" style="margin-bottom: 10px;">
<form method="post" action="bokacsubscribe.php" role="form">
<input type="email" placeholder="Enter your postcode" class="subscribe-input" name="postcode" style="margin-bottom: 10px;">
<button type="submit" class="btn btn-subscribe success" style="border-radius:120px;background-color:rgb(241,174,200);border:1px solid rgb(241,174,200)"><b>Send</b></button>
<input type="hidden" name="referr" id="referr"/>
</form>
</div>
</div>
<?php
// Credits: https://gist.github.com/mfkp/1488819
session_cache_limiter('nocache');
$apiKey = ''; - // How get your Mailchimp API KEY - http://kb.mailchimp.com/article/where-can-i-find-my-api-key
$listId = ''; - // How to get your Mailchimp LIST ID - http://kb.mailchimp.com/article/how-can-i-find-my-list-id
$submit_url = ""; - // Replace us2 with your actual datacenter
$double_optin = false;
$send_welcome = false;
$email_type = 'html';
$email = $_POST['email'];
$merge_vars = array( 'YNAME' => $_POST['yname'] );
$data = array(
'email_address' => $email,
'apikey' => $apiKey,
'id' => $listId,
'double_optin' => $double_optin,
'send_welcome' => $send_welcome,
'merge_vars' => $merge_vars,
'email_type' => $email_type
);
$payload = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $submit_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($payload));
$result = curl_exec($ch);
curl_close ($ch);
$data = json_decode($result);
if ($data->error) {
// do whatever you do on failure here
} else {
// do whatever you do on success here
$arrResult = array ('response'=>'success');
}

how to create wallet in mangopay?

I want to integrate mangopay using php and i am using following link as ref:
http://docs.mangopay.com/api-references/wallets/
but i can't able to do that because if i am use any options like create wallet or any other then it will try to create new user even i am trying to use any other option.
following is code which i used for create new wallet in mangopay:
<h2>Create User</h2>
<form action="https://api.sandbox.mangopay.com/v2/clients" method="post">
<input name="ClientId" id="ClientId" value="<cust's sandbox id>" /><br>
<input name="Email" id="Email" value="" /><br>
<input name="FirstName" id="FirstName" value="" /><br>
<input name="LastName" id="LastName" value="" /><br>
<input name="Birthday" id="Birthday" value="<?php echo strtotime("1988-03-19");?>" /><br>
<input name="Nationality" id="Nationality" value="DE" /><br>
<input name="CountryOfResidence" id="CountryOfResidence" value="DE" /><br>
<input type="submit" value="submit">
</form>
<h2>Create Wallet</h2>
<form action="https://api.sandbox.mangopay.com/v2/clients" method="post">
<input name="ClientId" id="ClientId" value="<cust's sandbox id>" /><br>
<input name="Owners" id="Owners" value="<cust's sandbox id>" /><br>
<input name="Email" id="Email " value="mddipen" /><br>
<input name="Description" id="Description" value="" /><br>
<input name="Currency" id="Currency" value="EUR" /><br>
<input type="submit" value="submit">
</form>
define('MANGOPAY_REQUEST_URL','https://api.sandbox.mangopay.com/v2/');
define('MANGOPAY_ADMIN_ID','Admin ID');
define('CURL_AUTH_HEADER','Authentication Key');
function processCurlJsonrequest($parseUrl, $fieldString) { //Initiate cURL request and send back the result
$URL=MANGOPAY_REQUEST_URL.$parseUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic ".CURL_AUTH_HEADER, "Content-Type: application/json; charset=utf-8","Accept:application/json, text/javascript, */*; q=0.01"));
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fieldString));
curl_setopt($ch, CURLOPT_POST, 1);
$resulta = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
return $resulta;
}
$data = array(
"FirstName" => $first_name,
"LastName" => $last_name,
"Address" => "",
"Birthday" => $birthdatestr,
"Nationality" => $nationality,
"CountryOfResidence" => $CountryOfResidence,
"Occupation" => "",
"IncomeRange" => "",
"ProofOfIdentity" => null,
"ProofOfAddress" => null,
//"PersonType" => "NATURAL",
"Email" => $email,
"Tag" => ""
);
$parseUrl=MANGOPAY_ADMIN_ID.'/users/natural';
$response= processCurlJsonrequest($parseUrl, $data);
$arrResponse=json_decode($response);
$mangopay_userId = $arrResponse->Id;
$data_mangopay = array(
"Owners" => array($mangopay_userId),
"Description" => "A very cool wallet",
"Currency" => "EUR",
"Tag" => ""
);
$parseUrl=MANGOPAY_ADMIN_ID.'/wallets';
$response_mangopay= processCurlJsonrequest($parseUrl, $data_mangopay);
$arrResponse_mangopay=json_decode($response_mangopay);
$mangopay_walletId = $arrResponse_mangopay->Id;
I don't quite understand what the problem is - are you trying to create a new user AND wallet on the same page? If so, that isn't possible - you'll have to get the UserId first to then supply for the wallet creation.
Also, if you're not yet using the new PHP SDK, I suggest you do as it's really comprehensive. However the reference/docs are pretty dire but I found this site which is very useful.
Using the SDK and to solve your problem if I've understood it correctly:
//Create an instance of MangoPayApi SDK
$mangoPayApi = new \MangoPay\MangoPayApi();
$mangoPayApi->Config->ClientId = MangoPayDemo_ClientId;
$mangoPayApi->Config->ClientPassword = MangoPayDemo_ClientPassword;
$mangoPayApi->Config->TemporaryFolder = MangoPayDemo_TemporaryFolder;
//Build the parameters for the request
$User = new MangoPay\User();
$User->PersonType = "NATURAL";
$User->FirstName = "blabla";
$User->LastName = "blabla";
$User->Address = "blabla";
$User->Birthday = 1396886568;
$User->Nationality = "NZ";
$User->CountryOfResidence = "ES";
$User->Email = "hello#example.com";
//Send the request
$createdUser = $mangoPayApi->Users->Create($User);
//Now for the wallet
$Wallet = new MangoPay\Wallet();
$Wallet->Owners = array($createdUser->Id);
$Wallet->Description = "blabla";
$Wallet->Currency = "GBP";
//Send the request
$createdWallet = $mangoPayApi->Wallets->Create($Wallet);
//store this in your DB: $createdWallet->Id

Categories