#yagnesh-p_best-practices

1 messages · Page 1 of 1 (latest)

barren bearBOT
#

👋 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/1460235780285796501

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

dull vapor
#

Can you share a session ID? cs_xxx

kindred wraith
#

cs_test_a1vkRbK35NaMUfXyisGXsBoFVLDxasKIWdAP6IPuEONXohBKk18nqbK2r4

dull vapor
#

Looking

kindred wraith
#

Is there any way to get the adaptive pricing amount in ui while stripe payment element is mounted? as i want to display that in one of my button.

dull vapor
kindred wraith
#

Okay thanks, let me verify the same

barren bearBOT
kindred wraith
#
            this.elements = await this.stripeV3.initCheckout({
                fetchClientSecret: () => this.getClientSecret(clientSecret),
                elementsOptions: { appearance: this.isDarkMode() ? STRIPE_APPEARANCE_ELEMENT_DARK_TW : STRIPE_APPEARANCE_ELEMENT_LIGHT_TW },
            });

            const shouldAddTerms = BUSINESS_PROFILE_TAGS_WITHOUT_TERMS.includes(this.profileTag());

            this.paymentElement = this.elements.createPaymentElement({
                ...(shouldAddTerms ? { terms: TERMS_CONFIG } : {}), layout: 'tabs'
            });

            this.isShowStripeElement.set(true);

            setTimeout(() => {
                this.paymentElement.mount('#payment-element');
            })

            const invoice = this.invoice();
            if (invoice?.type === INVOICE_TYPE.SINGLE) {
                const currencySelectorElement = this.elements.createCurrencySelectorElement();
                setTimeout(() => {
                    currencySelectorElement.mount('#currency-selector');
                })
            }
            const actions = await this.elements.loadActions();
            const session = actions.getSession();

            const total = session.total.total;
            console.log(total.amount);
            console.log(total.currency);

I am getting error: _this7.elements.loadActions is not a function

wind cobalt
#

hey there 👋 taking over from my colleague

I'm just taking a moment to get caught up!

kindred wraith
#

Okay

dull vapor
#

Ah, maybe just a variable naming thing?

kindred wraith
#

Yeah looks like it, but still getting the same error i pasted above.
I changed the code according to new doc you shared:
this.elements.loadActions().then(function (result) {
if (result.type === 'success') {
// Use the actions object to interact with the Checkout Session
const actions = result.actions;
var session = actions.getSession();
console.log('Session======', session);
}
});

dull vapor
#

Is this.elements definitely Checkout instance? Can you log it and share there

kindred wraith
#

i consoled the this.elemets:Stripe Elements initialized:

applyPromotionCode
: 
ƒ (e)
changeAppearance
: 
ƒ (e)
confirm
: 
ƒ ()
createBillingAddressElement
: 
ƒ (e)
createCurrencySelectorElement
: 
ƒ ()
createExpressCheckoutElement
: 
ƒ (e)
createPaymentElement
: 
ƒ (e)
createShippingAddressElement
: 
ƒ (e)
getBillingAddressElement
: 
ƒ ()
getCurrencySelectorElement
: 
ƒ ()
getExpressCheckoutElement
: 
ƒ ()
getPaymentElement
: 
ƒ ()
getShippingAddressElement
: 
ƒ ()
loadFonts
: 
ƒ (e)
on
: 
ƒ (e,n)
removePromotionCode
: 
ƒ ()
runServerUpdate
: 
ƒ (e)
session
: 
ƒ ()
updateBillingAddress
: 
ƒ (t)
updateEmail
: 
ƒ (e)
updateLineItemQuantity
: 
ƒ (e)
updatePhoneNumber
: 
ƒ (e)
updateShippingAddress
: 
ƒ (t)
updateShippingOption
: 
ƒ (e)
updateTaxIdInfo
: 
ƒ (e)
_sdkVersion
: 
"v1_server_updates_1_adaptive_pricing_2"``` 
and so on ......
dull vapor
#

Which version of Stripe.js are you using?

#

Before that you could just do const session = checkout.session() and have access to the session

kindred wraith
#

I am using 2025-04-30.basil
I am still getting error by using this too:

const session = this.elements.getSession();
            console.log('Stripe Session===:', session);

error: _this7.elements.getSession is not a function
Any ways I have got the docs that you have shared, I will figure something out.

dull vapor
#

Because that's wrong. You just need:

const checkout = await stripe.initCheckout({
  fetchClientSecret: () => clientSecret
});

const session = checkout.session()
// do whatever with `session` to get the currency/total data
kindred wraith
#
   this.elements = await this.stripeV3.initCheckout({
                fetchClientSecret: () => this.getClientSecret(clientSecret),
                elementsOptions: { appearance: this.isDarkMode() ? STRIPE_APPEARANCE_ELEMENT_DARK_TW : STRIPE_APPEARANCE_ELEMENT_LIGHT_TW },
            });
 const session = this.elements.getSession();
            console.log('Stripe Session===:', session);

I think just the variables are different

dull vapor
#

No, you're using the wrong method. It's not getSession(), it's session()

#

They're two different methods entirely. In your version of Stripe.js, initCheckout is async and we fetch the session upfront so then you can just access it via the session() method

The code you're trying to use is the new synchronous path which is more performant, but doesn't load the session object until you explicitly request it, via the async loadActions and getSession methods. Your version of Stripe.js doesn't work that way, hence the errors

kindred wraith
#

Okay with this session() i got the element and worked, now how will i get the local amount, via some different load actions only or other way

dull vapor
kindred wraith
#

Okay thanks

dull vapor
#

Did that help? Do you have the data you need?