<div dir="ltr"><div>I wasn't going to permanently store them there. Just wanted to 
quickly test out the Stripe functionality in my site. This simple stripe flask app 
(<a href="https://stripe.com/docs/checkout/guides/flask">https://stripe.com/docs/checkout/guides/flask</a>) works just fine for me stand alone. 
When I try to implement a similar thing in my site, I am getting the 400
 errors..<br><br></div>if 'a' not in b seems a bit easier to read to me. Thanks!</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 30, 2015 at 3:57 PM, Dorian Hoxha <span dir="ltr"><<a href="mailto:dorian.hoxha@gmail.com" target="_blank">dorian.hoxha@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div>From a quick look, don't store config values in the code.<br></div>Careful with stripe keys (they look like test keys though)<br><br></div>I think it's more pythonic:<br></div>if 'a' not in b<br><br></div>instead of :<br><br></div>if not 'a' in b:<br><br></div>I'm not sure though.<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 30, 2015 at 9:28 PM, Kyle Lawlor <span dir="ltr"><<a href="mailto:klawlor419@gmail.com" target="_blank">klawlor419@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Ok, I will look into this first. Thanks again for the pointers. In the meantime, any further comments still appreciated. <br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 30, 2015 at 2:34 PM, Dorian Hoxha <span dir="ltr"><<a href="mailto:dorian.hoxha@gmail.com" target="_blank">dorian.hoxha@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Replace the code like I said and try again if the error persist.<br></div>I don't know if the fields do(nt) exist in your code, that's why you have to fix them by actually checking.<br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 30, 2015 at 8:01 PM, Kyle Lawlor <span dir="ltr"><<a href="mailto:klawlor419@gmail.com" target="_blank">klawlor419@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Ok. Thanks for the response. I will keep this in mind as I continue to diagnose my problem. Did you spot a place in my code where the field d.n.e.?<br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 30, 2015 at 9:35 AM, Dorian Hoxha <span dir="ltr"><<a href="mailto:dorian.hoxha@gmail.com" target="_blank">dorian.hoxha@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>ALWAYS check if the field exist in request.form, if it doesn't you will get a 400 request-error.<br></div>2 ways to check:<br></div>if 'field' in request.form<br></div>if request.form.get('field')<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 30, 2015 at 12:29 AM, Kyle Lawlor <span dir="ltr"><<a href="mailto:klawlor419@gmail.com" target="_blank">klawlor419@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div>Hello, everyone. <br><br></div>I've been working on web app for a friends restaurant. I am slowly adding the functionality that I need. Earlier today I was able to add a payment method via the Stripe API. I have confirmed that the test payments are going through to my Stripe logs. I followed very closely to the [stripe flask tutorial](<a href="https://stripe.com/docs/checkout/guides/flask" target="_blank">https://stripe.com/docs/checkout/guides/flask</a>). Basically I am doing the exact same thing as what is done in the tutorial, except I have adjusted the payment amount based on interaction with the "order online" portion of the website. <br><br></div><div><b><u><i>First issue:</i></u><br></b></div><div><br></div>One issue I am having (which I am sure is just a stupid mistake) is that once the purchase is confirmed, I redirect to a confirmation page to show a summary of the order, but I am getting a "400 Bad Request - CSRF token missing or incorrect" error. <br><br>I tried to solve the problem using the methods from [this page](<a href="http://flask-wtf.readthedocs.org/en/latest/csrf.html" target="_blank">http://flask-wtf.readthedocs.org/en/latest/csrf.html</a>), like adding an empty form with a CSRF token, to no avail. I also tried including a meta tag with the token which also did not work. <br><br></div>I am puzzled. A curious thing is that I can access the "payment" page manually via url before and after the transaction goes through. It seems that the trouble only happens when I redirect from the Stripe payment.<br><br></div><div><b><u><i>Second issue:</i></u></b><br></div><div><br></div><div>Another possibly related issue is that there is a segment of code using the stripe API I have commented out for the following reason. When it is uncommented I get the following error in addition to the CSRF error stated above, "400 Bad Request - The browser (or proxy) sent a request that this server could not understand."<br></div><div><br></div>If anyone has a chance to take a look at this for me it would be greatly appreciated. Here is the latest version of the project (currently using the meta tag with CSRF).<br><br></div><u>Project:</u> <a href="https://github.com/callmeskywalker/casa-site" target="_blank">https://github.com/callmeskywalker/casa-site<br></a><br><u>First issue relevant:<br><br></u></div><div>stripe import and test keys:<br><a href="https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L38-L43" target="_blank">https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L38-L43</a><br></div><div><br>order view function: <br><a href="https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L47" target="_blank">https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L47-L128</a><br><br></div><div>pass stripe key to 'order' template:<br><a href="https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L128" target="_blank">https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L128<br></a></div><div><u><br></u></div><div>stripe implementation in 'order' template:<br><a href="https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L50-L64" target="_blank">https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L50-L64</a><br><br></div><div>action to redirect to the 'payment' template (just to display order details):<br><a href="https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L51" target="_blank">https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L51</a><br></div><div><u><br></u></div><div>payment template with csrf token:<br><a href="https://github.com/callmeskywalker/casa-site/blob/master/app/templates/payment.html#L5" target="_blank">https://github.com/callmeskywalker/casa-site/blob/master/app/templates/payment.html#L5</a><br></div><div><u><br></u></div><u>Second issue relevant:</u><br><br></div><div>code from stripe API in payment view function (causing second error):<br><a href="https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L138-L148" target="_blank">https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L138-L148</a><br></div><div><br><br></div><div>Thanks ahead. I look forward to any responses. <br><br></div><div>Best, <br></div><div>Kyle<br></div><div><br></div></div>
<br>_______________________________________________<br>
Flask mailing list<br>
<a href="mailto:Flask@python.org" target="_blank">Flask@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/flask" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/flask</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>