lnbits/extensions/streamalerts/views_api.py
async def api_create_donation(data: CreateDonation, request: Request):
    """Take data from donation form and return satspay charge"""
    # Currency is hardcoded while frotnend is limited
    cur_code = "USD"
    sats = data.sats
    message = data.message
    # Fiat amount is calculated here while frontend is limited
    price = await btc_price(cur_code)
    amount = sats * (10 ** (-8)) * price
    webhook_base = request.url.scheme + "://" + request.headers["Host"]
    service_id = data.service
    service = await get_service(service_id)
    charge_details = await get_charge_details(service.id)
    name = data.name if data.name else "Anonymous"

    description = f"{sats} sats donation from {name} to {service.twitchuser}"
    create_charge_data = CreateCharge(
        amount=sats,
        completelink=f"https://twitch.tv/{service.twitchuser}",
        completelinktext="Back to Stream!",
        webhook=webhook_base + "/streamalerts/api/v1/postdonation",
        description=description,
        **charge_details
    )
    charge = await create_charge(user=charge_details["user"], data=create_charge_data)
    await create_donation(
        id=charge.id,
        wallet=service.wallet,
        message=message,
        name=name,
        cur_code=cur_code,
        sats=data.sats,
        amount=amount,
        service=data.service,
    )
    return {"redirect_url": f"/satspay/{charge.id}"}
Take data from donation form and return satspay charge
Take data from donation form and return satspay charge
Take data from donation form and return satspay charge
async def api_create_donation(data: CreateDonation, request: Request):
    cur_code = "USD"
    sats = data.sats
    message = data.message
    price = await btc_price(cur_code)
    amount = sats * (10 ** (-8)) * price
    webhook_base = request.url.scheme + "://" + request.headers["Host"]
    service_id = data.service
    service = await get_service(service_id)
    charge_details = await get_charge_details(service.id)
    name = data.name if data.name else "Anonymous"
    description = f"{sats} sats donation from {name} to {service.twitchuser}"
    create_charge_data = CreateCharge(
        amount=sats,
        completelink=f"https://twitch.tv/{service.twitchuser}",
        completelinktext="Back to Stream!",
        webhook=webhook_base + "/streamalerts/api/v1/postdonation",
        description=description,
        **charge_details
    )
    charge = await create_charge(user=charge_details["user"], data=create_charge_data)
    await create_donation(
        id=charge.id,
        wallet=service.wallet,
        message=message,
        name=name,
        cur_code=cur_code,
        sats=data.sats,
        amount=amount,
        service=data.service,
    )
    return {"redirect_url": f"/satspay/{charge.id}"}
async def api_create_donation ( data : CreateDonation , request : Request ) : cur_code = "USD" sats = data . sats message = data . message price = await btc_price ( cur_code ) amount = sats * ( 10 ** ( - 8 ) ) * price webhook_base = request . url . scheme + "://" + request . headers [ "Host" ] service_id = data . service service = await get_service ( service_id ) charge_details = await get_charge_details ( service . id ) name = data . name if data . name else "Anonymous" description = f"{sats} sats donation from {name} to {service.twitchuser}" create_charge_data = CreateCharge ( amount = sats , completelink = f"https://twitch.tv/{service.twitchuser}" , completelinktext = "Back to Stream!" , webhook = webhook_base + "/streamalerts/api/v1/postdonation" , description = description , ** charge_details ) charge = await create_charge ( user = charge_details [ "user" ] , data = create_charge_data ) await create_donation ( id = charge . id , wallet = service . wallet , message = message , name = name , cur_code = cur_code , sats = data . sats , amount = amount , service = data . service , ) return { "redirect_url" : f"/satspay/{charge.id}" }
Take data from donation form and return satspay charge
Take data from donation form and return satspay charge
"""Take data from donation form and return satspay charge""" # Currency is hardcoded while frotnend is limited # Fiat amount is calculated here while frontend is limited
data
CreateDonation
request
Request