Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payment_gateway.py #2389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Payment_gateway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Install Stripe package with: pip install stripe
import stripe
from flask import Flask, jsonify, request

# Configure the Stripe API key
stripe.api_key = "your_secret_key" # Replace with your actual Stripe secret key

app = Flask(__name__)

# Route to create a new payment session
@app.route("/create-checkout-session", methods=["POST"])
def create_checkout_session():
try:
# Parse the amount and currency from the request
data = request.get_json()
amount = data["amount"]
currency = data["currency"]

# Create a Stripe checkout session
checkout_session = stripe.checkout.Session.create(
payment_method_types=["card"],
line_items=[
{
"price_data": {
"currency": currency,
"product_data": {
"name": "Sample Product",
},
"unit_amount": amount,
},
"quantity": 1,
},
],
mode="payment",
success_url="https://your-domain.com/success", # Replace with your success URL
cancel_url="https://your-domain.com/cancel", # Replace with your cancel URL
)
return jsonify({"session_id": checkout_session.id})

except Exception as e:
return jsonify({"error": str(e)}), 500

if __name__ == "__main__":
app.run(port=5000)