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

Make model classes final #1075

Merged
merged 1 commit into from
Jun 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.stripe.android.model.ShippingMethod;
import com.stripe.android.utils.ObjectUtils;

import java.util.Objects;

/**
* A data class representing the state of the associated {@link PaymentSession}.
*/
Expand Down Expand Up @@ -211,7 +213,8 @@ public PaymentSessionData[] newArray(int size) {
private PaymentSessionData(@NonNull Parcel in) {
mCartTotal = in.readLong();
mIsPaymentReadyToCharge = in.readInt() == 1;
mPaymentResult = PaymentSessionUtils.paymentResultFromString(in.readString());
mPaymentResult = PaymentSessionUtils.paymentResultFromString(
Objects.requireNonNull(in.readString()));
mPaymentMethod = in.readParcelable(PaymentMethod.class.getClassLoader());
mShippingInformation = in.readParcelable(ShippingInformation.class.getClassLoader());
mShippingMethod = in.readParcelable(ShippingMethod.class.getClassLoader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* Represents a grouping of parameters needed to create a Token for a Connect account on the server.
*/
public class AccountParams {
public final class AccountParams {

static final String API_BUSINESS_TYPE = "business_type";
static final String API_TOS_SHOWN_AND_ACCEPTED = "tos_shown_and_accepted";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* Model for an owner <a href="https://stripe.com/docs/api#source_object-owner-address">address</a>
* object in the Source api.
*/
public class Address extends StripeJsonModel implements Parcelable {
public final class Address extends StripeJsonModel implements Parcelable {

@IntDef({
RequiredBillingAddressFields.NONE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* <a href="https://stripe.com/docs/api/java#create_bank_account_token">the Stripe
* documentation.</a>
*/
public class BankAccount {
public final class BankAccount {

@Retention(RetentionPolicy.SOURCE)
@StringDef({TYPE_COMPANY, TYPE_INDIVIDUAL})
Expand Down
2 changes: 1 addition & 1 deletion stripe/src/main/java/com/stripe/android/model/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/**
* A model object representing a Card in the Android SDK.
*/
public class Card extends StripeJsonModel implements StripePaymentSource {
public final class Card extends StripeJsonModel implements StripePaymentSource {

@Retention(RetentionPolicy.SOURCE)
@StringDef({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Model for a Stripe Customer object
*/
public class Customer extends StripeJsonModel {
public final class Customer extends StripeJsonModel {

private static final String FIELD_ID = "id";
private static final String FIELD_OBJECT = "object";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Model of the "data" object inside a {@link Customer} "source" object.
*/
public class CustomerSource extends StripeJsonModel implements StripePaymentSource {
public final class CustomerSource extends StripeJsonModel implements StripePaymentSource {

@NonNull private final StripePaymentSource mStripePaymentSource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* <li><a href="https://stripe.com/docs/api/payment_intents">PaymentIntents API</a></li>
* </ul>
*/
public class PaymentIntent extends StripeJsonModel {
public final class PaymentIntent extends StripeJsonModel {
private static final String VALUE_PAYMENT_INTENT = "payment_intent";

static final String FIELD_ID = "id";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.HashMap;
import java.util.Map;

public class PaymentIntentParams {
public final class PaymentIntentParams {

public static final String API_PARAM_SOURCE_DATA = "source_data";
public static final String API_PARAM_PAYMENT_METHOD_DATA = "payment_method_data";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*
* See {@link PaymentMethodCreateParams} for PaymentMethod creation
*/
public class PaymentMethod extends StripeJsonModel implements Parcelable {
public final class PaymentMethod extends StripeJsonModel implements Parcelable {
private static final String FIELD_ID = "id";
private static final String FIELD_BILLING_DETAILS = "billing_details";
private static final String FIELD_CARD = "card";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* See {@link PaymentMethod} for API object
*/
public class PaymentMethodCreateParams {
public final class PaymentMethodCreateParams {

private static final String FIELD_BILLING_DETAILS = "billing_details";
private static final String FIELD_CARD = "card";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Model representing a shipping address object
*/
public class ShippingInformation extends StripeJsonModel implements Parcelable {
public final class ShippingInformation extends StripeJsonModel implements Parcelable {
public static final Creator<ShippingInformation> CREATOR = new Creator<ShippingInformation>() {
@Override
public ShippingInformation createFromParcel(Parcel source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Model representing a shipping method in the Android SDK.
*/
public class ShippingMethod extends StripeJsonModel implements Parcelable {
public final class ShippingMethod extends StripeJsonModel implements Parcelable {

public static final Parcelable.Creator<ShippingMethod> CREATOR
= new Parcelable.Creator<ShippingMethod>() {
Expand Down Expand Up @@ -50,8 +50,7 @@ public ShippingMethod[] newArray(int size) {
public ShippingMethod(@NonNull String label,
@NonNull String identifier,
long amount,
@NonNull @Size(min = 0, max = 3) String
currencyCode) {
@NonNull @Size(min = 0, max = 3) String currencyCode) {
this(label, identifier, null, amount, currencyCode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* can be seen at <a href="https://stripe.com/docs/api/sources/object?lang=java">
* https://stripe.com/docs/api/sources/object?lang=java</a>.
*/
public class Source extends StripeJsonModel implements StripePaymentSource {
public final class Source extends StripeJsonModel implements StripePaymentSource {

static final String VALUE_SOURCE = "source";
private static final String VALUE_CARD = "card";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* Model for data contained in the SourceTypeData of a Card Source.
*/
public class SourceCardData extends StripeSourceTypeModel {
public final class SourceCardData extends StripeSourceTypeModel {

@Retention(RetentionPolicy.SOURCE)
@StringDef({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* https://stripe.com/docs/api/sources/object#source_object-code_verification
* object in the source api, <em>not</em> source code verification
*/
public class SourceCodeVerification extends StripeJsonModel {
public final class SourceCodeVerification extends StripeJsonModel {

// Note: these are the same as the values for the @Redirect.Status StringDef.
// They don't have to stay the same forever, so they are redefined here.
Expand Down
50 changes: 9 additions & 41 deletions stripe/src/main/java/com/stripe/android/model/SourceOwner.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Model for a <a href="https://stripe.com/docs/api#source_object-owner">owner</a> object
* in the Source api.
*/
public class SourceOwner extends StripeJsonModel {
public final class SourceOwner extends StripeJsonModel {

private static final String VERIFIED = "verified_";
private static final String FIELD_ADDRESS = "address";
Expand All @@ -32,14 +32,14 @@ public class SourceOwner extends StripeJsonModel {
private static final String FIELD_VERIFIED_NAME = VERIFIED + FIELD_NAME;
private static final String FIELD_VERIFIED_PHONE = VERIFIED + FIELD_PHONE;

@Nullable private Address mAddress;
@Nullable private String mEmail;
@Nullable private String mName;
@Nullable private String mPhone;
@Nullable private Address mVerifiedAddress;
@Nullable private String mVerifiedEmail;
@Nullable private String mVerifiedName;
@Nullable private String mVerifiedPhone;
@Nullable private final Address mAddress;
@Nullable private final String mEmail;
@Nullable private final String mName;
@Nullable private final String mPhone;
@Nullable private final Address mVerifiedAddress;
@Nullable private final String mVerifiedEmail;
@Nullable private final String mVerifiedName;
@Nullable private final String mVerifiedPhone;

private SourceOwner(
@Nullable Address address,
Expand Down Expand Up @@ -100,38 +100,6 @@ public String getVerifiedPhone() {
return mVerifiedPhone;
}

void setAddress(Address address) {
mAddress = address;
}

void setEmail(String email) {
mEmail = email;
}

void setName(String name) {
mName = name;
}

void setPhone(String phone) {
mPhone = phone;
}

void setVerifiedAddress(Address verifiedAddress) {
mVerifiedAddress = verifiedAddress;
}

void setVerifiedEmail(String verifiedEmail) {
mVerifiedEmail = verifiedEmail;
}

void setVerifiedName(String verifiedName) {
mVerifiedName = verifiedName;
}

void setVerifiedPhone(String verifiedPhone) {
mVerifiedPhone = verifiedPhone;
}

@NonNull
@Override
public Map<String, Object> toMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Represents a grouping of parameters needed to create a {@link Source} object on the server.
*/
public class SourceParams {
public final class SourceParams {

private static final String API_PARAM_AMOUNT = "amount";
private static final String API_PARAM_CURRENCY = "currency";
Expand Down Expand Up @@ -246,7 +246,7 @@ public static SourceParams createCustomParams() {
* @return a {@link SourceParams} object that can be used to create a source.
*/
@NonNull
public static SourceParams createSourceFromTokenParams(String tokenId) {
public static SourceParams createSourceFromTokenParams(@NonNull String tokenId) {
SourceParams sourceParams = SourceParams.createCustomParams();
sourceParams.setType(Source.CARD);
sourceParams.setToken(tokenId);
Expand Down
34 changes: 10 additions & 24 deletions stripe/src/main/java/com/stripe/android/model/SourceReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,27 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;

/**
* Model for a <a href="https://stripe.com/docs/api#source_object-receiver">receiver</a> object in
* the source api. Present if the {@link Source} is a receiver.
* Model for a
* <a href="https://stripe.com/docs/api/sources/object#source_object-receiver">receiver</a> object
* in the Sources API. Present if the {@link Source} is a receiver.
*/
public class SourceReceiver extends StripeJsonModel {
public final class SourceReceiver extends StripeJsonModel {

private static final String FIELD_ADDRESS = "address";
private static final String FIELD_AMOUNT_CHARGED = "amount_charged";
private static final String FIELD_AMOUNT_RECEIVED = "amount_received";
private static final String FIELD_AMOUNT_RETURNED = "amount_returned";

// This is not to be confused with the Address object
@Nullable private String mAddress;
private long mAmountCharged;
private long mAmountReceived;
private long mAmountReturned;
@Nullable private final String mAddress;
private final long mAmountCharged;
private final long mAmountReceived;
private final long mAmountReturned;

private SourceReceiver(@Nullable String address,
long amountCharged,
Expand All @@ -44,38 +46,22 @@ public String getAddress() {
return mAddress;
}

public void setAddress(@Nullable String address) {
mAddress = address;
}

public long getAmountCharged() {
return mAmountCharged;
}

public void setAmountCharged(long amountCharged) {
mAmountCharged = amountCharged;
}

public long getAmountReceived() {
return mAmountReceived;
}

public void setAmountReceived(long amountReceived) {
mAmountReceived = amountReceived;
}

public long getAmountReturned() {
return mAmountReturned;
}

public void setAmountReturned(long amountReturned) {
mAmountReturned = amountReturned;
}

@NonNull
@Override
public Map<String, Object> toMap() {
final Map<String, Object> map = new HashMap<>();
final AbstractMap<String, Object> map = new HashMap<>();
if (!StripeTextUtils.isBlank(mAddress)) {
map.put(FIELD_ADDRESS, mAddress);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Model for a <a href="https://stripe.com/docs/api/sources/object#source_object-redirect">
* redirect</a> object in the source api.
*/
public class SourceRedirect extends StripeJsonModel {
public final class SourceRedirect extends StripeJsonModel {

@Retention(RetentionPolicy.SOURCE)
@StringDef({
Expand All @@ -43,9 +43,9 @@ public class SourceRedirect extends StripeJsonModel {
private static final String FIELD_STATUS = "status";
private static final String FIELD_URL = "url";

@Nullable private String mReturnUrl;
@Nullable @Status private String mStatus;
@Nullable private String mUrl;
@Nullable private final String mReturnUrl;
@Nullable @Status private final String mStatus;
@Nullable private final String mUrl;

private SourceRedirect(@Nullable String returnUrl, @Status @Nullable String status,
@Nullable String url) {
Expand All @@ -59,29 +59,17 @@ public String getReturnUrl() {
return mReturnUrl;
}

public void setReturnUrl(@Nullable String returnUrl) {
mReturnUrl = returnUrl;
}

@Nullable
@Status
public String getStatus() {
return mStatus;
}

public void setStatus(@Nullable @Status String status) {
mStatus = status;
}

@Nullable
public String getUrl() {
return mUrl;
}

public void setUrl(@Nullable String url) {
mUrl = url;
}

@NonNull
@Override
public Map<String, Object> toMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Model for the SourceTypeData contained in a SEPA Debit Source object.
*/
public class SourceSepaDebitData extends StripeSourceTypeModel {
public final class SourceSepaDebitData extends StripeSourceTypeModel {

private static final String FIELD_BANK_CODE = "bank_code";
private static final String FIELD_BRANCH_CODE = "branch_code";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
* Represents an object that has an ID field that can be used to create payments with Stripe.
*/
public interface StripePaymentSource {
@Nullable
String getId();
@Nullable String getId();
}
Loading