I am working on stripe and getting error when i charge amount code i am using is
<button id="customButton" class="submit_btn">Make Appointment</button>
<script src="https://checkout.stripe.com/checkout.js"></script>
<input type="hidden" id="stripeToken" name="stripeToken" />
<script>
var handler = StripeCheckout.configure({
key: 'TOKEN',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
token: function(token) {
jQuery(function ($) {
console.log("testing12");
var value = $('#stripeToken').val(token.id);
console.log(value);
});
}
});
jQuery(function ($) {
document.getElementById('customButton').addEventListener('click', function (e) {
var amount = 0;
$('input:checkbox:checked').each(function(){
amount += isNaN(parseInt($(this).val())) ? 0 : parseInt($(this).val());
$('#total').text(amount);
});
handler.open({
name: 'Sports Solution',
description: '',
amount: amount
});
e.preventDefault();
});
<?php
\Stripe\Stripe::setApiKey("sk_test TOTEN");
$token = $_POST['stripeToken'];
var_dump($token);
$charge = \Stripe\Charge::create([
'amount' => 999,
'currency' => 'usd',
'description' => 'Example charge',
'source' => $token,
]);
?>
});
// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
handler.close();
});
</script>
the error is am getting is visible on stripe like it show this { "error": { "code": "parameter_missing", "doc_url": "https://stripe.com/docs/error-codes/parameter-missing", "message": "Must provide source or customer.", "type": "invalid_request_error" } }
'source' => $token,should be a string starting withtok_. Can you check to verify that you're getting the proper value of$tokenthere? - taintedzodiac