简体   繁体   中英

How to implement stripe custom button in python on app engine

javascript for handling customButton:

var handler = StripeCheckout.configure({
    key: 'pk_test_9tnZ37cNgvyDCfICwHjOctXm',
    token: function(token, args) {
        //HOW DO I GENERATE THE SERVER SIDE CODE?
    }
});

$('#customButton').on('click', function(e) {
    handler.open({
      name: 'Get Meal Point Karma',
      description: '$10.00',
      amount: 1000
    });
    e.preventDefault();
});

I mapped "/charge" to a class called Charge with a post method for handling stripe payments:

def post(self):
    # https://manage.stripe.com/account/apikeys
    stripe.api_key = secretkey
    token = self.request.get('stripeToken')
    try: #charge card
        charge = stripe.Charge.create(
          amount=1000, #cents
          currency="usd",
          card=token
        )
    except: #card declined
        pass
    self.render("success.html")

How do I make a token and submit the information to the server? Is it just a normal ajax post?

The stripe JavaScript clears the html inputs which have stripe tags and adds its own token which is automatically passed to your server. This way your server never handles sensitive data. Your sever then calls stripe to attach card to an account or process payments. If you use the token to charge card you won't be able to attach card to account for later charging. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM