要扩展 @colinm ,
您将卡片信息发送到创建令牌并将其返回到表单提交位置的条带。
// Boom! We passed the basic validation, so request a token from Stripe:
Stripe.createToken({
number: cardNumber,
cvc: cardCVC,
exp_month: $('#expiration-month').val(),
exp_year: $('#expiration-year').val()
}, stripeResponseHandler);
// Prevent the default submit action on the form
return false;
之后,您可以使用令牌进行收费或客户
// Get all the values from the form
$token = $_POST['stripeToken'];
$email = $_POST['email'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$price = $_POST['price'];
并且不要忘记在收费/客户之前的某个地方设置 api 密钥!
$trialAPIKey = "your_Secret_testkey"; // These are the SECRET keys!
$liveAPIKey = "your_Secret_Livekey";
Stripe::setApiKey($trialAPIKey); // Switch to change between live and test environments
在第二种形式之后,您应该让它返回到成功页面(使用 try/catch 循环来处理错误,并在这些之外重定向成功)