#ankur_code

1 messages · Page 1 of 1 (latest)

woven monolithBOT
#

👋 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.

torpid dagger
woven monolithBOT
waxen condor
#

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;
    }
}
fair kraken
#

👋 taking over for my colleague. Let me catch up.

waxen condor
#

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

fair kraken
#

you're putting extra params instead of putting metadata

                    .putExtraParam("tx", tx)```
waxen condor
#

tried both

fair kraken
#

trying to recreate the issue, please give me a minute

waxen condor
#

sessionBuilder.setSubscriptionData(SessionCreateParams.SubscriptionData.builder().putMetadata("tx", tx).putExtraParam("tx", tx).setTrialPeriodDays(trialDays).build());

#

Just tried with putMetadata("tx", tx)

fair kraken
#

would you mind sharing the request ID that is generated please?

#

req_xxx

waxen condor
#

One min

#

is it in session or in web hook ?

fair kraken
#

actually if you give me the event ID I could get their myself

waxen condor
#

req_btusi7bBSD016j

#

evt_1RBEUiKQ1sBUt8Xqda4sXE1A

fair kraken
#

that's expected since you don't have any trialPeriodDays

waxen condor
#

ohh!

#

my bad

fair kraken
#

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());```
waxen condor
#

Yes

#

correct its my bad

#

Thanks for the help. Its worked

fair kraken
#

glad to hear that