i'm trying to var dump the $response of my code bellow but it returns null and I don't know why...
$token = $_POST['stripeToken'];
$email = $_POST['email'];
$name = $_POST['name'];
if(filter_var($email, FILTER_VALIDATE_EMAIL) && !empty($name) &&
!empty($token)){
$ch = curl_init();
$data = [
'source' => $token,
'description' => $name,
'email' => $email
];
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.stripe.com/v1/customers',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => 'sk_test_************************',
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_POSTFIELDS => http_build_query($data)
]);
$response = json_decode(curl_exec($ch));
curl_close($ch);
var_dump($response);
die();
}
For info, the $_POST variables are in another file and I verified that are filled with the informations of the form.
Hope someone can help
Thanks in advance !
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.stripe.com/v1/customers');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "source=" . $token . "&email=" . $cEmail);
curl_setopt($ch, CURLOPT_USERPWD, 'sk_test_xxxxxxxxxx' . ':' . '');
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
$obj = json_decode($result);
curl_close($ch);
$customer = $obj->id;
You are welcome :)