daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest Feb 28th, 2018 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. require_once("---PATH-TO-STRIPE-LIBRARY---");
  4. // Set your secret key: remember to change this to your test secret key in this situation
  5. // See your keys here: https://dashboard.stripe.com/account/apikeys
  6. \Stripe\Stripe::setApiKey("ENTER_YOUR_SK_HERE");
  7.  
  8. // Token is created using Checkout or Elements!
  9.  
  10. $stripeData = $_POST;
  11.  
  12. /*
  13.     $stripeData will look like this:
  14.     Array (
  15.          [stripeToken] => "tok_1C0a0wFqfn6NNRoaLYKlxjWR"
  16.          [stripeTokenType] => "card"
  17.          [stripeEmail] => "test@test.com"
  18.      )
  19. */
  20.  
  21.  
  22. // Get the payment token ID submitted by the form:
  23. $token = $stripeData['stripeToken'];
  24.  
  25. // if there's no token you might want to show an error here
  26. // otherwise try process the charge.
  27.  
  28. // Try charge the card token:
  29. try{
  30.     $charge = \Stripe\Charge::create(array(
  31.                     "amount" => 5000,
  32.                     "currency" => "GBP",
  33.                     "description" => "Special Fling Trophy Sponsorship £50.00",
  34.                     "source" => $token,
  35.                 )
  36.             );
  37. }catch(\Exception $e){
  38.     // handle the exception and show an error to the user
  39. }
  40.  
  41. ?>
  42. <html>
  43.     <head>
  44.         <script src="https://checkout.stripe.com/checkout.js"></script>
  45.     </head>
  46.     <body>
  47.         <form action="" method="POST">
  48.           <script
  49.             src="https://checkout.stripe.com/checkout.js" class="stripe-button"
  50.             data-key="ENTER_YOUR_PK_HERE"
  51.             data-amount="5000"
  52.             data-currency="GBP"
  53.             data-name="Newton Stewart Traditional Music Festival Association"
  54.             data-description="Special Fling Trophy Sponsorship £50.00"
  55.             data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
  56.             data-locale="auto">
  57.           </script>
  58.         </form>
  59.     </body>
  60. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top