NilPuig
5/24/2017 - 7:18 AM

charge.php

<?php require_once('./config.php'); ?>

<form action="charge.php" method="post">
  <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
          data-key="<?php echo $stripe['publishable_key']; ?>"
          data-amount="5000" data-description="One year's subscription"></script>
</form>
<?php
require_once('vendor/autoload.php');

$stripe = array(
  secret_key      => "sk_test_332kjf2jkewkw",
  publishable_key => "pk_test_n32ikj323k2kf"
);

\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>

<?php
  require_once('./config.php');

  $token  = $_POST['stripeToken']; // retrieve stripeToken POST parameter to charge the card

  $customer = \Stripe\Customer::create(array(
      'email' => $_POST['stripeEmail'],
      'card'  => $token
  ));

  $charge = \Stripe\Charge::create(array(
      'customer' => $customer->id,
      'amount'   => 5000,
      'currency' => 'usd'
  ));

  echo '<h1>Successfully charged $50!</h1>';
?>