What am I doing wrong? AJAX success appears not to be receiving anything at all as none of the three alerts are shown. The process works, except I do not get any response
jQuery.ajax({
type: 'POST',
url: 'https://xxxxxxxxxxx.com/charge.php',
data: {
tokenid: token.id,
email: customer_email,
amount: amount,
description: customer_first_name + ' ' + customer_surname + ' | ' + reference
},
dataType: 'json',
success: function(response) {
alert(response);
if (response == "OK") {
alert('Payment successfully made! ');
} else {
alert('Payment could not be processed. Please try again.');
location.reload();
}
}
});
<?php
require_once('./stripe/config.php');
$token = $_POST['tokenid'];
$email = $_POST['email'];
$amount = $_POST['amount'] ;
$description = $_POST['description'] ;
$err = 'OK' ;
$customer = \Stripe\Customer::create(array(
'email' => $email,
'source' => $token
));
try {
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $amount,
'currency' => 'GBP',
'description' => $description
));
} catch(\Stripe\Error\Card $e) {
$err = "Declined - $e";
}
function response() {
global $err;
print $err ;
return $err;
}
exit response() ;
?>
Please help as this is driving me mad.