#ninjajinja_code
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/1298252415518248961
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- ninjajinja_code, 4 days ago, 41 messages
some more code
* Creates a Stripe subscription schedule for indefinite quarterly billing with invoices sent 15 days before each quarter starts.
*
* This function sets up a subscription schedule that:
* 1. Starts 15 days before the next quarter begins.
* 2. Creates a single, indefinitely recurring phase.
* 3. Uses invoice-based billing with a 15-day payment window.
* 4. Continues billing as long as the subscription remains active.
*
* @param subscriptionId The ID of the existing Stripe subscription to schedule.
* @param quantity The number of subscription items.
* @param priceId The Stripe Price ID for the subscription items.
* @returns A promise that resolves to the created Stripe subscription schedule object.
*
* @throws Will throw an error if the Stripe API call fails.
*
* @example
* try {
* const schedule = await createStripeSubscriptionSchedule('sub_1234567890', 2, 'price_9876543210');
* console.log('Subscription schedule created:', schedule.id);
* } catch (error) {
* console.error('Failed to create subscription schedule:', error);
* }
*/
export async function createStripeSubscriptionSchedule(subscriptionId: string) {
return stripe.subscriptionSchedules.create({
from_subscription: subscriptionId,
});
}```
* Updates a Stripe subscription schedule with new phases, pricing, and quantity.
*
* @param {string} scheduleId - The ID of the Stripe subscription schedule.
* @param {number} scheduleStartDate - The Unix timestamp for when the schedule starts.
* @param {string} price - The ID of the Stripe price object to use for the subscription.
* @param {number} quantity - The quantity of the subscription item.
* @returns {Promise<Stripe.SubscriptionSchedule>} - A promise that resolves when the schedule is updated.
*/
export async function updateStripeSubscriptionSchedule(
scheduleId: string,
scheduleStartDate: number,
price: string,
quantity: number
): Promise<Stripe.SubscriptionSchedule> {
const now = new Date();
const currentQuarterEnd = endOfQuarter(now);
const nextQuarterStart = addDays(currentQuarterEnd, 1);
// Get the next quarter start date as a Unix timestamp (in seconds)
const endDateInSeconds = getUnixTime(nextQuarterStart);
return stripe.subscriptionSchedules.update(scheduleId, {
phases: [
{
start_date: scheduleStartDate,
end_date: endDateInSeconds,
items: [
{
price,
quantity, // Ensure correct quantity is set
},
],
proration_behavior: "none",
},
{
billing_cycle_anchor: "phase_start",
items: [
{
price,
quantity, // Set quantity for the next phase as well
},
],
proration_behavior: "none",
},
],
});
}```
Sorry, don't understand what you're asking for help with specifically? Sounds like you want to send a reminder if an invoice is unpaid?
yes and also set a time period during which a user can pay if they can't sub lapses we want to mark it as canceled
but dont want to go invoice route
Those are things you'd need to build yourself:
- We have automatic retries for invoice payments in failure scenarios which have some related emails. See: https://docs.stripe.com/billing/revenue-recovery/customer-emails
- We don't automatically cancel subscriptions after a specific time period in all scenarios โ only on creation if it doesn't transition to active
hi! I'm taking over this thread. let me know if you have other questions.
hi @eager trench
I had question can we take one of payment first and then roll it to a subscription?
so we take 1 of payment form user and them create a susbcription for them
It's technically possible yes. why do you want to do this?