Javascript 条纹';无法向没有活动卡的客户收费';
这是直接从网站上下载的。 所以我遵循了教程,但我显然出了点问题。 我把它放在带有SSL的服务器上 如果这是他们的代码,那么我哪里出错了。 jquery、v2.js和stripe被正确地包括在内Javascript 条纹';无法向没有活动卡的客户收费';,javascript,php,jquery,stripe-payments,Javascript,Php,Jquery,Stripe Payments,这是直接从网站上下载的。 所以我遵循了教程,但我显然出了点问题。 我把它放在带有SSL的服务器上 如果这是他们的代码,那么我哪里出错了。 jquery、v2.js和stripe被正确地包括在内 <!DOCTYPE html> <html lang="en"> <head> <!-- Stripe.js used; fewer compliance requirements! --> <!-- Include S
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Stripe.js used; fewer compliance requirements! -->
<!-- Include Stripe.js, either in your <head> or as a direct descendant of <body>
at the end of the page -->
<script type="text/javascript" src="v2.js"></script>
<script type="text/javascript" src="development-bundle"></script>
<script type="text/javascript">
Stripe.setPublishableKey('pk_test_thenthetestkeyidontwanttoshare');
</script>
<script>
function stripeResponseHandler(status, response) {
// Grab the form:
var $form = $('#payment-form');
if (response.error) { // Problem!
// Show the errors on the form:
$form.find('.payment-errors').text(response.error.message);
$form.find('.submit').prop('disabled', false); // Re-enable submission
} else { // Token was created!
// Get the token ID:
var token = response.id;
// 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:
$form.get(0).submit();
}
};
$(function() {
var $form = $('#payment-form');
$form.submit(function(event) {
// Disable the submit button to prevent repeated clicks:
$form.find('.submit').prop('disabled', true);
// Request a token from Stripe:
Stripe.card.createToken($form, stripeResponseHandler);
// Prevent the form from being submitted:
return false;
});
});
</script>
</head>
<body>
<form action="charge.php" method="POST" id="payment-form">
<span class="payment-errors"></span>
<div class="form-row">
<label>
<span>Card Number</span>
<input type="text" size="16" data-stripe="number">
</label>
</div>
<div class="form-row">
<label>
<span>Expiration (MM/YY)</span>
<input type="text" size="2" data-stripe="exp_month">
</label>
<span> / </span>
<input type="text" size="4" data-stripe="exp_year">
</div>
<div class="form-row">
<label>
<span>CVC</span>
<input type="text" size="3" data-stripe="cvc">
</label>
</div>
<div class="form-row">
<label>
<span>Billing Zip</span>
<input type="text" size="5" data-stripe="address_zip">
</label>
</div>
<input type="submit" class="submit" value="Submit Payment">
</form>
</body>
</html>
<?php
include('stripe/init.php');
\Stripe\Stripe::setApiKey("sk_test_otherkeyidontwanttoshare");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
// Create a Customer
$customer = \Stripe\Customer::create(array(
"source" => $token,
"description" => "Donation customer")
);
// Charge the Customer instead of the card
\Stripe\Charge::create(array(
"amount" => 1000, // Amount in cents
"currency" => "usd",
"customer" => $customer->id)
);
?>
Stripe.setPublishableKey('pk_test_then testkeyindwanttoshare');
函数stripeResponseHandler(状态、响应){
//抓取表格:
var$form=$(“#付款单”);
if(response.error){//问题!
//在表单上显示错误:
$form.find('.payment errors').text(response.error.message);
$form.find('.submit').prop('disabled',false);//重新启用提交
}否则{//令牌已创建!
//获取令牌ID:
var token=response.id;
//将令牌ID插入表单,以便将其提交到服务器:
$form.append($('').val(标记));
//提交表格:
$form.get(0.submit();
}
};
$(函数(){
var$form=$(“#付款单”);
$form.submit(函数(事件){
//禁用“提交”按钮以防止重复单击:
$form.find('.submit').prop('disabled',true);
//从Stripe请求令牌:
Stripe.card.createToken($form,stripeResponseHandler);
//阻止提交表单:
返回false;
});
});
卡号
有效期(年月日)
/
CVC
计费拉链
它给了我这个错误:
致命错误:未捕获异常“Stripe\error\Card”,在/home3/blueman/public_html/assistforlife.com/Stripe/lib/apirector.php:114从API请求“req_9SlHeDVEeYFup4”中显示消息“无法向没有活动卡的客户收费”堆栈跟踪:
#0/home3/blueman/public_html/assistforlife.com/stripe/lib/aprequestor.php(266):stripe\aprequestor->handleappierror(“{\n”错误):{\n...402,数组,数组)
#1/home3/blueman/public_html/assistforlife.com/stripe/lib/aprequestor.php(65):stripe\aprequestor->_解释响应(“{\n”错误):{\n...402,数组)
#2/home3/blueman/public_html/assistforlife.com/stripe/lib/apirource.php(120):stripe\aprequestor->request('post','/v1/charges',Array,Array)
#3/home3/blueman/public_html/assistforlife.com/stripe/lib/apirource.php(160):stripe\apirource::_staticRequest('post','/v1/charges',Array,NULL)
#4/home3/blueman/public_html/assistforlife.com/stripe/lib/Charge.php(73):stripe\apirource::u create(数组,NULL) #第114行的5/home3/blueman/public_html/assistforlife.com/charge.ph/home3/blueman/public_html/assistforlife.com/stripe/lib/apirector.php 我写了自己的代码,上面说我的卡的值为“空”
我借用别人的代码重新编写了它,它发布了客户信息,但没有发布任何收费信息。在服务器端PHP代码中,
$token
必须具有null
值,因此创建客户时没有支付来源。然后,当您尝试使用它创建收费时,请求失败,返回“无法向没有活动卡的客户收费”
您表单的代码看起来正确,因此我不确定为什么$token
为空。我建议您使用浏览器的开发工具,确保Stripe.js创建的令牌ID(“tok…”
)确实作为stripeToken
POST参数发送
在一个不相关的注释中,根据这一行:
<script type="text/javascript" src="v2.js"></script>
看起来您正在本地托管Stripe.js。请注意,为了兼容PCI,您必须使用托管在Stripe自己的服务器上的版本,位于https://js.stripe.com/v2/