Skip to content

Commit

Permalink
Make most data class models have private constructor (#1720)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshafrir-stripe authored Oct 17, 2019
1 parent 37b3116 commit 2e42c50
Show file tree
Hide file tree
Showing 36 changed files with 61 additions and 59 deletions.
2 changes: 1 addition & 1 deletion stripe/src/main/java/com/stripe/android/ApiVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package com.stripe.android
* See [https://stripe.com/docs/upgrades](https://stripe.com/docs/upgrades) for latest
* API changes.
*/
internal data class ApiVersion constructor(val code: String) {
internal data class ApiVersion private constructor(val code: String) {

override fun toString(): String {
return code
Expand Down
2 changes: 1 addition & 1 deletion stripe/src/main/java/com/stripe/android/AppInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.json.JSONObject
* @param url Website for your application (e.g. "https://myawesomeapp.info")
* @param partnerId Your Stripe Partner ID (e.g. "pp_partner_1234")
*/
data class AppInfo internal constructor(
data class AppInfo private constructor(
private val name: String,
private val version: String?,
private val url: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal open class PaymentRelayStarter(
host.startActivityForResult(PaymentRelayActivity::class.java, extras, requestCode)
}

internal data class Data constructor(
internal data class Data private constructor(
val stripeIntent: StripeIntent? = null,
val exception: Exception? = null
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.android.parcel.Parcelize
* Configuration for [PaymentSession].
*/
@Parcelize
data class PaymentSessionConfig internal constructor(
data class PaymentSessionConfig private constructor(
val hiddenShippingInfoFields: List<String> = emptyList(),
val optionalShippingInfoFields: List<String> = emptyList(),
val prepopulatedShippingInfo: ShippingInformation? = null,
Expand Down
2 changes: 1 addition & 1 deletion stripe/src/main/java/com/stripe/android/ResultWrapper.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.stripe.android

internal data class ResultWrapper<ResultType> constructor(
internal data class ResultWrapper<ResultType> private constructor(
val result: ResultType? = null,
val error: Exception? = null
) {
Expand Down
2 changes: 1 addition & 1 deletion stripe/src/main/java/com/stripe/android/StripeUid.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.stripe.android

internal data class StripeUid constructor(val value: String) {
internal data class StripeUid private constructor(val value: String) {
companion object {
@JvmStatic
fun create(uid: String): StripeUid {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.stripe.android.model
/**
* Represents a grouping of parameters needed to create a Token for a Connect account on the server.
*/
data class AccountParams internal constructor(
data class AccountParams private constructor(
private val businessType: BusinessType?,
private val businessData: Map<String, Any>?,
private val tosShownAndAccepted: Boolean
Expand Down
2 changes: 1 addition & 1 deletion stripe/src/main/java/com/stripe/android/model/Address.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.json.JSONObject
* object in the Source api.
*/
@Parcelize
data class Address internal constructor(
data class Address private constructor(
val city: String?,
val country: String?,
val line1: String?,
Expand Down
2 changes: 1 addition & 1 deletion stripe/src/main/java/com/stripe/android/model/Card.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.json.JSONObject
/**
* A model object representing a Card in the Android SDK.
*/
data class Card internal constructor(
data class Card private constructor(

/**
* @return the [number] of this card
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.stripe.android.ObjectBuilder
import com.stripe.android.model.ConfirmStripeIntentParams.Companion.API_PARAM_CLIENT_SECRET
import com.stripe.android.model.ConfirmStripeIntentParams.Companion.API_PARAM_USE_STRIPE_SDK

data class ConfirmPaymentIntentParams internal constructor(
data class ConfirmPaymentIntentParams private constructor(
val paymentMethodCreateParams: PaymentMethodCreateParams?,
val paymentMethodId: String?,
val sourceParams: SourceParams?,
Expand Down Expand Up @@ -81,25 +81,24 @@ data class ConfirmPaymentIntentParams internal constructor(
}
}

@VisibleForTesting
internal class Builder
/**
* Sets the client secret that is used to authenticate actions on this PaymentIntent
* @param clientSecret client secret associated with this PaymentIntent
*/
internal constructor(
@VisibleForTesting
internal class Builder internal constructor(
internal val clientSecret: String
) : ObjectBuilder<ConfirmPaymentIntentParams> {
internal var paymentMethodCreateParams: PaymentMethodCreateParams? = null
internal var paymentMethodId: String? = null
internal var sourceParams: SourceParams? = null
internal var sourceId: String? = null
private var paymentMethodCreateParams: PaymentMethodCreateParams? = null
private var paymentMethodId: String? = null
private var sourceParams: SourceParams? = null
private var sourceId: String? = null

internal var extraParams: Map<String, Any>? = null
internal var returnUrl: String? = null
private var extraParams: Map<String, Any>? = null
private var returnUrl: String? = null

internal var savePaymentMethod: Boolean = false
internal var shouldUseSdk: Boolean = false
private var savePaymentMethod: Boolean = false
private var shouldUseSdk: Boolean = false

/**
* Sets the PaymentMethod data that will be included with this PaymentIntent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.stripe.android.model.ConfirmStripeIntentParams.Companion.API_PARAM_PA
import com.stripe.android.model.ConfirmStripeIntentParams.Companion.API_PARAM_RETURN_URL
import com.stripe.android.model.ConfirmStripeIntentParams.Companion.API_PARAM_USE_STRIPE_SDK

data class ConfirmSetupIntentParams internal constructor(
data class ConfirmSetupIntentParams private constructor(
override val clientSecret: String,
private val paymentMethodId: String?,
val paymentMethodCreateParams: PaymentMethodCreateParams?,
Expand Down
2 changes: 1 addition & 1 deletion stripe/src/main/java/com/stripe/android/model/Customer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.json.JSONObject
/**
* Model for a Stripe Customer object
*/
data class Customer internal constructor(
data class Customer private constructor(
val id: String?,
val defaultSource: String?,
val shippingInformation: ShippingInformation?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.json.JSONObject
/**
* Model of the "data" object inside a [Customer] "source" object.
*/
data class CustomerSource internal constructor(
data class CustomerSource private constructor(
private val stripePaymentSource: StripePaymentSource
) : StripeModel(), StripePaymentSource {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.json.JSONObject
* - [Payment Intents Overview](https://stripe.com/docs/payments/payment-intents)
* - [PaymentIntents API](https://stripe.com/docs/api/payment_intents)
*/
data class PaymentIntent internal constructor(
data class PaymentIntent private constructor(
/**
* @return Unique identifier for the object.
*/
Expand Down Expand Up @@ -141,7 +141,9 @@ data class PaymentIntent internal constructor(
get() = if (nextAction == null || StripeIntent.NextActionType.UseStripeSdk !== nextActionType) {
null
} else {
StripeIntent.SdkData(nextAction[StripeIntent.NextActionType.UseStripeSdk.code] as Map<String, *>)
StripeIntent.SdkData(
nextAction[StripeIntent.NextActionType.UseStripeSdk.code] as Map<String, *>
)
}

override val redirectData: StripeIntent.RedirectData?
Expand Down Expand Up @@ -184,7 +186,7 @@ data class PaymentIntent internal constructor(
*
* See [last_payment_error](https://stripe.com/docs/api/payment_intents/object#payment_intent_object-last_payment_error).
*/
data class Error internal constructor(
data class Error private constructor(

/**
* For card errors, the ID of the failed charge.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.json.JSONObject
*
* See [PaymentMethod] for API object.
*/
data class PaymentMethodCreateParams internal constructor(
data class PaymentMethodCreateParams private constructor(
internal val type: Type,
private val card: Card? = null,
private val ideal: Ideal? = null,
Expand Down Expand Up @@ -107,7 +107,7 @@ data class PaymentMethodCreateParams internal constructor(
SepaDebit("sepa_debit", true)
}

data class Card internal constructor(
data class Card private constructor(
private val number: String? = null,
private val expiryMonth: Int? = null,
private val expiryYear: Int? = null,
Expand Down Expand Up @@ -182,7 +182,7 @@ data class PaymentMethodCreateParams internal constructor(
}
}

data class Ideal internal constructor(private val bank: String?) : StripeParamsModel {
data class Ideal private constructor(private val bank: String?) : StripeParamsModel {
override fun toParamMap(): Map<String, Any> {
return bank?.let { mapOf(FIELD_BANK to it) }.orEmpty()
}
Expand All @@ -205,7 +205,7 @@ data class PaymentMethodCreateParams internal constructor(
}
}

data class Fpx internal constructor(private val bank: String?) : StripeParamsModel {
data class Fpx private constructor(private val bank: String?) : StripeParamsModel {
override fun toParamMap(): Map<String, Any> {
return bank?.let {
mapOf(FIELD_BANK to it)
Expand All @@ -230,7 +230,7 @@ data class PaymentMethodCreateParams internal constructor(
}
}

data class SepaDebit internal constructor(private val iban: String?) : StripeParamsModel {
data class SepaDebit private constructor(private val iban: String?) : StripeParamsModel {
override fun toParamMap(): Map<String, Any> {
return iban?.let {
mapOf(FIELD_IBAN to it)
Expand Down
4 changes: 2 additions & 2 deletions stripe/src/main/java/com/stripe/android/model/SetupIntent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.json.JSONObject
* A SetupIntent guides you through the process of setting up a customer's payment credentials for
* future payments.
*/
data class SetupIntent internal constructor(
data class SetupIntent private constructor(

/**
* @return Unique identifier for the object.
Expand Down Expand Up @@ -137,7 +137,7 @@ data class SetupIntent internal constructor(
*
* See [last_setup_error](https://stripe.com/docs/api/setup_intents/object#setup_intent_object-last_setup_error).
*/
data class Error internal constructor(
data class Error private constructor(

/**
* For some errors that could be handled programmatically, a short string indicating the
Expand Down
2 changes: 1 addition & 1 deletion stripe/src/main/java/com/stripe/android/model/Source.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.json.JSONObject
*
* See [Sources API Reference](https://stripe.com/docs/api/sources/object).
*/
data class Source internal constructor(
data class Source private constructor(
override val id: String?,
val amount: Long?,
val clientSecret: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.json.JSONObject
* Model for data contained in the SourceTypeData of a Card Source.
*/
@Suppress("MemberVisibilityCanBePrivate")
data class SourceCardData internal constructor(
data class SourceCardData private constructor(
val addressLine1Check: String?,
val addressZipCheck: String?,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.json.JSONObject
*
* *Not* source code verification.
*/
data class SourceCodeVerification constructor(
data class SourceCodeVerification private constructor(
val attemptsRemaining: Int,
@param:Status @field:Status @get:Status val status: String?
) : StripeModel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.json.JSONObject
* Model for a [owner](https://stripe.com/docs/api#source_object-owner) object
* in the Source api.
*/
data class SourceOwner constructor(
data class SourceOwner private constructor(
val address: Address?,
val email: String?,
val name: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.json.JSONObject
* [receiver](https://stripe.com/docs/api/sources/object#source_object-receiver) object
* in the Sources API. Present if the [Source] is a receiver.
*/
data class SourceReceiver constructor(
data class SourceReceiver private constructor(
val address: String?,
val amountCharged: Long,
val amountReceived: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.json.JSONObject
* Model for a [redirect](https://stripe.com/docs/api/sources/object#source_object-redirect) object
* in the Sources API.
*/
data class SourceRedirect constructor(
data class SourceRedirect private constructor(
val returnUrl: String?,
@param:Status @field:Status @get:Status val status: String?,
val url: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.json.JSONObject
/**
* Model for the SourceTypeData contained in a SEPA Debit Source object.
*/
data class SourceSepaDebitData internal constructor(
data class SourceSepaDebitData private constructor(
val bankCode: String?,
val branchCode: String?,
val country: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject

internal data class Stripe3ds2AuthResult constructor(
internal data class Stripe3ds2AuthResult private constructor(
val id: String?,
private val objectType: String?,
val ares: Ares?,
Expand Down Expand Up @@ -79,7 +79,7 @@ internal data class Stripe3ds2AuthResult constructor(
}
}

data class Ares constructor(
data class Ares private constructor(
val threeDSServerTransId: String?,
private val acsChallengeMandated: String?,
val acsSignedContent: String?,
Expand Down Expand Up @@ -218,7 +218,7 @@ internal data class Stripe3ds2AuthResult constructor(
}
}

data class MessageExtension constructor(
data class MessageExtension private constructor(
// The name of the extension data set as defined by the extension owner.
val name: String?,

Expand Down Expand Up @@ -307,7 +307,7 @@ internal data class Stripe3ds2AuthResult constructor(
}
}

data class ThreeDS2Error constructor(
data class ThreeDS2Error private constructor(
val threeDSServerTransId: String?,
val acsTransId: String?,
val dsTransId: String?,
Expand Down Expand Up @@ -457,10 +457,11 @@ internal data class Stripe3ds2AuthResult constructor(
Ares.fromJson(authResultJson.optJSONObject(FIELD_ARES))
)
.setError(
if (authResultJson.isNull(FIELD_ERROR))
if (authResultJson.isNull(FIELD_ERROR)) {
null
else
} else {
ThreeDS2Error.fromJson(authResultJson.optJSONObject(FIELD_ERROR))
}
)
.setFallbackRedirectUrl(
if (authResultJson.isNull(FIELD_FALLBACK_REDIRECT_URL))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ interface StripeIntent {
}
}

data class RedirectData internal constructor(
data class RedirectData private constructor(
/**
* See [PaymentIntent.next_action.redirect_to_url.url](https://stripe.com/docs/api/payment_intents/object#payment_intent_object-next_action-redirect_to_url-url)
*/
Expand Down
2 changes: 1 addition & 1 deletion stripe/src/main/java/com/stripe/android/model/Token.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.json.JSONObject
* account details or personally identifiable information (PII), directly from your customers in a
* secure manner. A Token representing this information is returned to you to use.
*/
data class Token internal constructor(
data class Token private constructor(

/**
* @return the Token id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.stripe.android.model.wallets
import kotlinx.android.parcel.Parcelize

@Parcelize
data class AmexExpressCheckoutWallet internal constructor(
data class AmexExpressCheckoutWallet private constructor(
val dynamicLast4: String?
) : Wallet(Type.AmexExpressCheckout) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.stripe.android.model.wallets
import kotlinx.android.parcel.Parcelize

@Parcelize
data class ApplePayWallet internal constructor(
data class ApplePayWallet private constructor(
val dynamicLast4: String?
) : Wallet(Type.ApplePay) {

Expand Down
Loading

0 comments on commit 2e42c50

Please sign in to comment.