I'm integrating FastSpring into my app for payment, and I have problem with keeping data in cart after closing popup storefront.
According to documentation I pasted script in my index.html like this
<script
id="fsc-api"
src="https://d1f8f9xcsvx3ha.cloudfront.net/sbl/0.8.3/fastspring-builder.min.js"
type="text/javascript"
data-storefront="xxxxx.test.onfastspring.com/popup-xxx"
data-popup-webhook-received='paymentReceived'>
</script>
Then in my React app in js file I made, several buttons for adding to cart products and one for showing cart
<Buy onClick={()=>{addToCart(licence.name.replace(/\s+/g, ''))}}> <AddShoppingCartIcon/>Add to cart</Buy>
<ShoppingCartIcon onClick={()=>{myCart()}} style={{ width:'35px', height:'35px', cursor:'pointer'}}/>
These are my functions for showing and adding to cart
async function myCart () {
let res
try {
res= await window.fastspring.builder.viewCart()
}
catch(err) {
console.log('err',err)
}
if(!res) { //res is always undefined (when cart is empty and also when its not)
NotificationManager.error('Your cart is empty! Please add some products.')
}
}
function addToCart (productID) {
const res= window.fastspring.builder.add(productID)
NotificationManager.success('Product added to your cart.')
}
The problem is: If there is something in cart after closing popup StoreFront cart is automatically empty if you try to show it again. It shows this error
[FastSpring API] (!) Error: Error received: 400 empty-session
How to keep data in cart after closing popup storefront? Anyone had similar problem?
Thank you
It's a late answer, but I had the same case when the cart was clearing after closing a popup. Fortunately, FastSpring has an option continuous
, which prevents clearing the cart after closing a popup. Just add data-continuous="true"
to your script
tag. I have dug in FastSpring's JavaScript SDK and debugged the whole cycle to discover that option.
Docs: https://fastspringexamples.com/callback/data-continuous/