所以昨天我开始玩条纹,到目前为止一直很好。我有一个三步注册表,第一个是个人信息(姓名),第二个是密码和电子邮件,第三个标签是付款(每月订阅)。我的逻辑是,如果付款成功,那么在我的最终创建帐户,如果没有,则抛出错误。
到目前为止,我的逻辑非常好,但我的问题很少。当我阅读this documentation时,我应该将客户ID存储在数据库中供以后使用,并检查订阅是否有效。在function stripeResponseHandler(status, response) {}
我console.log(response)
时,我看到令牌代码和卡片信息,但我从未看到客户对象。
function stripeResponseHandler(status, response) {
// Grab the form:
var $form = $("#registrationForm"),
formData = new FormData(),
params = $form.serializeArray();
if (response.error) { // Problem!
// Show the errors on the form:
console.log(response.error.message);
$form.find('#btn-signup').prop('disabled', false); // Re-enable submission
} else { // Token was created!
// Get the token ID:
var token = response.id;
console.log(token);
console.log(response);
// Insert the token ID into the form so it gets submitted to the server:
$form.append($('<input type="hidden" name="stripeToken">').val(token));
// Submit the form:
$.ajax({
url: $form.attr('action'),
type: 'POST',
data: $form.serialize(),
cache: false,
success: function(data) {
$("#formAlert").empty();
console.log(data);
var items = '';
$.each(data.status, function(key, val) {
items += '<li>' + val + '</li>';
$(".se-pre-con").fadeOut("slow");
});
$("#registerAlerts").append(items);
},
error: function(jqXHR, textStatus, errorThrown, data) {
$(".se-pre-con").fadeOut("slow");
console.log(jqXHR, textStatus, errorThrown, data);
}
});
}
}
$("#btn-signup").on("click", function(e) {
e.preventDefault();
$(".se-pre-con").show();
var $form = $("#registrationForm");
// Request a token from Stripe:
Stripe.card.createToken({
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);
});
<?php
header('Content-type: application/json');
require_once 'class.user.php';
require_once ('../plugins/stripe/init.php');
$errors = 0;
if ($stmt->rowCount() > 0)
{
$errors++;
$errors_query["status"][] = 'User exists';
}
if ($errors == 0)
{
try
{
$customer = StripeCustomer::create(array(
'email' => $_POST['formEmail'],
'source' => $token,
'plan' => '123456789',
"description" => "Subscription for user " . $uFirstname
));
if ($reg_user->register($email, $upass, $code, $utype, $uFirstname, $uLastname, $termAndAgreement))
{
$user_id = $reg_user->lasdID();
$family_files = $reg_user->runQuery("INSERT into user_files (user_id, file_type, file_size, file_name, file_new_name, file_path, file_cat, file_folder, date_created) VALUES (:user_id, 'X', '0', 'X', 'X', 'X', 'profilePicture', 'profilePicture', NOW())");
$family_files->bindparam(':user_id', $user_id, PDO::PARAM_STR);
$family_files->execute();
}
else
{
$errors++;
$errors_query["status"][] = 'error';
}
}
catch(Exception $e)
{
$errors++;
$errors_query["status"][] = 'Error with payment';
$e->getMessage();
}
}
if ($errors > 0)
{
echo json_encode($errors_query);
exit();
}
else
{
$errors_query["status"][] = 'user_welcome';
echo json_encode($errors_query);
exit();
}
?>
答案 0 :(得分:0)
使用自定义条纹付款表单是完全安全的。 Stripe还在他们的文档中写到了它,只要你使用Stripe.js它就是安全的。
当您使用信用卡注册任何用户时,它始终会返回条带令牌。它不会返回客户ID,也不会在此时创建客户,因此您必须调用create customer API并在其中传递上述令牌,它将使用客户ID返回客户对象。
您可以阅读有关条带创建客户API here
的信息