Skip to content

Commit

Permalink
Create ShippingInformationValidator and ShippingMethodsFactory interf…
Browse files Browse the repository at this point in the history
…ace (#1847)
  • Loading branch information
mshafrir-stripe authored Nov 19, 2019
1 parent a1b3104 commit 43e70e3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions stripe/src/main/java/com/stripe/android/PaymentSessionConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package com.stripe.android

import android.os.Parcelable
import androidx.annotation.LayoutRes
import androidx.annotation.WorkerThread
import com.stripe.android.model.PaymentMethod
import com.stripe.android.model.ShippingInformation
import com.stripe.android.model.ShippingMethod
import com.stripe.android.view.SelectShippingMethodWidget
import com.stripe.android.view.ShippingInfoWidget
import com.stripe.android.view.ShippingInfoWidget.CustomizableShippingField
import java.io.Serializable
import java.util.Locale
import kotlinx.android.parcel.Parcelize

Expand Down Expand Up @@ -40,6 +43,33 @@ data class PaymentSessionConfig internal constructor(
}
}

private interface ShippingInformationValidator : Serializable {
/**
* @return whether the customer's [ShippingInformation] is valid. Will run on
* a background thread.
*/
@WorkerThread
fun isValid(shippingInformation: ShippingInformation): Boolean

/**
* @return the error message to show if [isValid] returns `false`. Will run on
* a background thread.
*/
@WorkerThread
fun getErrorMessage(shippingInformation: ShippingInformation): String
}

private interface ShippingMethodsFactory : Serializable {
/**
* @return a list of [ShippingMethod] options to present to the customer. Will run on
* a background thread.
*/
@WorkerThread
fun create(
shippingInformation: ShippingInformation
): List<ShippingMethod>
}

class Builder : ObjectBuilder<PaymentSessionConfig> {
private var shippingInfoRequired = true
private var shippingMethodsRequired = true
Expand Down

0 comments on commit 43e70e3

Please sign in to comment.