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

Convert CustomizableShippingField to enum #2617

Merged
merged 1 commit into from
Jul 7, 2020
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
4 changes: 4 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
}
}
```
- Changes to `ShippingInfoWidget`
- `setOptionalFields()` is now `optionalFields`
- `setHiddenFields()` is now `hiddenFields`
- `CustomizableShippingField` is now an enum
- Changes to `Source`
- `Source.SourceFlow` has been renamed to `Source.Flow` and is now an enum
- `Source.SourceStatus` has been renamed to `Source.Status` and is now an enum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class FragmentExamplesFragment : Fragment() {
config = PaymentSessionConfig.Builder()
.setShippingMethodsRequired(false)
.setHiddenShippingInfoFields(
ShippingInfoWidget.CustomizableShippingField.PHONE_FIELD,
ShippingInfoWidget.CustomizableShippingField.CITY_FIELD
ShippingInfoWidget.CustomizableShippingField.Phone,
ShippingInfoWidget.CustomizableShippingField.City
)
.build()
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.stripe.android

import android.annotation.SuppressLint
import android.os.Parcelable
import androidx.annotation.LayoutRes
import androidx.annotation.WorkerThread
Expand All @@ -24,8 +23,8 @@ import kotlinx.android.parcel.Parcelize
*/
@Parcelize
data class PaymentSessionConfig internal constructor(
val hiddenShippingInfoFields: List<String> = emptyList(),
val optionalShippingInfoFields: List<String> = emptyList(),
val hiddenShippingInfoFields: List<CustomizableShippingField> = emptyList(),
val optionalShippingInfoFields: List<CustomizableShippingField> = emptyList(),
val prepopulatedShippingInfo: ShippingInformation? = null,
val isShippingInfoRequired: Boolean = false,
val isShippingMethodRequired: Boolean = false,
Expand Down Expand Up @@ -93,8 +92,8 @@ data class PaymentSessionConfig internal constructor(
private var billingAddressFields: BillingAddressFields = DEFAULT_BILLING_ADDRESS_FIELDS
private var shippingInfoRequired = true
private var shippingMethodsRequired = true
private var hiddenShippingInfoFields: List<String>? = null
private var optionalShippingInfoFields: List<String>? = null
private var hiddenShippingInfoFields: List<CustomizableShippingField>? = null
private var optionalShippingInfoFields: List<CustomizableShippingField>? = null
private var shippingInformation: ShippingInformation? = null
private var paymentMethodTypes: List<PaymentMethod.Type> = listOf(PaymentMethod.Type.Card)
private var shouldShowGooglePay: Boolean = false
Expand Down Expand Up @@ -122,9 +121,8 @@ data class PaymentSessionConfig internal constructor(
* hidden in the shipping information screen. All fields will be shown if this list is
* empty. Note that not all fields can be hidden, such as country or name.
*/
@SuppressLint("WrongConstant")
fun setHiddenShippingInfoFields(
@CustomizableShippingField vararg hiddenShippingInfoFields: String
vararg hiddenShippingInfoFields: CustomizableShippingField
): Builder = apply {
this.hiddenShippingInfoFields = listOf(*hiddenShippingInfoFields)
}
Expand All @@ -133,9 +131,8 @@ data class PaymentSessionConfig internal constructor(
* @param optionalShippingInfoFields [CustomizableShippingField] fields that should be
* optional in the [ShippingInfoWidget]
*/
@SuppressLint("WrongConstant")
fun setOptionalShippingInfoFields(
@CustomizableShippingField vararg optionalShippingInfoFields: String
vararg optionalShippingInfoFields: CustomizableShippingField
): Builder = apply {
this.optionalShippingInfoFields = listOf(*optionalShippingInfoFields)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ internal class PaymentFlowPagerAdapter(
shippingInformation: ShippingInformation?,
allowedShippingCountryCodes: Set<String>
) {
shippingInfoWidget
.setHiddenFields(paymentSessionConfig.hiddenShippingInfoFields)
shippingInfoWidget
.setOptionalFields(paymentSessionConfig.optionalShippingInfoFields)
shippingInfoWidget.hiddenFields = paymentSessionConfig.hiddenShippingInfoFields
shippingInfoWidget.optionalFields = paymentSessionConfig.optionalShippingInfoFields
shippingInfoWidget
.setAllowedCountryCodes(allowedShippingCountryCodes)
shippingInfoWidget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ internal class PostalCodeValidator {
fun isValid(
postalCode: String,
countryCode: String?,
optionalShippingInfoFields: List<String>,
hiddenShippingInfoFields: List<String>
optionalShippingInfoFields: List<ShippingInfoWidget.CustomizableShippingField>,
hiddenShippingInfoFields: List<ShippingInfoWidget.CustomizableShippingField>
): Boolean {
if (countryCode == null) {
return false
Expand Down Expand Up @@ -42,13 +42,13 @@ internal class PostalCodeValidator {
)

private fun isPostalCodeNotRequired(
optionalShippingInfoFields: List<String>,
hiddenShippingInfoFields: List<String>
optionalShippingInfoFields: List<ShippingInfoWidget.CustomizableShippingField>,
hiddenShippingInfoFields: List<ShippingInfoWidget.CustomizableShippingField>
): Boolean {
return optionalShippingInfoFields.contains(
ShippingInfoWidget.CustomizableShippingField.POSTAL_CODE_FIELD
ShippingInfoWidget.CustomizableShippingField.PostalCode
) || hiddenShippingInfoFields.contains(
ShippingInfoWidget.CustomizableShippingField.POSTAL_CODE_FIELD
ShippingInfoWidget.CustomizableShippingField.PostalCode
)
}
}
Expand Down
Loading