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.
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.
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.
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.