Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PaymentMethodCreateParams.Card creation #862

Merged
merged 1 commit into from Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -128,12 +128,25 @@ public static final class Card {
@Nullable private final String mCvc;
@Nullable private final String mToken;

@NonNull
public static Card create(@NonNull String token) {
return new Card(token);
}

private Card(@NonNull String token) {
this.mToken = token;
this.mNumber = null;
this.mExpiryMonth = null;
this.mExpiryYear = null;
this.mCvc = null;
}

private Card(@NonNull Card.Builder builder) {
this.mNumber = builder.mNumber;
this.mExpiryMonth = builder.mExpiryMonth;
this.mExpiryYear = builder.mExpiryYear;
this.mCvc = builder.mCvc;
this.mToken = builder.mToken;
this.mToken = null;
}

@Override
Expand Down Expand Up @@ -180,12 +193,15 @@ public Map<String, Object> toMap() {
return map;
}

/**
* Used to create a {@link Card} object with the user's card details. To create a
* {@link Card} with a Stripe token (e.g. for Google Pay), use {@link Card#create(String)}.
*/
public static final class Builder {
@Nullable private String mNumber;
@Nullable private Integer mExpiryMonth;
@Nullable private Integer mExpiryYear;
@Nullable private String mCvc;
@Nullable private String mToken;

@NonNull
public Builder setNumber(@Nullable String number) {
Expand All @@ -211,12 +227,6 @@ public Builder setCvc(@Nullable String cvc) {
return this;
}

@NonNull
public Builder setToken(@Nullable String token) {
this.mToken = token;
return this;
}

@NonNull
public Card build() {
return new Card(this);
Expand Down
5 changes: 2 additions & 3 deletions stripe/src/test/java/com/stripe/android/StripeTest.java
Expand Up @@ -1236,9 +1236,8 @@ public void createPaymentMethod_withCardToken()

final PaymentMethodCreateParams paymentMethodCreateParams =
PaymentMethodCreateParams.create(
new PaymentMethodCreateParams.Card.Builder()
.setToken(token.getId())
.build(), null);
PaymentMethodCreateParams.Card.create(token.getId()),
null);
final PaymentMethod createdPaymentMethod = stripe.createPaymentMethodSynchronous(
paymentMethodCreateParams, FUNCTIONAL_PUBLISHABLE_KEY);
assertNotNull(createdPaymentMethod);
Expand Down