#arkansasbeauty_89186
1 messages · Page 1 of 1 (latest)
Hello
Hi
My next js code: const billingAddressFormik = useFormik({
initialValues: {
address1: '',
address2: '',
city: '',
state: '',
zipcode: '',
agreed: false,
},
validationSchema: billingAddressValidationSchema,
onSubmit: async (values) => {
if (!stripe || !selectedCard || !selectedCard.stripePaymentMethodID) {
console.error('Stripe instance or selected card details are not available');
setIsUpdatingBillingAddress(false);
return;
}
setIsUpdatingBillingAddress(true);
try {
const billingDetails = {
address: {
line1: values.address1,
line2: values.address2,
city: values.city,
state: values.state,
postal_code: values.zipcode,
}
};
await updateBillingDetails(stripe, selectedCard.stripePaymentMethodID, billingDetails);
} catch (error) {
console.error('Error during billing update process:', error);
} finally {
setIsUpdatingBillingAddress(false);
closeBillingAddressPopup();
}
},
});
const updateBillingDetails = async (stripe, paymentMethodId, billingDetails) => {
if (!stripe) {
console.error('Stripe instance is not available');
return;
}
try {
const updatedPaymentMethod = await stripe.paymentMethods.update(paymentMethodId, {
billing_details: billingDetails,
});
console.log('Billing details updated successfully', updatedPaymentMethod);
return updatedPaymentMethod;
} catch (error) {
console.error('Error updating Payment Method billing details:', error);
throw error;
}
};
What version of our Node SDK are you using?
Hmm that looks like you are trying to update client-side, no?
yes
Yeah you can't update a PaymentMethod client-side
It can only be done server-side as otherwise that would be a security risk
Does this look right?"stripe": "^13.4.0",
Yep that is fine
ok will implement on server side to see if that error goes away. But is the error that I shared indicative of the fact that its on the client side?
As I implemented it this way just for testing
Yes, paymentMethods.update does not exist in our Stripe.JS library
Which is what you are trying to use client-side
but I see "update" when logging the object on the client side.
Yes because you can update Elements (see: https://stripe.com/docs/js/element/other_methods/update?type=card for example)
But you can't update PaymentMethod objects client-side
I understand, thank you. I will give it a shot.