【发布时间】:2015-06-24 15:35:12
【问题描述】:
我试图尽可能简化这一点。 当用户点击提交按钮时,会发生以下情况:
- 验证信用卡/到期日期/cvc 值是否有效
- 生成一个令牌作为输入
- token的值贴在php代码中
- 查询运行并存储值,页面被重定位
我一直能够管理到第 2 名。 我无法发布令牌的值,因此不会存储令牌值。
约束:
- 如果没有找到或可用的令牌值,我将无法运行查询
- 在生成输入令牌之前无法运行 php 脚本
- 执行 php 查询后,需要销毁令牌输入
下面是生成token的js函数:
<script type="text/javascript">
// This identifies your website in the createToken call below
Stripe.setPublishableKey('CODE');
var stripeResponseHandler = function(status, response) {
var $form = $('#payment-form');
if (response.error) {
// Show the errors on the form
$form.find('.payment-errors').text(response.error.message);
$form.find('button').prop('disabled', false);
} else {
// token contains id, last4, and card type
var token = response.id;
// Insert the token into the form so it gets submitted to the server
$form.append($('<input type="text" name="stripeToken" />').val(token));
// and re-submit
}
};
jQuery(function($) {
$('#payment-form').submit(function(e) {
var $form = $(this);
// Disable the submit button to prevent repeated clicks
$form.find('button').prop('disabled', true);
Stripe.card.createToken($form, stripeResponseHandler);
// Prevent the form from submitting with the default action
return false;
});
});
</script>
下面是php代码
if(isset($_POST['paid'])){
$course_token = $_POST['stripeToken'];
if (!empty($course_token)) {
$course_price_final = $_POST['course_price_final'];
$course_provider = $_POST['course_provider'];
$user_email = $_POST['user_email'];
$course_delivery = $_POST['course_delivery'];
$order_date = date("Y-m-d");
$insert_c = "insert into orders (course_title,course_price_final,course_provider,user_email,course_date,course_delivery,order_date,course_token)
values ('$crs_title','$course_price_final','$course_provider','$user_email','$course_date1','$course_delivery','$order_date','$course_token')";
$run_c = mysqli_query($con, $insert_c);
ob_start();
}
}
?>
提前致谢,如有任何澄清,请告诉我。
【问题讨论】:
-
您是否正在从条带中取回令牌?
-
我正在从 stripe 中检索令牌,它确实输出到输入中,因此我可以直观地看到它,我的问题在于在填充输入后获取该值并将其作为变量发布到 php 中查询可以执行
标签: javascript php jquery mysql ajax