Kristofen, could I see the template? The javascript/jQuery you're using in
the template specifically?

 I think that's where the problem is.
I copied it directly from https://stripe.com/docs/custom-form, but it
doesn't appear to be running the jQuery. I get an error,
js jquery referenceerror $ is not defined $(function() when I look at
Firebug (in browser).

On Fri, Jun 17, 2016 at 4:49 PM, Kristofer Pettijohn <
kristo...@cybernetik.net> wrote:

> This is how I did it.  This is using Stripe Checkout.
>
> forms.py ... (you can omit the address pieces if you don't need them)
>
>     class StripeForm(forms.Form):
>         stripeToken = forms.CharField(max_length=80)
>         stripeBillingName = forms.CharField(max_length=80, required=False)
>         stripeBillingAddressLine1 = forms.CharField(max_length=80,
> required=False)
>         stripeBillingAddressZip = forms.CharField(max_length=80,
> required=False)
>         stripeBillingAddressState = forms.CharField(max_length=80,
> required=False)
>         stripeBillingAddressCity = forms.CharField(max_length=80,
> required=False)
>         stripeBillingAddressCountry = forms.CharField(max_length=80,
> required=False)
>
>
> views.py ...
>
>     stripe_form = StripeForm(request.POST or None)
>     if request.method == 'POST' and stripe_form.is_valid():
>         token = stripe_form.cleaned_data['stripeToken']
>         customer = stripe.Customer.create(
>             description=summary_dict['email_address'],
>             source=token
>         )
>
>
> ------------------------------
> *From: *"Chris Kavanagh" <cka...@gmail.com>
> *To: *"Django users" <django-users@googlegroups.com>
> *Sent: *Thursday, June 16, 2016 2:20:22 PM
> *Subject: *Stripe Not Returning Token (test mode)
>
> *Stripe Not Returning Token (test mode)*
>
> I'm trying out Stripe in test mode on a site I'm building, and for some
> reason Stripe won't return a token as it's supposed to.
> I can tell it's not returning a token, because I get a
> MultiValueDictKeyError when submitting the form. Plus, it won't print
> the token out to the console, so it's obviously not returning one.
>
> If I change the line (* token = request.POST['stripeToken']*)  to  (*token
> = request.POST.get('stripeToken*')), I get the error  "
>
> Request req_8eOcfP3bw2bzDd: Must provide source or customer." This way will 
> actually create
> a customer I can see in the Stripe Dashboard but won't create a charge, and 
> of course
> I get the error "must provide a source or customer."
>
> Here's the link to Stripe form documentation along with javascript. . .
> https://stripe.com/docs/custom-form
>
>
> I've double checked the keys to make sure they are correct, and it's
> definitely in test mode. From the examples &
> tutorials I've looked at, I don't see a reason it shouldn't be working.
> Any help is greatly appreciated, thanks Chris.
>
> Anyway, here's the code:
>
>
>
> *#views.py*def checkout(request):
>     publishable_key = settings.STRIPE_PUBLISHABLE_KEY
>     stripe.api_key = settings.STRIPE_SECRET_KEY
>     if request.method == "POST":
>         #token = request.POST.get('stripeToken')
>         token = request.POST['stripeToken']
>         print token
>         customer = stripe.Customer.create(description='test', source=token)
>         print customer
>         stripe.Charge.create(amount=500, currency='usd', source=token,
> description='test')
>         #stripe.Charge.create(amount=500, currency='usd',
> customer=customer, description=customer_data['description'])
>         return redirect('orders:thanks.html')
>     context = {'publishable_key': publishable_key}
>     return render(request, 'orders/checkout.html', context)
>
>
>
>
>
>
>
> *#template checkout,html*{% extends "base.html" %}
>
>  {% block jQuery %}
>  <script type="text/javascript" src="https://js.stripe.com/v2/";></script>
>
> <script type="text/javascript">
>     Stripe.setPublishableKey('{{ publishable_key }}');
>
>     $(function() {
>   var $form = $('#payment-form');
>   $form.submit(function(event) {
>     // Disable the submit button to prevent repeated clicks:
>     $form.find('.submit').prop('disabled', true);
>
>     // Request a token from Stripe:
>     Stripe.card.createToken($form, stripeResponseHandler);
>
>     // Prevent the form from being submitted:
>     return false;
>   });
> });
>
>     function stripeResponseHandler(status, response) {
>   // Grab the form:
>   var $form = $('#payment-form');
>
>   if (response.error) { // Problem!
>
>     // Show the errors on the form:
>     $form.find('.payment-errors').text(response.error.message);
>     $form.find('.submit').prop('disabled', false); // Re-enable submission
>
>   } else { // Token was created!
>
>     // Get the token ID:
>     var token = response.id;
>
>     // Insert the token ID into the form so it gets submitted to the
> server:
>     $form.append($('<input type="hidden" name="stripeToken">').val(token));
>
>     // Submit the form:
>     $form.get(0).submit();
>   }
> };
> </script>
>
>     {% endblock %}
>
>
>  {% block content %}
>  <h3 class="text-center">Credit Card Payment</h3>
>  <div class="container">
> <div class="row">
>     <form method="post" action="." id="checkout-form">
>         {% csrf_token %}
>
>
>         <div class="form-group">
>           <label class="control-label" for="card">Card</label>
>           <div class="controls">
>               <input type="text" id="card" class="form-control"
> data-stripe="number" />
>           </div>
>         </div>
>         <div class="form-group">
>             <label class="control-label" for="">Expiration
> (MM/YYYY)</label>
>             <div class="row">
>                 <div class="col-xs-2">
>                     <input type="text" size="2" data-stripe="exp-month"
> class="form-control" />
>                 </div>
>                 <div class="col-xs-2">
>                     <input type="text" size="4" data-stripe="exp-year"
> class="form-control" />
>                 </div>
>             </div>
>         </div>
>         <div class="form-group">
>             <label class="control-label" for="cvc">CVC</label>
>             <div class="controls">
>                 <input type="text" id="cvc" size="4" class="form-control"
> data-stripe="cvc" />
>             </div>
>         </div>
>         <div class="form-group">
>             <div class="controls">
>                 <input type="submit" value="Checkout" class="btn
> btn-primary" />
>             </div>
>         </div>
>     </form>
> </div>
> </div>
> {% endblock %}
>
>
>
> Request req_8eOcfP3bw2bzDd: Must provide source or customer.
>
>
> MultiValueDictKeyError at /orders/checkout/
>
> "'stripeToken'"
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8596d735-c697-4734-a2a3-a6bbec0ee2e2%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8596d735-c697-4734-a2a3-a6bbec0ee2e2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/kOYgvRGOSqw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/834594107.94049123.1466196586714.JavaMail.zimbra%40cybernetik.net
> <https://groups.google.com/d/msgid/django-users/834594107.94049123.1466196586714.JavaMail.zimbra%40cybernetik.net?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOywziCzdYGJ8xpMN5jT1dNue9_XR4pVY-eJy4NpNoJsn7Xx9g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to