#windy_applepay-trial
1 messages ยท Page 1 of 1 (latest)
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.
- windy_code, 12 hours ago, 22 messages
- windy_code, 1 day ago, 53 messages
- windy_code, 2 days ago, 18 messages
๐ 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/1238173251096805408
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
windy_applepay-trial
@rocky frigate can you share the code that creates the Subscription server-side?
Sure
const customer = await handleCreateCustomer(user);
console.log('created customer:', customer.id);
const product = await getStripeProduct(membershipPlan.stripeProductId);
console.log('got product:', product.id);
const metadata: CreateSubscriptionMetadata = {
userId: userToken.uid,
// This is needed for plan upgrades
membershipPlanId: membershipPlan.id as string,
paymentCardType: cardType,
};
// should check if product has default_price on stripe dashboard
const subscription = await createSubscription(
customer.id,
product.default_price as string,
initializeTrial,
metadata
);
console.log('created subscription:', subscription.id);
let clientSecret: string | null;
if (initializeTrial) {
clientSecret = (subscription.pending_setup_intent as Stripe.SetupIntent)
?.client_secret;
} else {
clientSecret = (
(subscription?.latest_invoice as Stripe.Invoice)
?.payment_intent as Stripe.PaymentIntent
)?.client_secret;
}
console.log(
`client secret (initializeTrial=${initializeTrial}):`,
clientSecret
);
return res.status(200).send({
status: 'success',
data: {
subscriptionId: subscription.id,
clientSecret,
},
});
yeah sorry that's not what I want
Just the exact code that calls the Create Subscription API
sec
but wait if (initializeTrial) { clientSecret = (subscription.pending_setup_intent as Stripe.SetupIntent) ?.client_secret; }
you have this, so you already understand the concept of pending_setup_intent right?
const createSubscription = async (
customerId: string,
priceId: string,
initializeTrial: boolean,
metadata: CreateSubscriptionMetadata
): Promise<Stripe.Response<Stripe.Subscription>> => {
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [
{
price: priceId,
},
],
metadata,
trial_period_days: initializeTrial
? SEVEN_DAYS_FREE_TRIAL_LENGTH
: undefined,
payment_behavior: 'default_incomplete',
payment_settings: { save_default_payment_method: 'on_subscription' },
expand: ['latest_invoice.payment_intent'],
});
return subscription;
};
ah yeah here we go! expand: ['latest_invoice.payment_intent'],
yeah a bit ๐
this is the bug. Here you expand the latest Invoice's PaymentIntent to get its client_secret.
But you do not expand the pending_setup_intent so you are getting back pending_setup_intent: 'seti_123' as a string so your code I quoted above fails to find the client_secret
Change to expand: ['latest_invoice.payment_intent', 'pending_setup_intent'], and it should now work
Amazing, thank you. Let me update it and test my app