I have created a very simple website which has the default stripe checkout that submits to a charging page. I have followed the PHP instructions on the stripe website and I am utterly confused as to why it does not work. The checkout page is working perfectly:
<div class="container">
<form action="charge.php" method="POST">
<h6> amount </h6>
<input type="text" name="amount" />
<h6> test-info </h6>
<br /> <input type="text" name="pubkey" />
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_NC2CbWJLgm82SMzbxRX4JBLo"
data-amount="2000"
data-name="Demo Site"
data-description="2 widgets ($20.00)"
data-image="/128x128.png"
data-bitcoin="true">
</script>
</form>
</div>
All the inputs from the checkout such as the email, the token and pubkey are transferred to the charge.php page perfectly. In charge.php:
<?php
require_once('config.php');
$token = $_POST ['stripeToken'];
$email = $_POST['stripeEmail'];
$pubkey = $_POST['pubkey'];
$amount = $_POST['amount'];
?>
<h3> Public key: <?php echo $pubkey; ?> </h3>
<h3> Token: <?php echo $token; ?> </h3>
<h3> Amount: <?php echo $amount; ?> </h3>
<h3> Email: <?php echo $email; ?> </h3>
<?php
try {
$charge = \Stripe\Charge::create(array(
"amount" => 1000, // amount in cents, again
"currency" => "gbp",
"source" => $token,
"description" => "Example charge"
));
} catch(\Stripe\Error\Card $e) {
}
?>
<h6> You've been charged </h6>
all of the variables from the form submission are printed out. However, for some reason the actual charging does not work and the header (i.e. you've been charged) is not printed out. The token is correct so I'm really not sure how it is possible for it not to be charging. Why am I wrong and how could I debug this to find out?
Config.php
<?php
require_once('vendor/autoload.php');
$stripe = array(
"secret_key" => "sk_test_**********************",
"publishable_key" => "pk_test_NC2CbWJLgm82SMzbxRX4JBLo"
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
echo 'this is from config.php';
?>
$e
exception output? It will tell you why the try/catch failed. – Martin