Calling setPostalCode using react-square-payment-form

Not sure if this is the right place to be asking questions around react-square-payment-form but here goes:

I’m trying to call setPostalCode in the paymentFormLoaded callback so that the postal code is defaulted to the known billing contact of the app I’m working on. Problem is, the SqPaymentForm instance is hidden in a closure and there is no obvious/documented way to access it.

Additionally, there does not appear to be a way to provide the default value for the postal code via props/context. Any pointers or ideas would be appreciated.

Thanks for an excellent platform and great library.

Hi @boycey welcome to the forums!

Are you saying that your call to setPostalCode is failing, or never being hit? If it’s never being hit, then you would need actually build your form (by calling build()) whenever you intend on making the form visible. There is no current way to set a default value other than calling setPostalCode with some value.

Hi @sjosey - thanks :slightly_smiling_face:

I am saying that since the SquarePaymentForm react component builds (and manages) the SqPaymentForm instance for me (and calls build() when appropriate) as seen here, I see no way in being able to get access to the underlying JS instance paymentForm and call setPostalCode at the appropriate time.

Can provide some sample code if that helps.

Ah, my apologies. I totally missed you were using the React payment form plugin. Let me check in with some folks, and I’ll follow up in a bit.

Looks like setPostalCode is not a part of the React plugin. The team that owns it recommends posting it on the Github repo (https://github.com/square/react-square-payment-form) as a feature request/enhancement, and they’ll follow up to prioritize it.

Thanks for the quick response, I filed an issue on the repo. Can’t link to github - but the issue number is 78.

1 Like

react-square-payment-form 0.7.0 has been released and supports this functionality.

Thanks for turning that around so quickly team square! :slight_smile:

1 Like