#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/1296702823286964277
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
hi there, can you share the request id [0]? it'd look like req_xxx
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
sure Please give me a sec Thanks
req_8ROYJGC8I3daV4 HI @stark sable Please find request id
there's no error for this request though : https://dashboard.stripe.com/test/logs/req_8ROYJGC8I3daV4
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 its ok can I share scrren shot of my logs?
sure
please find the screenshot above
can you paste the full stacktrace of the error, it's cut off midway
what's at index.ts line 80?
`createSubscriptionHandler() - unexpected error: ${JSON.stringify(error)}`
);
if (error instanceof ServiceError) {
switch (error.data.code) {
case "STRIPE_CUSTOMER_NOT_FOUND":
case "STRIPE_SUBSCRIPTION_ERROR":
case "NFT_NOT_REGISTERED":
case "SUBSCRIPTION_ALREADY_EXISTS":
case "STRIPE_SUBSCRIPTION_CREATION_FAILED":
throw new HttpResponseError(error.data.code, error.message);
default:
throw new HttpResponseError(
"internal-server-error",
"Unexpected error while handling the createSubscription request"
);
}
}
the subscription creation is clearly fine, you'll should step through your code after that to see where the issue is actually occurring
ok I think I found something when iam trying to pull latest_invocie.paymentintentid ists null beacuse the invocie seems to be null
any idea why is that?
btw subscription creation is a promise, how come you're not waiting for it to complete before returning?
i wrapped it in fucntion
https://docs.stripe.com/api/subscriptions/create?lang=node - we show in our example const subscription = await stripe.subscriptions.create
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
stripeCustomerId: string,
priceId: string,
nfts: number[],
dbSubscriptionId: string,
dbUserId: string
) {
const now = new Date();
const currentQuarterEnd = endOfQuarter(now);
console.log(Math.floor(currentQuarterEnd.getTime() / 1000));
return stripe.subscriptions.create({
customer: stripeCustomerId,
items: [{ price: priceId, quantity: nfts.length }],
payment_settings: {
payment_method_types: ["card", "paypal"],
save_default_payment_method: "on_subscription",
},
payment_behavior: "default_incomplete",
expand: ["latest_invoice.payment_intent", "schedule"],
metadata: {
userId: dbUserId,
subscriptionId: dbSubscriptionId,
nfts: JSON.stringify(nfts),
},
proration_behavior: "none",
collection_method: "charge_automatically",
billing_cycle_anchor: Math.floor(currentQuarterEnd.getTime() / 1000),
});
}```
customer.stripeCustomerId,
product.priceId,
nfts,
dbSubscription.id,
dbSubscription.userId
);```
usage
what's the actual line of code where you try to access latest_invocie.paymentintentid -> there's clearly typos here
because you set
"proration_behavior": "none",
"billing_cycle_anchor": "1735669799",
There's nothing to be charged on the first invoice. There's a pending_setup_intent which you would use to collect the payment method details instead
buisness has decided is the first payment would consider for complete quarter
and then rest can follow the quarter in sync with yearly quarters how shoud i approach it
i don't understand what you mean by the first payment would consider for complete quarter, can you illustrate with an example as to what's the ideal situation?
sure
a user comes in and buys 1 sub in 4th quarter of 2024 on OCT 21 our subscription period is 3 months now we want that current period should end with end of quarter we have some rewards to pay though they would register after the quarter has started we would pay them rewards for whole quarter and then the upcoming payments should follow the yearly quarter cycle i.e jan-mar .... so on
what do you expect them to pay for the subscription when they start it on oct 21? should it be a prorated amount?
complete amount
we dont want any prorations as we would be paying them based on complete payment
gimme a while to test something out
sure Thank you
okay, i think i got something that works, typing it out right now...
At a high level,
- create a subscription as per normal
- After the subscription is successful, create a subscription schedule for the existing subscription and set the billing_cycle_anchor to start at the end of the quarter with no prorations
You need to update the below example with your own Price id
const testClock = await stripe.testHelpers.testClocks.create({
frozen_time: Math.floor(+new Date() / 1000),
});
const customer = await stripe.customers.create({
description: 'test clock customer',
email : 'test@example.com',
test_clock: testClock.id,
payment_method: 'pm_card_amex_threeDSecureNotSupported',
invoice_settings : {
default_payment_method : 'pm_card_amex_threeDSecureNotSupported'
}
});
const subscription = await stripe.subscriptions.create({
customer: customer.id,
items: [
{price:'price_xxx'} // USD 3 months
],
});
console.log(subscription);
const schedule = await stripe.subscriptionSchedules.create({
from_subscription: subscription.id,
});
const subscriptionSchedule = await stripe.subscriptionSchedules.update(
schedule.id, {
phases:[
{
start_date : schedule.phases[0].start_date,
end_date : 1735689600,
items: [{
price: 'price_xxx'
}],
proration_behavior: "none",
},
{
billing_cycle_anchor : "phase_start",
items: [{
price: 'price_xxx'
}],
proration_behavior: "none",
}
]
}
);
console.log(subscriptionSchedule);
test it and see if it fits what you're looking for
thank you so much will try