from flask import jsonify import stripe from app.pay import pay from app import db from app.classes.delivery import Delivery_Delivery from app.classes.service import Service_Call_Money @pay.route("/oil/", methods=["GET"]) def create_charge_oil(delivery_id): get_oil_delivery = db.session\ .query(Delivery_Delivery)\ .filter(Delivery_Delivery.id == delivery_id)\ .first() if get_oil_delivery.customer_asked_for_fill == 1: gallons = get_oil_delivery.gallons_ordered else: gallons = 250 checkout_session = stripe.checkout.Session.create( success_url='http://localhost:5173/success', cancel_url='http://localhost:5173/canceled', payment_method_types=['card'], mode='payment', line_items=[ { 'price': 'price_1OXTkZJznCGgUo9kIoz37lwg', 'quantity': gallons, }, ] ) return jsonify({'sessionId': checkout_session['id']}) @pay.route("/service/", methods=["GET"]) def create_charge_service(service_id): get_service_call = db.session\ .query(Service_Call_Money)\ .filter(Service_Call_Money.service_call_id == service_id)\ .first() amount_to_charge = round(float(get_service_call.total_cost_service) * 100) ## TODO try stripe.charge.create ???! checkout_session = stripe.checkout.Session.create( success_url='http://localhost:5173/success', cancel_url='http://localhost:5173/canceled', payment_method_types=['card'], mode='payment', line_items=[ { 'price': 'price_1OXTkZJznCGgUo9kIoz37lwg', 'quantity': amount_to_charge, }, ] ) return jsonify({'sessionId': checkout_session['id']})