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

Create ShippingInformationValidator and ShippingMethodsFactory interfaces #1847

Merged
merged 1 commit into from
Nov 19, 2019
Merged
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
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
mshafrir-stripe marked this conversation as resolved.
Show resolved Hide resolved
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