So i am trying to implement a stripe payment page and using the examples in
the current gluon/contrib/stripe.py
I cut and pasted the Template into a page with the default controller to
see how it went but it failed first up with a global name not defined error
on pk=PUBLISHABLE_KEY_GOES_HERE.
I then passed the test keys as strings to the controller and ended up with
the following:
def verify():
response.flash = T("Enter Your Credit Card Transaction")
from gluon.contrib.stripe import StripeForm
form = StripeForm(
pk="pk_test_K44o7S1yuutpxBBLFOYZTsxl",
sk="sk_test_MQAXb12hLq3PiJBgVmozMJbS",
amount=150, # $1.5 (amount is in cents)
description="Nothing").process()
if form.accepted:
payment_id = form.response['id']
redirect(URL('thank_you'))
elif form.errors:
redirect(URL('pay_error'))
return dict(form=form)
This handled the error above but the code then failed with a different error
<type 'exceptions.NameError'>(name 'pk' is not defined)
Tracing this down... the traceback shows that the error is occuring when
web2py is attempting to construct the html page...
Traceback (most recent call last):
File "/home/gsv/enertek/web2py/gluon/restricted.py", line 217, in restricted
exec ccode in environment
File
"/home/gsv/enertek/web2py/applications/welcome/views/default/verify.html", line
84, in <module> <<< this is after the last line of code
{{if security_notice or disclosure_notice:}}
NameError: name 'pk' is not defined
and is happening here...
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
response.write('\n <div class="span3 left-sidebar">\n ',
escape=False)
response.write('\n <h3>Left Sidebar</h3>\n <p></p>\n
', escape=False)
response.write('\n </div>\n ', escape=False)
pass
response.write('\n\n <div class="', escape=False)
response.write(middle_columns)
response.write('">\n ', escape=False)
response.write('\n ', escape=False)
response.write('\n<script type="text/javascript"
src="https://js.stripe.com/v2/"></script>\n<script>\njQuery(function(){\n //
This identifies your website in the createToken call below\n
Stripe.setPublishableKey(\'', escape=False)
response.write(pk)
response.write('\');\n\n var stripeResponseHandler = function(status,
response) {\n var jQueryform = jQuery(\'#payment-form\');\n\n if
(response.error) {\n // Show the errors on the form\n
jQuery(\'.payment-errors\').text(response.error.message).show();\n
jQueryform.find(\'button\').prop(\'disabled\', false);\n } else {\n
// token contains id, last4, and card type\n var token = response.id;\n
// Insert the token into the form so it gets submitted to the server\n
var tokenInput = jQuery(\'<input type="hidden" name="stripeToken" />\');\n
jQueryform.append(tokenInput.val(token));\n // and re-submit\n
jQueryform.get(0).submit();\n }\n };\n\n jQuery(function(jQuery)
{\n jQuery(\'#payment-form\').submit(function(e) {\n\n var
jQueryform = jQuery(this);\n\n // Disable the submit button to prevent
repeated clicks\n jQueryform.find(\'button\').prop(\'disabled\',
true);\n\n Stripe.createToken(jQueryform, stripeResponseHandler);\n\n
// Prevent the form from submitting with the default action\n return
false;\n });\n });\n});\n</script>\n\n<h3>Payment Amount: ',
escape=False)
response.write(currency_symbol)
response.write(' ', escape=False)
response.write("%.2f" % (0.01*amount))
response.write('</h3>\n<form action="" method="POST" id="payment-form"
class="form-horizontal">\n\n <div class="form-row control-group">\n <label
class="control-label">Card Number</label>\n <div class="controls">\n
<input type="text" size="20" data-stripe="number"\n\t
placeholder="4242424242424242"/>\n </div>\n </div>\n\n <div
class="form-row control-group">\n <label class="control-label">CVC</label>\n
<div class="controls">\n <input type="text" size="4" style="width:80px"
data-stripe="cvc"\n\t placeholder="XXX"/>\n <a
href="http://en.wikipedia.org/wiki/Card_Verification_Code" target="_blank">What
is this?</a>\n </div>\n </div>\n\n <div class="form-row control-group">\n
<label class="control-label">Expiration</label>\t\n <div
class="controls">\n <input type="text" size="2" style="width:40px"
data-stripe="exp-month"\n\t placeholder="MM"/>\n /\n <input
type="text" size="4" style="width:80px" data-stripe="exp-year"\n\t
placeholder="YYYY"/>\n </div>\n </div>\n\n\n <div class="control-group">\n
<div class="controls">\n <button type="submit" class="btn
btn-primary">Submit Payment</button>\n <div class="payment-errors error
hidden"></div>\n </div>\n </div>\n <input type="hidden" name="signature"
value="', escape=False)
response.write(signature)
response.write('" />\n</form>\n\n', escape=False)
if security_notice or disclosure_notice:
response.write('\n<div class="well">\n ', escape=False)
if security_notice:
How can I fix this please?
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.