/ 表格 /
<form action="submit.php" id="payment-form" method="post">
<p>
<input type="text" placeholder="Card Number" data-stripe="number">
</p>
<p>
<input type="text" placeholder="CVC" data-stripe="cvc">
</p>
<p>
<input type="text" placeholder="expire-month" data-stripe="exp-month">
<input type="text" placeholder="expire-year" data-stripe="exp-year">
</p>
<!-- Buttons -->
<button type="submit">Submit</button>
</form>
html页面中的/ 脚本 /
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"> </script>
<script src="https://js.stripe.com/v2/"> </script>
<script>
Stripe.setPublishableKey('secret_key');
$('#payment-form').submit(function(e){
$form =$(this);
$form.find('button').prop('disbled', true);
Stripe.card.createToken($form, function(status, response){
var token = response.id;
$form.append($('<input type="hidden name="stripe-token/>').val(token));
$form.get(0).submit();
});
return false;
});
</script>
/ PHP PAGE-submit.php /
<?php
include_once 'vendor/stripe/stripe-php/Stripe.php';
//secret key
Stripe::setApiKey('sk_test_key');
$token = $_POST['stripe-token'];
var_dump($token);
$customer = Stripe_Customer::create([
"card" => $token,
"description" => "paycar"
]);
?>
答案 0 :(得分:0)
我不是专家,但您不是在其中缺少两个引号吗? 以下声明。
$form.append($('<input type="hidden" name="stripe-token"/>').val(token));