Javascript 如何解决PHP中未定义的索引:stripeToken?
我犯了这个错误,对此我没有任何线索,我试图整理这些东西,尝试了很多东西,但都没有效果。请检查以下错误: 注意:未定义索引:stripeToken inJavascript 如何解决PHP中未定义的索引:stripeToken?,javascript,php,jquery,laravel,stripe-payments,Javascript,Php,Jquery,Laravel,Stripe Payments,我犯了这个错误,对此我没有任何线索,我试图整理这些东西,尝试了很多东西,但都没有效果。请检查以下错误: 注意:未定义索引:stripeToken in /第42行opt/lampp/htdocs/fullbrick/thankYou.php无效致命错误: 未捕获条带\Error\InvalidRequest:必须提供源或客户。 在/opt/lampp/htdocs/fullbrick/stripe-php/lib/apirector.php:181 从API请求'req_cuGvSG7abb9b
/第42行opt/lampp/htdocs/fullbrick/thankYou.php无效致命错误:
未捕获条带\Error\InvalidRequest:必须提供源或客户。
在/opt/lampp/htdocs/fullbrick/stripe-php/lib/apirector.php:181
从API请求'req_cuGvSG7abb9bzS'堆栈跟踪:#0
/opt/lampp/htdocs/fullbrick/stripe-php/lib/apirector.php(144):
条带\ApiRequestor::_specificAPIError('{\n“error”):{\n...400,
数组,数组,数组)#1
/opt/lampp/htdocs/fullbrick/stripe-php/lib/apirector.php(430):
条带\APIRestor->handleErrorResponse(“{\n”错误):{\n...400, 数组,数组)#2
/opt/lampp/htdocs/fullbrick/stripe-php/lib/apirector.php(97):
条带\APIRestor->\u解释响应('{\n“错误”:{\n...,400, 数组)#3
/opt/lampp/htdocs/fullbrick/stripe-php/lib/ApiOperations/Request.php(56):
Stripe\apirector->request('post','/v1/charges',数组,数组)#4
/opt/lampp/htdocs/halfdrink/stripe-php/lib/ApiOperations/Create.php(23):
条带\ApiResource::_staticRequest('post','/v1/charges',数组,NULL)
5/opt/lampp/htdocs/fullbrick/thankYou.php(53):Stripe\Charge::create(Array)#6
{main}in /opt/lampp/htdocs/fullbrick/stripe php/lib/apirector.php联机
181 代码是:
<script>
// Errors For Stripe Payment Card Check
card.addEventListener('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
// Create a token or display an error when the form is submitted.
var form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
event.preventDefault();
stripe.createToken(card).then(function(result) {
if (result.error) {
// Inform the customer that there was an error.
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
// Send the token to your server.
stripeTokenHandler(result.token);
}
});
});
function stripeTokenHandler(token) {
// Insert the token ID into the form so it gets submitted to the server
var form = document.getElementById('payment-form');
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'stripeToken');
hiddenInput.setAttribute('value', token.id);
form.appendChild(hiddenInput);
// Submit the form
form.submit();
}
// Custom styling can be passed to options when creating an Element.
var style = {
base: {
// Add your base input styles here. For example:
fontSize: '16px',
color: "#32325d",
}
};
// Create an instance of the card Element.
var card = elements.create('card', {style: style});
// Add an instance of the card Element into the `card-element` <div>.
card.mount('#card-element');
</script>
<form action="thankYou.php" method="post" id="payment-form">
<span class="bg-danger" id="payment_errors"></span>
<span class="bg-danger" id="card-errors"></span>
<div class="form-group col-md-6">
<label for="full_name">Full Name:</label>
<input class="form-control" type="text" name="full_name" id="full_name">
</div>
//Same as Email div, phone,address,city,state,zipcode,country,cardname,cardnumber,exp month, exp year, cvc
<button type="submit" class="btn btn-primary" id="checkout_button" style="display:none;">Check Out >></button>
</form>
我想这是apirequester.php的主要问题。可能与@B001重复ᛦ 1不,我正在获得Thankyu.php上的产品详细信息。问题是提交表单后没有生成令牌。我按照stripe文档中的所有说明进行了操作。可能是因为您的模型无法计费。应该有一些源代码或客户。请查看stripe php文档以指导您提供完整和准确的代码您正在使用?另外,请注意,您从Stripe收到一个API错误:这可能意味着您的收费脚本没有正确地传递令牌错误消息很有用,但唯一可以修复的是代码。因为我们看不到它,所以很难修复它。如果您需要进一步的帮助,请提供一些相关代码。谢谢s
//Getting Variable details like
$full_name = $_POST['full_name']; // same as email,phone, address,city ...
$metadata = array(
"cart_id" => $cart_id,
"tax" => $tax,
"sub_total" => $sub_total,
);
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("sk_test_hiQjZlN9oJ9GcLGAlPVwAvfq"); // secret Key
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken']; // Here not getting token
var_dump($token);
try{ . // Here not getting inside the try because token is null
$charge = \Stripe\Charge::create([
'amount' => 999,
'currency' => 'usd',
'description' => 'Example charge',
'source' => $token,
'receipt_email' => $email,
'metadata' => $metadata,
]);
}catch(\Stripe\Error\card $e){
echo $e;
}