PaymentCardDetailsSingleLineView

class PaymentCardDetailsSingleLineView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : ConstraintLayout, CardValidCallback, CardInputListener

Convenience view for collecting card details from a user. All card fields are combined into a single-line view


Important:

User-entered card details are intentionally restricted to reduce PCI compliance scope


Styling/Branding

This view provides full support for styling and customization, which can be accomplished in the following ways:

  • Individual Style Attributes: Style specific aspects of the view individually

  • Text Appearance Style Attributes: Style text using Android's TextAppearance styles

  • Background Resource Attributes: Style the background using drawable resources


XML attributes can be set directly on the view or they can be defined in a style that gets applied to the view. The following examples each produce the same result:

Customizations applied directly to the view:

// NOTE: This example assumes a namespace definition of `app`. Replace
// this with your own namespace qualifier if you use something different
<com.olo.olopay.controls.PaymentCardDetailsSingleLineView
app:cardBorderColor="@color/android:black"
app:cardBorderWidth="2dp" />
/>

Customizations applied in a style:

// Style definition
<style name="MyCardStyle">
<item name="cardBorderColor">@color/android:black</item>
<item name="cardBorderWidth">2dp</item>
</style>

// Layout file
<com.olo.olopay.controls.PaymentCardDetailsSingleLineView
style="@style/MyCardStyle" />

Individual Style Attributes

These attributes are responsible for controlling a single aspect of the view. In the case of conflicting styles between these attributes and Text Appearance Style Attributes or Background Resource Attributes these attributes take precedence.

This view supports the following attributes for styling/branding purposes:

Important:

Some customizations are only possible when using Text Appearance Style Attributes or Background Resource Attributes. Refer to those sections for more information.


Text Appearance Attributes

Unlike the text attributes specified in Individual Style Attributes above, where each attribute specifies one aspect of the text's appearance, these attributes define the entire appearance through one attribute using a text appearance style. These styles can define text color, text size, hint text color, or even have different appearances defined based on the state of the view (e.g. focused or unfocused, enabled or disabled). For a full list of available attributes, see TextAppearance.

This view supports the following text appearance resource attributes for styling/branding purposes:

Important

Text attributes defined directly on this view (from the Individual Style Attributes section above) will override attributes defined by the textAppearance and errorTextAppearance attributes


Background Attributes

Unlike the background attributes specified in Individual Style Attributes above, where each attribute specifies one aspect of the background, these attributes define the entire background through one resource id. For example, a single drawable resource could be used that specifies padding, border color, border radius, and a gradient background, or even have different backgrounds defined based on the state of the view (e.g. focused or unfocused, enabled or disabled).

This view supports the following background resource attributes for styling/branding purposes:

Important

Background attributes from the Individual Style Attributes section above take precedence over these background attributes.


Constructors

Link copied to clipboard
constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)

Creates a new instance of PaymentCardDetailsSingleLineView

Properties

Link copied to clipboard

The detected card brand based on the currently entered card number

Link copied to clipboard

Set this to receive callbacks about card input events for this control

Link copied to clipboard

Set this to receive notifications when configuration changes occur

Link copied to clipboard

XML Attribute: displayErrors

Link copied to clipboard

Provides a snapshot of the current state of each card field

Link copied to clipboard

true if all fields are complete and valid, otherwise false

Link copied to clipboard

Get an IPaymentMethodParams instance that can be used to create an IPaymentMethod instance. If the form is not valid this will return null.

Link copied to clipboard

XML Attribute: postalCodeEnabled

Functions

Link copied to clipboard

Clears all text fields in the control

Link copied to clipboard

Dismisses the keyboard, if visible, and removes focus from input fields in this control

Link copied to clipboard

Gets the font of the error message

Link copied to clipboard
fun getErrorMessage(ignoreUneditedFieldErrors: Boolean): String

Get the error message that would be displayed if displayErrors is true and isValid is false. Note that isValid having a value of false does not necessarily mean there will be an error message (see ignoreUneditedFieldErrors param)

Link copied to clipboard

Gets the font of the input fields

Link copied to clipboard
fun hasErrorMessage(ignoreUneditedFieldErrors: Boolean = true): Boolean

Check if there is an error message to be displayed.

Link copied to clipboard
open override fun isEnabled(): Boolean

True if the form is enabled and can accept user input, false otherwise

Link copied to clipboard
fun requestFocus(field: CardField, showKeyboard: Boolean)

Moves focus to the specified input field

Link copied to clipboard

XML Attribute: cardBackground

Link copied to clipboard
fun setCardBackgroundStyle(backgroundColor: Int? = null, borderColor: Int? = null, borderWidthPx: Float? = null, borderRadiusPx: Float? = null)
@RequiresApi(value = 27)
fun setCardBackgroundStyle(backgroundColorHex: String? = null, borderColorHex: String? = null, borderWidthPx: Float? = null, borderRadiusPx: Float? = null)

XML Attributes: cardBackgroundColor, cardBorderColor, cardBorderWidth, cardBorderRadius

Link copied to clipboard
fun setCardNumber(number: String?)

Sets the card number. Does not change field focus

Link copied to clipboard
fun setCardPadding(startPx: Int?, topPx: Int?, endPx: Int?, bottomPx: Int?)

XML Attributes: cardStartPadding, cardTopPadding, cardEndPadding, cardBottomPadding

Link copied to clipboard
@RequiresApi(value = 29)
fun setCursorColor(color: Int)
@RequiresApi(value = 29)
fun setCursorColor(colorHex: String)

XML Attribute: cursorColor

Link copied to clipboard
fun setCvv(cvv: String?)

Set the CVV value for the card. The maximum length is assumed to be 3, unless the brand of the card has already been set (by setting the card number)

Link copied to clipboard
open override fun setEnabled(enabled: Boolean)

XML Attribute: android:enabled

Link copied to clipboard

XML Attribute: errorBackground

Link copied to clipboard
fun setErrorBackgroundStyle(backgroundColor: Int? = null, borderColor: Int? = null, borderWidthPx: Float? = null, borderRadiusPx: Float? = null)
@RequiresApi(value = 27)
fun setErrorBackgroundStyle(backgroundColorHex: String? = null, borderColorHex: String? = null, borderWidthPx: Float? = null, borderRadiusPx: Float? = null)

XML Attributes: errorBackgroundColor, errorBorderColor, errorBorderWidth, errorBorderRadius

Link copied to clipboard

Sets the error font for error messages

Link copied to clipboard
fun setErrorGravity(gravityPosition: Int)

XML Attribute: errorGravity

Link copied to clipboard
fun setErrorPadding(startPx: Int?, topPx: Int?, endPx: Int?, bottomPx: Int?)

XML Attributes: errorStartPadding, errorTopPadding, errorEndPadding, errorBottomPadding

Link copied to clipboard
fun setErrorTextAppearance(resourceId: Int)

XML Attribute: errorTextAppearance

Link copied to clipboard
@RequiresApi(value = 27)
fun setErrorTextColor(colorHex: String)

XML Attribute: errorTextColor

Link copied to clipboard

XML Attribute: errorTextSize

Link copied to clipboard
fun setExpirationDate(@IntRange(from = 1, to = 12) month: Int, @IntRange(from = 0, to = 9999) year: Int)

Set the expiration date. This invokes the completion listener and changes focus to the CVV field if a valid date is entered

Link copied to clipboard
fun setFont(font: Typeface)

Sets the font for all input fields

Link copied to clipboard
fun setHintText(field: CardField, hint: String)

XML Attributes: cardNumberHint, expirationHint, cvvHint, postalCodeHint

Link copied to clipboard
fun setHintTextColor(color: Int)
@RequiresApi(value = 27)
fun setHintTextColor(colorHex: String)

XML Attribute: hintTextColor

Link copied to clipboard
fun setTextAppearance(resourceId: Int)

XML Attribute: textAppearance

Link copied to clipboard
fun setTextColor(color: Int)
@RequiresApi(value = 27)
fun setTextColor(colorHex: String)

XML Attribute: textColor

Link copied to clipboard
fun setTextSize(size: Float)

XML Attribute: textSize

Link copied to clipboard
fun setVerticalSpacing(spacingPx: Int)

**XML Attribute: verticalSpacing