#bennn

1 messages · Page 1 of 1 (latest)

clear flintBOT
haughty elm
#

hello! what do you need help with?

cobalt tusk
#

Request req_k3vc3m01slwPqX: The price specified is set to type=recurring but this field only accepts prices with type=one_time.

haughty elm
#

it seems fairly self explanatory, what are you trying to do here?

#

you can't create an InvoiceItem with a recurring Price

cobalt tusk
haughty elm
cobalt tusk
#

oh ok

#

is that hard

#

?

haughty elm
#

you can look through the guides to decide if it's difficult

cobalt tusk
#

is there a python example? @haughty elm

haughty elm
#

which integration flow are you using? Are you using Stripe Checkout or custom code a.k.a Elements?

cobalt tusk
# haughty elm which integration flow are you using? Are you using Stripe Checkout or custom co...
async def donate(email: str, stripe_price_id: str, discord_author_id: str):
    try:
        # Check if the user already has a pending invoice
        existing_payment = await db_payments["payments"].find_one(
            {"discord_id": discord_author_id, "paid": False}
        )
        if existing_payment:
            return (
                "You already have a pending invoice. Please use `/cancel_invoice` to cancel the existing invoice before creating a new one.",
            )

        # Create Stripe customer
        customer = stripe.Customer.create(email=email)

        # Create Stripe invoice
        invoice_item = stripe.InvoiceItem.create(
            customer=customer.id,
            price=stripe_price_id,  # Replace with your Stripe price ID
        )

        invoice = stripe.Invoice.create(
            customer=customer.id,
            auto_advance=True,
            pending_invoice_items_behavior="include",
        )

        # Finalize the invoice
        finalised_invoice = stripe.Invoice.finalize_invoice(invoice.id)

        # Log unpaid invoice to the "payments" MongoDB collection
        await db_payments["payments"].insert_one(
            {
                "discord_id": discord_author_id,
                "email": email,
                "invoice_id": finalised_invoice.id,
                "paid": False,
                "invoice_url": finalised_invoice.hosted_invoice_url,
            }
        )

        # Send the invoice URL to the user
        # Direct message the user the link as well
        return finalised_invoice.hosted_invoice_url
    except Exception as e:
        print(e)
        return f"Error creating your invoice, {e}"

#

i have options for user to chose one time payment or recurring

haughty elm
#

you can't use the Invoice API to create Subscriptions

cobalt tusk
#

a custom link for them?

haughty elm
cobalt tusk
#

Okay 24 hrs looks good

#

and i can like check if itws been paid similar to invoices?

haughty elm
cobalt tusk
#

thanks

cobalt tusk
#

im confused on how to pass a customer in @haughty elm

haughty elm
#

what have you tried?

#

and what's the issue?

cobalt tusk
#

i dont see a customer parameter like invoices have

haughty elm
cobalt tusk
#

sry i was looking qat more parameters

#

it says customer above

#

my bade

#

do i need a website?

#

for the success url

haughty elm
#

do you need to ensure you don't have duplicate customers in Stripe?

#

If you don't need to de-duplicate customers then maybe you should just use Payment Links instead

#

it doesn't require a success_url

cobalt tusk
#

hm

#

can i tell u the use case and maybe u know?

haughty elm
#

sure

cobalt tusk
#

well i run a service where i sell access via discord

#

and this is a bot im making to do it all

#

(i used to use a paid website solution but need to cut costs)

#

im letting the user add 30 days thru invoices

#

or setup a subscription

#

so ye

#

i sent my invoice code above

haughty elm
#

then yes, you probably do need to maintain unique Customers to easily track data, so you should use Checkout Sessions (not Payment Links). I suggest you set a meaningful page as the success page otherwise your customers are going to be really confused if they get sent to google after successful payment, but it's ultimately up to you

cobalt tusk
#

would it be okay if i make like a pastebin or smth that says check discord

haughty elm
#

it should work, you can test it out

cobalt tusk
#

bc my bot tells the user that their payment was successful and they were added

#

ok cool