braintree / android-card-form

A ready-made card form layout that can be included in your Android app, making it easy to accept credit and debit cards.
MIT License
366 stars 128 forks source link

Function returns null string #2

Closed joeljoy closed 8 years ago

joeljoy commented 8 years ago
mCardForm = (CardForm) findViewById(R.id.card_form);
mCardForm.setRequiredFields(this, true, true, true, true, getString(R.string.purchase));
mCardForm.setOnCardFormSubmitListener(this);

CardNumber = mCardForm.getCardNumber();
ExpirationMonth = mCardForm.getExpirationMonth();
ExpirationYear = mCardForm.getExpirationYear();
Cvv = mCardForm.getCvv();
 PostelCode = mCardForm.getPostalCode();

Above functions return null strings.

grantbdev commented 8 years ago

They are returning null probably because no text has been put in the field yet if you're getting the values right after creating the card form. You can override onCardFormSubmit() and then once the user submits the form you can check that the form is valid and get the values.

lkorth commented 8 years ago

@grantbdev is correct, you'll want to make sure that the user has typed something or submitted the form. Under the hood these are just TextViews and will return null if no value has been entered into them.

There are tests for the CardForm class to make sure that they do always return the values correctly.