#chunkyboi_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1420102622521720934
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there! also wanted to say hi to an ex-coworker (I used to work at Stripe haha)
hello! if you want to DM me their name i can pass it along ๐
hey! I meant just to you haha
sorry about the confusion
but yea anyway I have this problem - happy to hop on a call as well
ooooo haha hello!
my @ was @andycai
but yea we have this issue on our hand, was wondering if you could help us with it
ok, so basically you just need a free subscription forever?
yes
and to be clear, for the $0 subscription, we do not need the customer to go through a checkout flow. The ideal solution is actually we'd create a Stripe customer object, a subscription object
invoices are not even required as long as we can listen to some objects of the subscription being renewed (refreshed), I just mentioned invoice because I know we can listen to invoice.paid event
you should be able to configure that but it's been a while since i've done it... you can create a $0 price, attach it to subscriptions, and then there's a way to only collect payment methods if required. what surface are you using for these? checkout, creating subscriptions directly, etc?
so for this specific use case, I've already created a product with a $0 price
just not sure where the PM requirement configuration lives
this is my account id: acct_1S8u28EsEIWx7LWK
This is the product: https://dashboard.stripe.com/acct_1S8u28EsEIWx7LWK/test/products/prod_T6QxKuFCipCuu9
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
if you have a subscription with $0 prices then the invoices should automatically pay when the subscription period renews... have you already tried testing this? if so can you share an example subscription ID? i can also spin up a test real quick
I actually have not tested it locall yet
but I was able to create a sub here to the free tier: sub_1SAHndEsEIWx7LWKNLiJADvy
but this was through dashboard, and no payment method was required
just tested it with test clock: https://dashboard.stripe.com/acct_1S8u28EsEIWx7LWK/test/subscriptions/sub_1SAHndEsEIWx7LWKNLiJADvy
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
but there was a payment method on file so maybe that's not the best example
let me try creating a new subscription without a pm
ok yes, i just created a customer with no default payment method, created a subscription with a $0 price, and advanced it with test clocks, and it looks like the invoices are automatically paying as expected
oh wait that's awesome!
so this should just work
is it possible to accomplish this programmatically
feel free to send over the code
yep! create_test_clock_customer is just a wrapper function that creates a customer, attaches a test clock, and gives them a default payment method (or none if you pass an empty string like i did here)
customer = create_test_clock_customer(payment_method="")
print(customer.id)
subscription = client.subscriptions.create(params={
"customer": customer.id,
"items": [{"price": "price_1SAaOnLFIO5qXQOWeWbXruJv"}],
})
print(subscription.id)
advance_clock(customer.test_clock, increment=1 * 60 * 60 * 24 * 31) # 31 days
advance_clock(customer.test_clock, increment=1 * 60 * 60 * 24 * 31) # 31 days
advance_clock(customer.test_clock, increment=1 * 60 * 60 * 24 * 31) # 31 days
payment_method="pm_card_visa",
email="testy-test@test.com",
start_time=int(datetime.now().timestamp()),
cust_params={},
):
"""
Create customer with assigned test clock
Args:
stripe (Stripe): Instantiated stripe client library
payment_method (str, optional): Payment method to attach to customer. Defaults to 'pm_card_visa'.
email (str, optional): Email associated with customer record. Defaults to "testy-test@example.com".
Returns:
stripe.Customer: The customer object created
"""
clock = create_test_clock(start_time=start_time)
kwargs = {
"email": email,
"description": "Test clock customer",
"name": "Clocky McClockerton",
"test_clock": clock.id,
}
if cust_params:
kwargs.update(cust_params)
if payment_method:
kwargs["payment_method"] = payment_method
kwargs["invoice_settings"] = {"default_payment_method": payment_method}
tc_customer = stripe.Customer.create(**kwargs)
return tc_customer```
what we want is ideally:
- when the customer logs into our platform, we create a stripe customer object
- we attach the newly created customer object to the product
- The subscription is created and a $0 invoice is gnerated per month (the invoice part is optional)
"""
Advance a test clock by a specified increment
Args:
- stripe (Stripe): Instantiated client library
- clock_id (str): ID of test clock to advance
- increment (int, optional): Increment in seconds to advance the clock's frozen time. Defaults to 864000 (10 days in seconds).
- timedelta (datetime.timedelta, optional): Timedelta object to use for incrementing the clock. Defaults to False (not using).
"""
if timedelta:
increment = int(timedelta.total_seconds())
clock = stripe.test_helpers.TestClock.retrieve(clock_id)
new_frozen_time = clock.frozen_time + increment
clock = stripe.test_helpers.TestClock.advance(
clock_id, frozen_time=new_frozen_time
)
clock_finished = False
print(f"Advancing {clock.id} to {clock.frozen_time}...")
while not clock_finished:
time.sleep(1)
clock = stripe.test_helpers.TestClock.retrieve(clock_id)
if clock.status == "ready":
clock_finished = True
elif clock.status == "internal_failure":
raise Exception(f"Clock {clock_id} failed to advance.")```
oh wow that's awesome!
haha I know about advance_clock, p sure my ex-manager built it
ok this is awesome
so I just do payment_method = "" and it should be able to create a customer without a PM
i wrote this one actually ๐
yep!
oh wait
yep makes sense
ok anyways if you work with Marko btw say hi to him for me
but this is great
does this subscription generate an invoice?
and more qs:
in my use case, which events should I be listening to?
my action is that I want to perform an internal topup of credits in our system
ok awesome
and that'll also send for the $0 sub as well right
this is the events I'm listening to right now
lmk if there's any discrepency
that looks good to me!
idk if you have looked at this page yet but it covers pretty much every possible event and gives suggestions on how to handle it
yeap! also thank you very much
if I have further questions should I use the built-in workflows
or can I just hit you up directly?
built in workflows! we take turns responding to questions in the server so there is a very good chance i won't be around when you have another question
another question, when we create those $0 subscriptions and the invoices are created, will emails be sent to the customers?
is that configurable by any chance
the short answer is yes but there are a lot of email options available, this page does a good job of covering them all
but the default is to not send emails right
ideally we don't send any emails that we don't configure ourselves
and for subscription upgrades, I'm assuming we should use the update subscription endpoint?
it depends on the settings in your stripe account, i would go to the settings page in your stripe account and make sure you have the settings disabled just to be sure
https://dashboard.stripe.com/settings/billing/subscriptions
yep! just update and set a new price for the line item
Is it possible to have checkout session handle the entire subscription upgrade flow instead of us?
for that you'd want to look at the customer portal which allows you to create a session that allows users to upgrade subscriptions, cancel them, update payment methds etc (you can configure which of these options you want enabled)
https://docs.stripe.com/customer-management