Skip to content

Instantly share code, notes, and snippets.

@boucher
Forked from siddarth/gist:1379745
Created February 6, 2012 07:09

Revisions

  1. boucher revised this gist Feb 6, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.aw
    Original file line number Diff line number Diff line change
    @@ -53,14 +53,14 @@ if ($_POST) {
    $("#payment-form").submit(function(event) {
    // disable the submit button to prevent repeated clicks
    $('.submit-button').attr("disabled", "disabled");
    var chargeAmount = 1000; //amount you want to charge, in cents. 1000 = $10.00, 2000 = $20.00 ...

    // createToken returns immediately - the supplied callback submits the form if there are no errors
    Stripe.createToken({
    number: $('.card-number').val(),
    cvc: $('.card-cvc').val(),
    exp_month: $('.card-expiry-month').val(),
    exp_year: $('.card-expiry-year').val()
    }, chargeAmount, stripeResponseHandler);
    }, stripeResponseHandler);
    return false; // submit from callback
    });
    });
  2. @siddarth siddarth revised this gist Nov 20, 2011. 1 changed file with 17 additions and 6 deletions.
    23 changes: 17 additions & 6 deletions gistfile1.aw
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,20 @@
    require 'path-to-Stripe.php';

    if ($_POST) {
    Stripe::setApiKey("your-api-key");
    Stripe_Charge::create(array("amount" => 1000,
    "currency" => "usd",
    "card" => $_POST['stripeToken']));
    Stripe::setApiKey("YOUR-API-KEY");
    $error = '';
    $success = '';
    try {
    if (!isset($_POST['stripeToken']))
    throw new Exception("The Stripe Token was not generated correctly");
    Stripe_Charge::create(array("amount" => 1000,
    "currency" => "usd",
    "card" => $_POST['stripeToken']));
    $success = 'Your payment was successful.';
    }
    catch (Exception $e) {
    $error = $e->getMessage();
    }
    }

    ?>
    @@ -20,7 +30,7 @@ if ($_POST) {
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript">
    // this identifies your website in the createToken call below
    Stripe.setPublishableKey('YOUR_PUBLISHABLE_KEY');
    Stripe.setPublishableKey('YOUR-PUBLISHABLE-API-KEY');

    function stripeResponseHandler(status, response) {
    if (response.error) {
    @@ -59,7 +69,8 @@ if ($_POST) {
    <body>
    <h1>Charge $10 with Stripe</h1>
    <!-- to display errors returned by createToken -->
    <span class="payment-errors"></span>
    <span class="payment-errors"><?= $error ?></span>
    <span class="payment-success"><?= $success ?></span>
    <form action="" method="POST" id="payment-form">
    <div class="form-row">
    <label>Card Number</label>
  3. @gdb gdb revised this gist Oct 2, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.aw
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ require 'path-to-Stripe.php';

    if ($_POST) {
    Stripe::setApiKey("your-api-key");
    Stripe_Charge::create(array("amount" => 400,
    Stripe_Charge::create(array("amount" => 1000,
    "currency" => "usd",
    "card" => $_POST['stripeToken']));
    }
  4. Greg Brockman created this gist Sep 30, 2011.
    81 changes: 81 additions & 0 deletions gistfile1.aw
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,81 @@
    <?php
    require 'path-to-Stripe.php';

    if ($_POST) {
    Stripe::setApiKey("your-api-key");
    Stripe_Charge::create(array("amount" => 400,
    "currency" => "usd",
    "card" => $_POST['stripeToken']));
    }

    ?>

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title>Stripe Getting Started Form</title>
    <script type="text/javascript" src="https://js.stripe.com/v1/"></script>
    <!-- jQuery is used only for this example; it isn't required to use Stripe -->
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript">
    // this identifies your website in the createToken call below
    Stripe.setPublishableKey('YOUR_PUBLISHABLE_KEY');

    function stripeResponseHandler(status, response) {
    if (response.error) {
    // re-enable the submit button
    $('.submit-button').removeAttr("disabled");
    // show the errors on the form
    $(".payment-errors").html(response.error.message);
    } else {
    var form$ = $("#payment-form");
    // token contains id, last4, and card type
    var token = response['id'];
    // insert the token into the form so it gets submitted to the server
    form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
    // and submit
    form$.get(0).submit();
    }
    }

    $(document).ready(function() {
    $("#payment-form").submit(function(event) {
    // disable the submit button to prevent repeated clicks
    $('.submit-button').attr("disabled", "disabled");
    var chargeAmount = 1000; //amount you want to charge, in cents. 1000 = $10.00, 2000 = $20.00 ...
    // createToken returns immediately - the supplied callback submits the form if there are no errors
    Stripe.createToken({
    number: $('.card-number').val(),
    cvc: $('.card-cvc').val(),
    exp_month: $('.card-expiry-month').val(),
    exp_year: $('.card-expiry-year').val()
    }, chargeAmount, stripeResponseHandler);
    return false; // submit from callback
    });
    });
    </script>
    </head>
    <body>
    <h1>Charge $10 with Stripe</h1>
    <!-- to display errors returned by createToken -->
    <span class="payment-errors"></span>
    <form action="" method="POST" id="payment-form">
    <div class="form-row">
    <label>Card Number</label>
    <input type="text" size="20" autocomplete="off" class="card-number" />
    </div>
    <div class="form-row">
    <label>CVC</label>
    <input type="text" size="4" autocomplete="off" class="card-cvc" />
    </div>
    <div class="form-row">
    <label>Expiration (MM/YYYY)</label>
    <input type="text" size="2" class="card-expiry-month"/>
    <span> / </span>
    <input type="text" size="4" class="card-expiry-year"/>
    </div>
    <button type="submit" class="submit-button">Submit Payment</button>
    </form>
    </body>
    </html>