#ankur_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/1358773018091982848
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
Try using this param instead: https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Should be set on checkout.session.*, customer.subscription.* and invoice.* events (in this hash: https://docs.stripe.com/api/invoices/object#invoice_object-parent-subscription_details)
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
My code
public Session session(String customer, Subscription subscription, BillingCycle billingCycle, String tx) {
try {
String priceId = subscription.getPriceIds().get(billingCycle);
long trialDays = subscription.getFreeTrialDays();
double discount = billingCycle == BillingCycle.MONTHLY ? 0 : subscription.getDiscount();
SessionCreateParams.Builder sessionBuilder = SessionCreateParams.builder()
.setMode(SessionCreateParams.Mode.SUBSCRIPTION)
.setSuccessUrl(redirect + "/success" + "?session_id={CHECKOUT_SESSION_ID}&tx=" + tx)
.setCancelUrl(redirect + "/failed" + "?session_id={CHECKOUT_SESSION_ID}&tx=" + tx)
.setCustomer(customer)
.addLineItem(SessionCreateParams.LineItem.builder()
.setPrice(priceId)
.setQuantity(1L)
.build());
if (trialDays > 0) {
sessionBuilder.setSubscriptionData(SessionCreateParams.SubscriptionData.builder()
.putExtraParam("tx", tx)
.setTrialPeriodDays(trialDays)
.build());
}
if (discount > 0) {
CouponCreateParams couponParams = CouponCreateParams.builder()
.setPercentOff(new BigDecimal(discount))
.setDuration(CouponCreateParams.Duration.ONCE)
.build();
Coupon coupon = Coupon.create(couponParams);
sessionBuilder.addDiscount(SessionCreateParams.Discount.builder()
.setCoupon(coupon.getId())
.build());
} else {
sessionBuilder.setAllowPromotionCodes(true);
}
sessionBuilder.putMetadata("tx", tx);
SessionCreateParams params = sessionBuilder.build();
return Session.create(params);
} catch (Exception e) {
return null;
}
}
👋 taking over for my colleague. Let me catch up.
Hey Tarzan
I'm trying to propagate a custom transaction key (tx) that I generate when creating a Checkout Session for a subscription. I need this key to be consistently available in the webhooks.
I can confirm that the tx metadata is present on the Session object, but it's not automatically carried over to the Subscription or Invoice objects. I tried using putExtraParam("tx", tx) in SubscriptionData, but it doesn’t seem to be showing up in the webhook payloads for subscriptions or invoices.
I am using above code
you're putting extra params instead of putting metadata
.putExtraParam("tx", tx)```
tried both
trying to recreate the issue, please give me a minute
sessionBuilder.setSubscriptionData(SessionCreateParams.SubscriptionData.builder().putMetadata("tx", tx).putExtraParam("tx", tx).setTrialPeriodDays(trialDays).build());
Just tried with putMetadata("tx", tx)
Find help and support for Stripe. Our support site provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
actually if you give me the event ID I could get their myself
that's expected since you don't have any trialPeriodDays
I suggest doing it differently though
create the builder first SessionCreateParams.SubscriptionData.builder()
then set the metadata if it's always going to be available
.putMetadata("tx", tx)
basically something like that
SessionCreateParams.SubscriptionData.Builder subscriptionDataBuilder = SessionCreateParams.SubscriptionData.builder()
.putMetadata("tx", tx);
if (trialDays > 0) {
subscriptionDataBuilder.setTrialPeriodDays(trialDays);
}
sessionBuilder.setSubscriptionData(subscriptionDataBuilder.build());```
glad to hear that