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 for PCI compliance


Styling/Branding

This class can be styled in the following ways:

  1. Override general-purpose resource values

  2. Override resource values specific to PaymentCardDetailsSingleLineView

  3. Override styles specific to PaymentCardDetailsSingleLineView

  4. Set styles programmatically

Override general-purpose resource values

Overriding general-purpose resource values is the easiest way to control the look/feel of the views in the Olo Pay SDK. Changing these values (listed below) will apply to not just PaymentCardDetailsSingleLineView, but also PaymentCardDetailsMultiLineView, and in a limited way, PaymentCardDetailsForm and PaymentCardCvvView. To override the resources, simply define resources in your app with the same names listed below

Dimen Resources

olopay_textsize
olopay_errortext_textsize

Color Resources

olopay_hintcolor
olopay_edittext_textcolor
olopay_errortext_textcolor

Override resource values specific to PaymentCardDetailsSingleLineView

Overriding the resource values listed below provides for more flexibility, but they apply ONLY to PaymentCardDetailsSingleLineView. The default values for these resources are defined in terms of the general-purpose resources listed in the previous section. Overriding these values take precedence over values defined by the general-purpose resources.

Dimen Resources

olopay_paymentcarddetailssinglelineview_edittext_textsize
olopay_paymentcarddetailssinglelineview_errortext_textsize

Color Resources

olopay_paymentcarddetailssinglelineview_edittext_textcolor
olopay_paymentcarddetailssinglelineview_edittext_errorcolor
olopay_paymentcarddetailssinglelineview_edittext_hintcolor
olopay_paymentcarddetailssinglelineview_cardicon_tint
olopay_paymentcarddetailssinglelineview_errortext_textcolor

Override styles specific to PaymentCardDetailsSingleLineView

This is the most difficult option for customization but also allows for the most flexibility. One potential use case for overriding styles would be to change the font (though there are other means of doing that via application-wide themes, etc)

When overriding styles, note the following:

  • The style names MUST match what is listed below. You can choose a different parent but it should be a similar type of parent

  • Some resource values are not defined by the styles that can be overridden so when taking this approach you may need to override resource values as well

  • The styles listed below use some of the properties from above (see code below for which ones)

  • Overridden styles take precedence... if you override a style that is using one of the resource values from above, you will need to define it in your style

  • Because these are custom controls with custom behavior, not all standard Android style attributes will have an effect on the control

The styles that can be defined that will be applied to this view are listed here:

<style name="OloPay.PaymentCardDetailsSingleLineView.TextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">@color/olopay_paymentcarddetailssinglelineview_edittext_textcolor</item>
<item name="android:textSize">@dimen/olopay_paymentcarddetailssinglelineview_edittext_textsize</item>
<!-- Provide other customizations here -->
</style>

<style name="OloPay.PaymentCardDetailsSingleLineView.ErrorText">
<item name="android:textAppearance">@style/OloPay.PaymentCardDetailsSingleLineView.ErrorText.TextAppearance</item>
<!-- Provide other customizations here -->
</style>

<style name="OloPay.PaymentCardDetailsSingleLineView.ErrorText.TextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">@color/olopay_paymentcarddetailssinglelineview_errortext_textcolor</item>
<item name="android:textSize">@dimen/olopay_paymentcarddetailssinglelineview_errortext_textsize</item>
<!-- Provide other customizations here -->
</style>

Set styles programmatically

A number of methods exist that allow you to style PaymentCardDetailsSingleLineView. Methods exist for changing the background style (color, border, radius, etc), the text colors, error text colors, hint text colors, font, and font size.

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

Whether or not to display built-in error messages

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

Whether or not the postal code is enabled. It is enabled by default. Disabling the postal code field is discouraged because it could impact authorization success rates.

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
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
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
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)

Sets background styles for this view.

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?)

Sets the padding for the area immediately surrounding the card input fields.

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

Sets the color for the cursor, selection handles, and text selection highlight

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)

Enables or disables the control

Link copied to clipboard

Sets the error font for error messages

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

Sets the padding for the error message displayed below the card input fields.

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

Sets the error text color for all input fields and error messages

Link copied to clipboard

Sets the text size for error messages

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)

Sets the hint text for the specified field

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

Sets the hint text color for all input fields

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

Sets the text color for all input fields

Link copied to clipboard
fun setTextSize(size: Float)

Sets the text size for all input fields