#Swann - postal code

1 messages ยท Page 1 of 1 (latest)

regal loom
#

Hi there. One moment

undone pewter
#

Hey! Long time no see

#

Sure

#

I'm trying to find a way to validate the postal code after getting it back from the react native sdk

#

I've found this code in the android sdk that seems useful

   internal enum class Config {
       Global,
       US
   }

   /**
    * Returns if the postal is valid. If config is not US, any non-empty postal is valid.
    */
   internal fun hasValidPostal() =
       config == Config.US && ZIP_CODE_PATTERN.matcher(fieldText)
           .matches() || 1eldText.isNotEmpty()

   private companion object {
       private const val MAX_LENGTH_US = 5

       private val ZIP_CODE_PATTERN = Pattern.compile("^[0-9]{5}$")
   }
#

But I still need to check the address_postal_code_check field before creating the card

regal loom
#

Oh ok. So what is happening in that screenshot? Is that not validating the postal code prior to creating the card?

undone pewter
#

So this screenshot is of the PaymentSessions screen from the native sdk (iOS in this instance)

#

We're migrating over from using the native sdks directly to using the react native sdk

#

The native sdk handled postal code validation correctly (including taking into account stripe fraud settings)

#

But now that I've rewritten it to use the react native sdk we're missing the ability to do that ๐Ÿ˜ฆ

regal loom
#

Got it. Let me check with a colleague on this

undone pewter
#

Thanks ๐Ÿ™

#

I'm doing some experimentation on my side as well

regal loom
#

So the recommendation I got for this is to add validation yourself based on the onCardChange CardField method

undone pewter
#

I agree

#

Is there a way for me to know which country the card is from for me to do the postal code validation?

tawdry hamlet
#

๐Ÿ‘‹ Hello! Just stepping in since @regal loom has to head out - quick question, what are you using in the react native sdk? payment element?

undone pewter
#

Hey!

#

I'm using the react native sdk

#

0.12.0

tawdry hamlet
#

๐Ÿ‘ What specific part of the react native sdk are you using though, payment sheet? just the card element?

undone pewter
#

I believe this is the same as the card element from the web sdk?

tawdry hamlet
#

Gotcha, and because the ReactNative CardField doesn't provide postal code validation right now, you're asking how to get the country so you can do the validation yourself?

undone pewter
#

Yes! ๐Ÿ˜„

tawdry hamlet
#

I don't think there's a way for you to get that (and I wouldn't recommend it even if you could, since a common issue that you see in the web card element is that the country tied to the card doesn't match the country of their billing address). You should collect the billing address country in a separate UI and validate off that

undone pewter
#

Solid advice ๐Ÿ‘

#

Thanks, will take this info back to our PM

undone pewter
#

Is there a way to attach a payment method to a customer using the react native sdk? Or is our only option to send the token to the backend to have that done?

#

If it's possible it would make it easier for us to perform the postal code validation

tawdry hamlet
#

Let me double check, but I don't think there's a way

#

Yeah, there isn't a way to just take a payment method and attach it to a customer from the react native sdk.