Thanks for the pointer.

It was quite easy but as a beginner it took me a while to figure this out, 
so i thought i would write what i did in the hope it helps someone else.

I followed the instructions in the documentation. https://stripe.com/docs

You need to install the API as described then you need to remove or rename 
the stripe.py found in gluon/contrib

in db.py i
*import stripe*
and added
*stripe.api_key = "Replace_with_your_key"*

I used the Custom form from the Stripe documents in my view.

Then in the controller i put the code from the example just a couple of 
small changes. You change the request.POST to request.post_vars. You also 
need to put this in an if loop.

def createcustomer():
     # Get the credit card details submitted by the form
    if request.post_vars:
        token = request.post_vars['stripeToken']

        # Create the charge on Stripe's servers - this will charge the 
user's card
        try:

            # Create a Customer
            customer = stripe.Customer.create(
                card=token,
                description="[email protected]"
            )
             
           # Charge the Customer instead of the card
               stripe.Charge.create(
               amount=1000, # in cents
               currency="usd",
               customer=customer.id
           )

            #Save Customer ID in your DB
            db.customer.insert(customer_id = customer.id )
            db.commit()

            # Redirect to view post
            session.flash = T("You Payed!")
            return redirect(URL('default', 'view'))

        except stripe.CardError, e:
          # The card has been declined
          response.flash = "Card Error"
          pass
    


I am a beginner, so there is probably a cleaner and better way, but the 
above worked for me. Hope it helps


On Friday, January 16, 2015 at 10:32:50 PM UTC-8, Massimo Di Pierro wrote:
>
> The StripeForm does not support it. Sorry. You have to use their API.
>
> On Friday, 16 January 2015 20:13:25 UTC-6, UG wrote:
>>
>> Hi,
>>
>> i am a beginner in python and web2py. 
>>
>> i am using the stripe form in web2py to process credit cards. It is 
>> simple and all works when i make a test. 
>>
>> what i want to do is make what stripe calls a "customer" so that i can 
>> make a charge at a later time. 
>> i tried to read through the stripe file in gluon but can not figure it 
>> out , Is there something i pass to the form instead of "amount" to get it 
>> to generate the customer token instead of a charge?
>>
>> Or is it something else?
>>
>> i would appreciate any direction on this.
>>
>> Thanks
>>
>>
>>

-- 
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.

Reply via email to