Skip to content

Commit

Permalink
Add setters on Card widgets for card number, expiration, and CVC
Browse files Browse the repository at this point in the history
Fixes #532
  • Loading branch information
mshafrir-stripe committed Aug 28, 2019
1 parent a90d50a commit 8b29a94
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ public void setCardInputListener(@Nullable CardInputListener listener) {
*
* @param cardNumber card number to be set
*/
public void setCardNumber(String cardNumber) {
@Override
public void setCardNumber(@Nullable String cardNumber) {
mCardNumberEditText.setText(cardNumber);
setCardNumberIsViewed(!mCardNumberEditText.isCardNumberValid());
}
Expand All @@ -230,6 +231,7 @@ public void setCardNumber(String cardNumber) {
* @param month a month of the year, represented as a number between 1 and 12
* @param year a year number, either in two-digit form or four-digit form
*/
@Override
public void setExpiryDate(
@IntRange(from = 1, to = 12) int month,
@IntRange(from = 0, to = 9999) int year) {
Expand All @@ -242,7 +244,8 @@ public void setExpiryDate(
*
* @param cvcCode the CVC value to be set
*/
public void setCvcCode(String cvcCode) {
@Override
public void setCvcCode(@Nullable String cvcCode) {
mCvcNumberEditText.setText(cvcCode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,21 @@ public void setShouldShowPostalCode(boolean shouldShowPostalCode) {
*
* @param cardNumber card number to be set
*/
@Override
public void setCardNumber(@Nullable String cardNumber) {
mCardNumberEditText.setText(cardNumber);
}

@Override
public void setExpiryDate(int month, int year) {
mExpiryDateEditText.setText(DateUtils.createDateStringFromIntegerInput(month, year));
}

@Override
public void setCvcCode(@Nullable String cvcCode) {
mCvcEditText.setText(cvcCode);
}

/**
* Checks whether the current card number is valid
*/
Expand Down
8 changes: 8 additions & 0 deletions stripe/src/main/java/com/stripe/android/view/CardWidget.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.stripe.android.view;

import android.support.annotation.IntRange;
import android.support.annotation.Nullable;

import com.stripe.android.model.Card;
Expand Down Expand Up @@ -31,4 +32,11 @@ interface CardWidget {
void setCardInputListener(@Nullable CardInputListener listener);

void clear();

void setCardNumber(@Nullable String cardNumber);

void setExpiryDate(@IntRange(from = 1, to = 12) int month,
@IntRange(from = 0, to = 9999) int year);

void setCvcCode(@Nullable String cvcCode);
}

0 comments on commit 8b29a94

Please sign in to comment.