Commits

Steven Kryskalla  committed 9b7527c

rename "stripe_key" to "stripe_token"

  • Participants
  • Parent commits b93de3d

Comments (0)

Files changed (8)

File demos/001-simplest/templates/itemshop/default_index.html

 </div>
 
 <form action="{{url_for('itemshop.%s.process' % item.name)}}" method="POST" id="stripe-form">
-    <input type="hidden" name="stripe_key" value="" />
+    <input type="hidden" name="stripe_token" value="" />
     <div class="form-row">
         <label>Name</label>
         <input type="text" size="35" maxlength="99" name="name" />

File demos/002-two-items/templates/itemshop/macros.html

 {% macro purchase_form(item) -%}
 <form action="{{url_for('itemshop.%s.process' % item.name)}}" method="POST" id="stripe-form">
-    <input type="hidden" name="stripe_key" value="" />
+    <input type="hidden" name="stripe_token" value="" />
     <div class="form-row">
         <label>Name</label>
         <input type="text" size="35" maxlength="99" name="name" />

File demos/003-secure-download/templates/itemshop/macros.html

 {% macro purchase_form(item) -%}
 <form action="{{url_for('itemshop.%s.process' % item.name)}}" method="POST" id="stripe-form">
-    <input type="hidden" name="stripe_key" value="" />
+    <input type="hidden" name="stripe_token" value="" />
     <div class="form-row">
         <label>Name</label>
         <input type="text" size="35" maxlength="99" name="name" />

File demos/static/js/demos.js

 function stripeResponseHandler(status, response) {
     if(status == 200) {
-        $("input[name=stripe_key]").val(response.id);
+        $("input[name=stripe_token]").val(response.id);
         $("#stripe-form button").removeAttr('disabled');
         $('#stripe-form').off("submit");
         $("#stripe-form").submit();

File docs/index.rst

 
 Payments are handled using `stripe`_. The credit card information is processed
 in the browser using `stripe.js`_, so you don't need to handle sensitive info
-server-side. The server-side code takes the ``stripe_key`` obtained from
+server-side. The server-side code takes the ``stripe_token`` obtained from
 ``stripe.js``, then uses the `stripe python API`_ to actually make the charge.
 
 .. _Flask: http://flask.pocoo.org/

File docs/philosophy.rst

 
 This package also does not do any form generation or validation. By default,
 :class:`ItemBP` only requires one form field to be POSTed to process the request:
-``stripe_key``.
+``stripe_token``.
 
 The demos include some Javascript validation. In my opinion, you should
 validate using javascript (or AJAX) because A.) the stripe.js API validates

File docs/quickstart.rst

 * HTML and JS
 
   * create a template called "``itemshop/default_index.html``", which contains a
-    form with credit card fields and one hidden field called "``stripe_key``"
+    form with credit card fields and one hidden field called "``stripe_token``"
   * wire up the ``stripe.js`` API with this form, so that when the user submits
     the form, their credit card is processed with ``stripe.js``, and your
-    ``stripe_key`` hidden field is populated with the key returned by stripe
+    ``stripe_token`` hidden field is populated with the key returned by stripe
   * create a template called "``itemshop/default_process.html``", which will be shown
     to the user after their purchase is complete
 
 .. code-block:: html
 
     <form id="stripe-form" action="{{url_for('itemshop.%s.process' % item.name)}}" method="POST">
-        <input type="hidden" name="stripe_key" value="" />
+        <input type="hidden" name="stripe_token" value="" />
         <div>
             <label>Email</label>
             <input type="text" size="20" maxlength="99" name="email" />
 
 Two important things to note:
 
-1. The very first field is the hidden field for "``stripe_key``". We will use this element to store the key obtained from the ``stripe.js`` API call.
-2. None of the credit card fields (card number, CVC, expiration month, or expiration year) have a ``name`` attribute. This means that even if the form gets submitted without javascript, the credit card fields will not be sent to your backend. This is a safety precaution.
+1. The very first field is the hidden field for "``stripe_token``".
+   We will use this element to store the key obtained from the ``stripe.js`` API call.
+2. None of the credit card fields (card number, CVC, expiration month, or expiration
+   year) have a ``name`` attribute. This means that even if the form gets submitted
+   without javascript, the credit card fields will not be sent to your backend. This
+   is a safety precaution.
 
-The last step for the HTML templates is to create the "thanks" template, ``default_process.html``, which is what gets shown to users after they successfully make a purchase. It could be as simple as this:
+The last step for the HTML templates is to create the "thanks" template,
+``default_process.html``, which is what gets shown to users after they
+successfully make a purchase. It could be as simple as this:
 
 .. code-block:: html
 
 Javascript
 ----------
 
-Create a new static JS file at ``static/demo.js`` (you could also just put this in a ``<script>`` tag in ``default_index.html``).
+Create a new static JS file at ``static/demo.js`` (you could also just put
+this in a ``<script>`` tag in ``default_index.html``).
 
 First, we attach an on-submit handler to the "``#stripe-form``" form tag:
 
 
     function stripeResponseHandler(status, response) {
         if(status == 200) {
-            $("input[name=stripe_key]").val(response.id);
+            $("input[name=stripe_token]").val(response.id);
             $("#stripe-form button").removeAttr('disabled');
             $('#stripe-form').off("submit");
             $("#stripe-form").submit();
 The ``stripeResponseHandler`` callback does a check on the status of the stripe API call:
 
 * If the response was ``200``, then the credit card is valid and a token was
-  returned as ``response.id``. We store that token in the ``stripe_key`` field,
+  returned as ``response.id``. We store that token in the ``stripe_token`` field,
   re-enable the submit button, turn off the on-submit handler, then submit the form,
   which will POST the form data to the flask app.
 
 3. Finally, we pass in a dict of default values that will be used to
    instantiate the stripe payment. In this case, we pass in the amount (1500 in
    cents, $15.00) and the currency 'usd'. Any other values, like the
-   ``stripe_key`` will come from the form data. You can also use this dict to pass 
+   ``stripe_token`` will come from the form data. You can also use this dict to pass 
    in an ``api_key``, which will override the global ``stripe.api_key``, so you could
    have a different ``api_key`` for an item.
 

File itemshop/__init__.py

     '''
     :class:`BlueprintWrapper` that models a shop item. There are two view methods:
     ``index``, to show the form, and ``process``, to process the incoming
-    ``stripe_key`` and show the thank you page. There are also two hooks:
+    ``stripe_token`` and show the thank you page. There are also two hooks:
     :meth:`pre_purchase` and :meth:`post_purchase`, that can be overridden to add
     behavior before and after the purchase is made.
 
     @bp_route('/process', methods=["POST"])
     def process(self):
         '''     
-        View method. Processes incoming ``stripe_key`` (obtained by the client
+        View method. Processes incoming ``stripe_token`` (obtained by the client
         with ``stripe.js``) to actually charge the user's credit card.
 
         You can change / add behavior to this method by overriding
         are passed into the template.
         '''
         args = self.pmt_default_args.copy()
-        args['card'] = request.values['stripe_key']
+        args['card'] = request.values['stripe_token']
 
         #which field do we use for email?
         email = request.values['email']