#417goose_api
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/1242927078635081728
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Updating the amount on the elements object would be the way to update it in the UI: https://docs.stripe.com/js/elements_object/update#elements_update-options-amount
That's not working?
Correct, that is not working already doing that
I am outputting into the console the new amount before I run the elements.update(amount: xxx); but it doesn't change it
Just a visual to show what I am talking about
been working on this for days it seems
code to update: elements.update({amount:parseInt(amount)});
Hm so you called elements.update prior to clicking the link button?
I clear all cookies/cache, add items to cart, click "Pay with Link" it opens window, fill out the email/phone and shipping address when I enter the shipping address it fires off the change to to get the tax amounts and then i call elements.update({amount:parseInt(amount)});
it stays the same value (you'll notice the background it changes on the right part of the screen).
when I clicked the Pay with Link" button the amount was $18.98, after shipping address changed it adds the tax to 19.64
Interesting. Hmm let me check with a colleague on this
Ok thank you
Someone who's a little more familiar with that link flow
Will let you know when I hear back
Can you share your front end code for this?
Front end like the <div id="elements"> code? or the js
Yeah the js for listening to shipping changes and updating amounts
ok give me a second
const expressCheckoutElement = elements.create(
'expressCheckout', exoptions
)
expressCheckoutElement.mount('#express-checkout-element')
const handleError = (error) => {
const messageContainer = document.querySelector('#error-message');
messageContainer.textContent = error.message;
}
expressCheckoutElement.on('click', (event) => {
const options = {
shippingAddressRequired: true,
allowedShippingCountries: ['US'],
shippingRates: [
{
id: '<cfoutput>#session.shipping#</cfoutput>',
displayName: 'Shipping',
amount: <cfoutput>#Replace(session.shipamt,".","")#</cfoutput>,
},
]
};
event.resolve(options);
});
expressCheckoutElement.on('shippingaddresschange', function(event) {
let resolve = event.resolve;
let address = event.address;
console.log('shipping address');
console.log(address);
console.log(address.postal_code);
let url = "/checkoutajax.cfm?process=getAmounts";
$.post(url, {
state: address.state,
country: address.country,
postalcode: address.postal_code,
memberid: <cfoutput>#val(session.memberloggedin.memberid)#</cfoutput>,
taxexempt: <cfoutput>#val(session.taxExempt)#</cfoutput>
}).done(function (response) {
$('.ordersummary').load('checkout_ordersummary.cfm');
data = response;
console.log('---')
console.log(data);
console.log('---')
console.log('tax ---> ' + response.tax);
console.log('amt ---> ' + response.amttocharge);
console.log('wt --->' + response.wallettotal);
let amount = parseInt(response.wallettotal);
updatePaymentIntent(response.wallettotal,'usd');
});
resolve();
})
// Update Payment Intent
function updatePaymentIntent(amount,currency) {
let mydata = {
amount: amount,
currency: currency
}
let url = "/checkoutajax.cfm?process=paymentIntentUpdate";
elements.update({amount:parseInt(amount)});
$.ajax({
cache: false,
type: "POST",
url: url,
data: mydata,
success: function(response){
console.log(response);
}
})
}
Are you creating a Payment Intent up-front and that's why you update a Payment Intent here?
Yes sorry
Gotcha thanks
Can you try https://docs.stripe.com/js/elements_object/fetch_updates instead of elements.update?
let me look at it for a second
doesn't elements.update() actually passes the update? So wouldn't this be in addition to elements.update() (basically make the update then fetch the updates).
No. fetchUpdates() is used to get updates from the Payment/Setup Intent that you used when you initialized the Payment Element. The update() method just updates the configuration of the Payment Element itself (e.g. if you wanted to change the Appearance or stop a specific Payment Method type from being shown after render)
I am getting an error that it needs the client secrete, but it doesn't show how to pass that in within the documentation. Oddly elements.update() doesn't error but elements.fetchUpdate() does
Are you instantiating the Payment Element with a client secret? In other words, are you creating the Payment/Setup Intent upfront, then passing its' client secret into the Payment Element when you create it?
~~This guide explains how to do that if you're looking for a reference: https://docs.stripe.com/payments/quickstart~~
Ok let me backup and read this, maybe I am confusing everything.
Ah, apologies. I sent you the wrong doc. Just a second
~~Here you go: https://docs.stripe.com/checkout/embedded/quickstart~~
Technically either of those would work to explain the concept, but the most recent one is catered to the embedded form and is a little simpler to understand
What is the "embeded form" ?
Ugh. All these names autocorrect. Just a minute ๐คฆโโ๏ธ
Gotta love when sales names products all the same.
Okay, third time's the charm: https://docs.stripe.com/elements/express-checkout-element/accept-a-payment
I am probably the the brightest bulb, but this whole process has been difficult
If you look through that you'll see in step 5 how they interact with the client secret from the Payment Intent
Ok but back to our original task of elements.fetchUpdates() should it be just elements.fetchUpdates(clientSecret); the docs here don't really expand on that https://docs.stripe.com/js/elements_object/fetch_updates
I have the clientSecret value, just not sure how to put it into the fetchUpdates()
Hi there ๐ I've been helping my teammates try to look into this. Can you share your code where you're first creating the elements instance?
We're trying to determine whether you initialize it with a client secret like this (we'll call this intent-first):
https://docs.stripe.com/js/elements_object/create
or like this (deferred-intent):
https://docs.stripe.com/js/elements_object/create_without_intent
Can you scroll up in the message? I have all the code up there
I am creating the PaymentIntent before everything.
But I don't have the code posted for that
The first part of the code shared calls your instance of elements, I'm not seeing where that's declared/initialized though.
'expressCheckout', exoptions
)```
const elements = stripe.elements({
mode: 'payment',
amount: orderAmount,
currency: 'usd',
exappearance,
})
Okay, so this is a deferred intent flow then, and elements.update() should be the right path. Sorry for the confusion, but it caught us off guard to see you manipulating an intent before you got to the submission part of your flow.
The "whole" checkout process is two parts, not logged in people are presented with the express checkout, but if they continue on without the express checkout, we get into the whole web elements ui payment intent world.
Also, my code may be getting out of whack because I am trying to what I would think is a simple thing, getting information back from the payment link, Google Pay or Amazon Pay
Trying to get information back in real time and make updates accordingly is a bit trickier, but should still be feasible. Do you have a publicly accessible test site where we could take a closer look at your process?
This is all local. would doing a Google screen share be an option?
I think I need to clean up some of my code as trying a number of different things has caused things to get a little jumbled.
A screenshare isn't going to be super helpful here, since we would need to poke through network requests (of which there are going to be many) and do some internal searching for object IDs, which require copy/paste.
I think next best steps here are to hone in one specific integration path at a time, clean it up so it's as simple as it can be, then try breaking it with one possible solution at a time from there. If you're still blocked after doing that, then spin up a quick publicly accessible test site or a JSFiddle with all the relevant code and we can come through and hopefully be a bit more helpful.
Sure thing. Best of luck!