#bennn
1 messages · Page 1 of 1 (latest)
hello! what do you need help with?
im getrting that error
Request req_k3vc3m01slwPqX: The price specified is set to type=recurring but this field only accepts prices with type=one_time.
it seems fairly self explanatory, what are you trying to do here?
you can't create an InvoiceItem with a recurring Price
send a recurring invpoice
you'd want to create a Subscription then, i suggest you start from this page : https://stripe.com/docs/billing
you can look through the guides to decide if it's difficult
is there a python example? @haughty elm
which integration flow are you using? Are you using Stripe Checkout or custom code a.k.a Elements?
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
you can't use the Invoice API to create Subscriptions
your option here is either to use Stripe Checkout - https://stripe.com/docs/payments/checkout, or build your own custom UI using the Payment Element - https://stripe.com/docs/payments/payment-element
stripe checkout lets me give the user a link?
a custom link for them?
Yes, it does generate a link for them to access. However, the link expires within a certain time - https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-expires_at
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
If you want one with no expiry time, you can look into Payment Links instead : https://stripe.com/docs/payment-links
yes, you can check if it's been paid, you can go through : https://stripe.com/docs/payments/checkout/fulfill-orders
thanks
im confused on how to pass a customer in @haughty elm
well im looking at the docs
i dont see a customer parameter like invoices have
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
sry i was looking qat more parameters
it says customer above
my bade
do i need a website?
for the success url
uhh i dont hsve one
can i just put google.com?
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
sure
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
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
ah ur right
would it be okay if i make like a pastebin or smth that says check discord
it should work, you can test it out