#arkansasbeauty_89186

1 messages · Page 1 of 1 (latest)

dusky swiftBOT
upper jungle
#

Hello

peak elk
#

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;
    }
  };
upper jungle
#

What version of our Node SDK are you using?

#

Hmm that looks like you are trying to update client-side, no?

peak elk
#

yes

upper jungle
#

Yeah you can't update a PaymentMethod client-side

#

It can only be done server-side as otherwise that would be a security risk

peak elk
#

Does this look right?"stripe": "^13.4.0",

upper jungle
#

Yep that is fine

peak elk
#

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

upper jungle
#

Yes, paymentMethods.update does not exist in our Stripe.JS library

#

Which is what you are trying to use client-side

peak elk
#

but I see "update" when logging the object on the client side.

upper jungle
#

But you can't update PaymentMethod objects client-side

peak elk
#

I understand, thank you. I will give it a shot.