braintree / braintree-web-drop-in

Braintree Drop-in for the web
MIT License
200 stars 126 forks source link

Retrieve Postal Code from Drop-in Field #619

Closed alex-osman closed 4 years ago

alex-osman commented 4 years ago

Issue description

When including AVS Rules for a Postal Code, I should be able to get that Postal Code when I get the nonce and send both to the backend to process the transaction. I'm not sure how to get the Postal Code from the DropIn component, as the requestPaymentMethod() function does not return the postal code at all. I am able to get a nonce that works with an incorrect postal code on the drop-in UI. Why is that?

Thanks for your help

image

crookedneighbor commented 4 years ago

The nonce includes the postal code. So you can just submit the nonce and it will satisfy that check.

alex-osman commented 4 years ago

@crookedneighbor Thanks for the quick response. One more quick question. My international customers aren't able to pay with credit card due to the postal code validation failing. I have it set to US only, but it does not appear a billing country is ever sent to Braintree.

How am I able to make sure the AVS knows if the customer is international and therefore should give them a nonce regardless of postal code. My customer's get an error on the frontend before a nonce is ever acquired and sent to my backend:

image

crookedneighbor commented 4 years ago

Yeah, that is gonna be a weird edge case with Drop-in since it doesn't collect the other address details (yet!).

For now, I'd do the following in your card create options:

dropin.create({
  card: {
    vault: {
      vaultCard: false
    }
  }

And then vault the card on your server instead, rather than doing the auto-vaulting on the client, which will allow you to pass the country code you've collected from them. This will allow Drop-in to still show a customer's saved payment methods, but not try to vault/verify the card on the client.

You can then use clearSelectedPaymentMethod https://braintree.github.io/braintree-web-drop-in/docs/current/Dropin.html#clearSelectedPaymentMethod to reset Drop-in and write a custom error message to your page if the verification fails on the server.