How to pass customer billing information from the angular component to Snipcart?
Hi ytamer,
You can update the cart with the JavaScript API. This should get you started: Snipcart Update Cart API
1 Like
Thanks @poljpocket
The problem is that it gives me Cannot find name ‘Snipcart’.ts(2304)
any
Although I see the script is loaded and I am calling this within snip cart.ready
private initializeSnipcartEvents(): void {
document.addEventListener('snipcart.ready', function() {
const count = Snipcart.api.items.count();
try {
await Snipcart.api.cart.update({
email: 'john.doe@example.com',
metadata: {
customMetadataKey: 'value'
},
billingAddress:{
name: 'John Doe',
address1: '3671 Garfield Road',
city: 'Neponset',
country: 'US',
province: 'IL',
postalCode: '61345'
}
});
} catch (error) {
console.log(error);
}
});
}
I had to add two more fields to overcome a validation error
I added the phone and first name. It works now. Thanks for your support.
try {
await Snipcart.api.cart.update({
email: 'john.doe@example.com',
metadata: {
customMetadataKey: 'value'
},
billingAddress:{
name: 'John Doe',
firstName: 'John',
phone:'',
address1: '3671 Garfield Road',
city: 'Neponset',
country: 'US',
province: 'IL',
postalCode: '61345'
}
});
apparantely this article that you shared its link with me earlier needs to be updated by two adding the two missing fields to the mentioned example