*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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to