import stripe
from espy_pay.us.stripe.CONSTANTS import STRIPE_KEY
from espy_pay.general.schema import TranxDto
import logging
logger = logging.getLogger(__name__)
async def create_stripe(data: TranxDto):
    """
    This function creates a payment intent on Stripe.
    Args:
        data (dict): A dictionary containing the payment data.
    """
    try:
        stripe.api_key = STRIPE_KEY
        intent = stripe.PaymentIntent.create(
            amount=data.amount,
            currency=data.currency,
            automatic_payment_methods={"enabled": True}
        )
        logger.info(f"Payment intent created: {intent}")
        return intent
    except Exception as e:
        logger.error(f"Error creating payment intent: {e}")
        raise e
    
async def confirm_stripe(intent_id: str, payment_method: str):
    """
    This function confirms a payment intent on Stripe.
    Args:
        data (dict): A dictionary containing the payment data.
    """
    try:
        stripe.api_key = STRIPE_KEY
        intent = stripe.PaymentIntent.confirm(
            intent_id,
            payment_method,
        )
        logger.info(f"Payment intent confirmed: {intent}")
        return intent
    except stripe.error as e:
        logger
        raise e