Forums

Trying to connect stripe to github pages and Pythonanywhere

I've been trying to fix it for a long time, but I can't find the problem. this is the code:

python (uploaded in pythonanywhere):

from flask import Flask,redirect

import stripe

stripe.api_key = 'MyApi'

app = Flask (name, static_url_path='', static_folder='static')

YOUR_DOMAIN = 'julianburastero.github.io/pruebas4.github.io/'

@app.route('/create-checkout-session', methods=['POST']) def create_checkout_session(): try: checkout_session = stripe.checkout.Session.create( line_items=[ { 'price': 'price_1NPp2QB3zf8eVaNEpBD2yEUH', 'quantity': 1, }, ], mode='payment', success_url=YOUR_DOMAIN + '/success.html', cancel_url=YOUR_DOMAIN + '/cancel.html', ) except Exception as e: return str(e)

return redirect(checkout_session.url, code =303)

HTML (uploaded in github pages)

!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Buy cool new product</title> <link rel="stylesheet" href="style.css"> <script src="https://js.stripe.com/v3/"></script> </head> <body> <section> <div class="product"> <h3>Stubborn Attachments</h3> <h5>$20.00</h5> </div> <form action="/create-checkout-session" method="post"> <button type="submit" id="checkout-button">Checkout</button> </form> </section> </body> </html>

When I press the button "Checkout", I get the following error:

405 Not Allowed

It's a very simple app and I'm making it to learn how to use stripe on a web server, but I'd like to make it work.

The code works locally but when uploading it to githubpages and pythonanywhere I had to adapt the code but it didn't work anymore

Maybe you have to use "{{PYTHONANYWHERE_DOMAIN}}/create-checkout-session" instead of "/create-checkout-session" as an action, if your HTML code is hosted elsewhere.