hey guys I am fairly new to programming. Would really appreciate your help. I am trying to setup Stripe payment but upon charging the card I am getting this very long error message again and again.
Fatal error: Uncaught exception 'Stripe\Error\InvalidRequest' with message 'No such token: false' in C:\xampp\htdocs\vendor\stripe\stripe-php\lib\ApiRequestor.php:124 from API request 'req_MN1aLPlF6OMPIv' Stack trace: #0 C:\xampp\htdocs\vendor\stripe\stripe-php\lib\ApiRequestor.php(102): Stripe\ApiRequestor::_specificAPIError('{\n "error": {\n...', 400, Array, Array, Array) #1 C:\xampp\htdocs\vendor\stripe\stripe-php\lib\ApiRequestor.php(309): Stripe\ApiRequestor->handleErrorResponse('{\n "error": {\n...', 400, Array, Array) #2 C:\xampp\htdocs\vendor\stripe\stripe-php\lib\ApiRequestor.php(65): Stripe\ApiRequestor->_interpretResponse('{\n "error": {\n...', 400, Array) #3 C:\xampp\htdocs\vendor\stripe\stripe-php\lib\ApiResource.php(119): Stripe\ApiRequestor->request('post', '/v1/charges', Array, Array) #4 C:\xampp\htdocs\vendor\stripe\stripe-php\lib\ApiResource.php(158): Stripe\ApiResource::_staticRequest('post', '/v1/charges', Array, NULL) #5 C:\xampp\htdocs\vendor\stripe\stripe-php\lib\Charge.php(74): Stripe\ApiResourc in C:\xampp\htdocs\vendor\stripe\stripe-php\lib\ApiRequestor.php on line 124
I am absolutely clueless what does this mean. I have literally copy/pasted every thing from stripe. Below are my codes
Stripe.setPublishableKey('<?=STRIPE_PUBLIC;?>');
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();
}
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);
}
});
});
After this I am taking my customer to ThankYou.php with following code
<?php
require_once '/init.php';
Set your secret key: remember to change this to your live secret key in production
\Stripe\Stripe::setApiKey(STRIPE_PRIVATE);
Token is created using Checkout or Elements! Get the payment token ID submitted by the form:
$token = isset($_POST['stripeToken']);
Charge the user's card:
$charge = \Stripe\Charge::create(array(
"amount" => 1000,
"currency" => "usd",
"description" => "Example charge",
"source" => $token,
));