Using Stripe's Checkout w/ web2py

336 visualizações
Pular para a primeira mensagem não lida

Scott Hunter

não lida,
21 de mar. de 2017, 23:19:2121/03/2017
para web2py-users
Has anyone been able to use Stripe's Checkout with web2py?  If so, how did you do it?  I'm having trouble getting the token it generates back.

- Scott

lyn2py

não lida,
22 de mar. de 2017, 00:29:3622/03/2017
para web2py-users
You might need to be more detailed describing your issue. 

Scott Hunter

não lida,
22 de mar. de 2017, 04:22:2422/03/2017
para web2py-users
I enter the credit cad info, the submit button turns green w/ the animated check box after being pressed, and the appropriate controller gets invoked.  But there is nothing in the request about the token: no post vars (which makes sense, since it isn't using a web2py-generated form), but not even in any of the more "raw" parts, or at least not so that I can recognize it.

So either I need to modify the form (which seems problematic, since Stripe does all of it within a script, like so):

<form action="/init/pay/charge" method="POST">
 
<script
   
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
   
data-email="...@gmail.com"
   
data-key="pk_test_..."
   
data-amount="30000"
   
data-name="UKI TMS"
   
data-description="Trials in 2017 ($300)"
   
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
   
data-panel-label="Pay {{amount}} for 2017"
   
data-locale="auto">
 
</script>
</form>


or the controller, but since I can't tell where the information I need is, I can't tell how to get it.

I've been using web2py's Stripe module, but been getting errors about not using TSL1.2; so instead of trying to mess with that, thought I would go directly to using one of Stripe's supported methods.

- Scott

Scott Hunter

não lida,
22 de mar. de 2017, 21:29:3822/03/2017
para web2py-users
From the deafening silence, apparently this was not enough detail for anyone to even ask what other details I need to provide, so I'll do it myself: what other info do I need to provide to get some kind of response?

- Scott

Dave S

não lida,
22 de mar. de 2017, 21:42:4222/03/2017
para web2py-users


On Wednesday, March 22, 2017 at 6:29:38 PM UTC-7, Scott Hunter wrote:
From the deafening silence, apparently this was not enough detail for anyone to even ask what other details I need to provide, so I'll do it myself: what other info do I need to provide to get some kind of response?

- Scott

I suspect that Stripe users here are in the minority of the minority.  There are people here handling payments through similar sites, judging by the occasional post here, and there's the info in the book.  Saying that pretty near exhausts what I know about the subject, although I've been at presentations about the role of OAUTH2 in some of the implementations.

/dps

Dave S

não lida,
22 de mar. de 2017, 21:46:5722/03/2017
para web2py-users


On Wednesday, March 22, 2017 at 6:42:42 PM UTC-7, Dave S wrote:


On Wednesday, March 22, 2017 at 6:29:38 PM UTC-7, Scott Hunter wrote:
From the deafening silence, apparently this was not enough detail for anyone to even ask what other details I need to provide, so I'll do it myself: what other info do I need to provide to get some kind of response?

- Scott

I suspect that Stripe users here are in the minority of the minority.  There are people here handling payments through similar sites, judging by the occasional post here, and there's the info in the book.  Saying that pretty near exhausts what I know about the subject, although I've been at presentations about the role of OAUTH2 in some of the implementations.

/dps


I think Massimo has done all the US-accessible methods, at least for testing, and it occurs to me that some of his videos may touch upon that, but I haven't watched enough of them to tell you which one, or whether it uses Stripe, but here's a post about his use of it:

<URL: https://groups.google.com/d/msg/web2py/Ou_Qc0-mucs/etrCBfoOM5MJ
>

/dps


 

Mathieu Clabaut

não lida,
23 de mar. de 2017, 04:11:0223/03/2017
para web2py-users
I have a working stripe integration in web2py which is closely based to what the gluon/contrib/stripe.py provides.
I'll try to provide more information this evening.

--
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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott Hunter

não lida,
23 de mar. de 2017, 07:57:4623/03/2017
para web2py-users, mat...@clabaut.net
I'd be very interested to see how you manage the Checkout form within the web2py framework.

- Scott

Happy Rob

não lida,
23 de mar. de 2017, 12:42:1323/03/2017
para web2py-users, mat...@clabaut.net
I'd be very interested too!

Joe Barnhart

não lida,
23 de mar. de 2017, 15:47:5523/03/2017
para web2py-users
I use Stripe all the time.  My sites (web2py and rails) have charged over $10M thru stripe so I'd have to say it works pretty well.

My favorite way to use it is to use their Javascript pop-up box, which prevents any CC info from even getting into my server logs.  I actually started using it before the stripe.py contrib, so I haven't used the contrib library very much.

I'll look over the question here and post later when I have a minute.

--- Joe B.

Mathieu Clabaut

não lida,
25 de mar. de 2017, 12:07:3325/03/2017
para web...@googlegroups.com

I use the attached modules/stripeform.py, which is mostly based upon the contrib/stripe.py
It imports the python stripe module : https://github.com/stripe/stripe-python.git

I use it like :

@auth.requires_login(otherwise=lambda: helper.flash(
    T("You need to log in to extend your subscription")))
def buy():
    from stripeform import clean_stripe_session
    clean_stripe_session() #To prevent reuse of idempotent uuid for stripe transactions
    form = SQLFORM.factory(
   # snipped …
            )
    form = form.process(keepvalues=True)
    if form.accepted:
           # error logic
        else:
            session.buyvars = form.vars
            redirect(URL('pay'))
    elif form.errors: # pragma: no branch
        response.flash = T('form has errors')
    return dict(form=form)

@auth.requires_login(otherwise=lambda: helper.flash(
    T("You need to log in to extend your subscription")))
def pay():
    if not session.buyvars:
        redirect(URL('buy'))
    from stripeform import StripeForm
    total = # TODO calculate total from session.buyvars content
    cart_form = TABLE(
# snipped : table displaying what is buyed (from session.buyvars
                  )
    payment_id = db.payments.insert(amount=total)
    form = StripeForm(
        pk=STRIPE_PUBLISHABLE_KEY,
        sk=STRIPE_SECRET_KEY,
        amount=total,  # (amount is in cents)
        currency='eur',
        currency_symbol='€',
        description="…",
        more = { 'metadata': {'payment_id':payment_id}}
    ).process()

    if form.accepted:
        pi = form.response
        from datetime import datetime
        import pytz
        db.payments[payment_id]= dict(…) # Update db with buyed items if necessary
        session.flash = T("Thank you!")
        redirect(URL(c='default', f='index'))
    elif form.errors: # pragma: no branch
        response.flash = form.response.errors
        del db.payments[payment_id]
    return dict(cart_form=cart_form, form=form)

And the views for pay looks like:

{{extend 'layout.html'}}
<div class="container">
   <div class="row">
      <h2>{{=T("Payment")}}</h2>
      <div class="col-md-7 col-sm-12 col-md-push-5">
     <h3>{{=T("Cart Content")}}</h3>
     <div class="table-responsive" id="payment">
        {{=cart_form}}
     </div>
      </div>
      <div class="col-md-5 col-md-pull-7 col-sm-12">
     {{=form}}
      </div>

--

stripeform.py

Happy Rob

não lida,
27 de mar. de 2017, 15:58:3927/03/2017
para web2py-users, mat...@clabaut.net
Hi Mathieu

I used Stripes submit form and put that in a form, and that seems to work ok -


<form action="/pay" method="POST">

<script

src="https://checkout.stripe.com/checkout.js"

class="stripe-button"

data-key="pk_test_XXXXXXXXXXXXXXXXXXXXX"

data-amount="999"

data-name="XXXXXXXXXXX"

data-description="Widget"

data-image="https://stripe.com/img/documentation/checkout/marketplace.png"

data-locale="auto"

data-zip-code="true"

data-currency="nzd">

</script>

</form>


I've used your code for my pay view, but cannot seem to get it to work - it just returns invalid request at https://robstestinglab.pythonanywhere.com/pay?stripeToken=tok_1A23uIERiozJkA6DO2gMlyJJ&stripeTokenType=card&stripeEmail=sgjkahg%40gashgj.com

The code I use in my pay page is...

def pay():

  from gluon.contrib.stripe import StripeForm

  amount = 1000

#1000 is $10 in cents

  description ="Example charge"

  form = StripeForm(

      pk=STRIPE_PUBLISHABLE_KEY,

      sk=STRIPE_SECRET_KEY,

      amount=int(100*amount),

      description=description).process()

  if form.accepted:

      #can also add stuff to update my records and allow them access and that. Also send them an email. But me, I’ll probably do that on the TU page itself.

      redirect(URL('thank_you'))

  elif form.errors:

      redirect(URL('pay_error'))

  return dict(form=form)


The form generated at Stripe is
# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.api_key = "sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxx"

# Token is created using Stripe.js or Checkout!
# Get the payment token submitted by the form:
token = request.POST['stripeToken'] # Using Flask

# Charge the user's card:
charge = stripe.Charge.create(
  amount=1000,
  currency="nzd",
  description="Example charge",
  source=token,
)



So - where do I put the token, the test code, etc?
I've tried to strip out everything so it's as bare bones as possible eg only able to submit $10, no shopping cart, but still confused.
I'd be very grateful for your help

Cheers
Rob

Happy Rob

não lida,
27 de mar. de 2017, 16:02:4427/03/2017
para web2py-users, mat...@clabaut.net
Oops, it would be $1000, and I also need to put in a proper description, but that's not the tricky bit.

Thanks
Rob

Happy Rob

não lida,
27 de mar. de 2017, 22:47:0827/03/2017
para web2py-users, mat...@clabaut.net
OK,I'm down to just this now:

def pay():
    from gluon.contrib.stripe import StripeForm
    form = StripeForm(
        pk='pk_test_xxxxxxxxxxxxxxxxxx',
        sk='sk_test_xxxxxxxxxxxxxxxxxx',
        amount=1000,
        description="Example charge").process()
    if form.accepted:
        #can also add stuff to update my records and allow them access and that. Also send them an email. But me, I’ll probably do that on the TU page itself.
        redirect(URL('thank_you'))
    elif form.errors:
        redirect(URL('pay_error'))
    return dict(form=form)

 but I get an internal error:

<class 'gluon.contrib.simplejson.decoder.JSONDecodeError'> No JSON object could be decoded: line 1 column 0 (char 0)


I have no idea what this means! Help!

Mathieu Clabaut

não lida,
28 de mar. de 2017, 09:11:1928/03/2017
para Happy Rob, web2py-users
I have no easy solution to your problem.
I guess that the response is empty and lead to an invalid json when trying to decode it.
Do you see the request in your stripe dashboard ?
You could also try to debug down to the call of stripe.charge() to see internally what is received or spy what is exchanged (I use vcrpy to be able to replay my tests locally, and  as a side effect, it allows to see precisely which data are send and receive).

Hope this help.

Happy Rob

não lida,
28 de mar. de 2017, 12:00:0228/03/2017
para web2py-users, happy.ro...@gmail.com, mat...@clabaut.net
Looking a little deeper (thanks google) it seems that the free version of python anywhere is unable to send the JSON thing through some proxy.
To be honest I'm not entirely sure what that means, but the solution seems to be to get the app working locally, then later upgrade to a paid plan when ready to go live.

So no free solution for python anywhere (yet!), so I'll try getting the local one working.

David Manns

não lida,
10 de out. de 2018, 14:11:3510/10/2018
para web2py-users
I know your post is a long time ago, but since I have just been dealing with the same issue ...

Initially, I followed the implementation described in the web2py manual, using /gluon/contrib/stripe.py.

This worked locally but not on my (free) test account at PA. I re-implemented, following the API documentation on stripe.com. This uses the stripe module in Python. This version works fine on PA.

Hopefully, you long since solved your problem.

Dan Carroll

não lida,
10 de out. de 2018, 15:45:0510/10/2018
para web2py-users
For those looking for how to get Stripe to work with Web2Py, follow the API from Stripe. The getting started documentation with the checkout script works. Make sure you are following the Python code section.


Hint: Place the checkout script inside of a web2py generated form. The script will submit the form and in the form.process().accepted part of your code you can get the Stripe token.

(stripeToken = form.vars.stripeToken)
Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem