fschaule/android-card-form


A ready-made card form layout that can be included in your Android app, making it easy to accept credit and debit cards.

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.fschaule:android-card-form:'
	}
	dependencies {
		implementation("com.github.fschaule:android-card-form:")
	}
	<dependency>
	    <groupId>com.github.fschaule</groupId>
	    <artifactId>android-card-form</artifactId>
	    <version></version>
	</dependency>

                            
    libraryDependencies += "com.github.fschaule" % "android-card-form" % ""
        
        

                            
    :dependencies [[com.github.fschaule/android-card-form ""]]
        
        

Readme


Card Form

Card Form is a ready made card form layout that can be included in your app making it easy to accept credit and debit cards.

Build Status

Adding It To Your Project

In your build.gradle:

dependencies {
    compile 'com.braintreepayments:card-form:2.1.1'
}

Usage

Card Form is a LinearLayout that you can add to your layout:

<com.braintreepayments.cardform.view.CardForm
    android:id="@+id/bt_card_form"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

To initialize the view and change which fields are required for the user to enter, use CardForm#setRequiredFields(Activity activity, boolean cardNumberRequired, boolean expirationRequired, boolean cvvRequired, boolean postalCodeRequired, String imeActionLabel).

CardForm cardForm = (CardForm) findViewById(R.id.bt_card_form);
cardForm.setRequiredFields(Activity.this, true, true, false, false, "Purchase");

To access the values in the form, there are getters for each field:

cardForm.getCardNumber();
cardForm.getExpirationMonth();
cardForm.getExpirationYear();
cardForm.getCvv();
cardForm.getPostalCode();

To check if CardForm is valid call CardForm#isValid(). To validate each required field and show the user which fields are incorrect, call CardForm#validate().

Additionally CardForm has 3 available listeners:

  • CardForm#setOnCardFormValidListener called when the form changes state from valid to invalid or invalid to valid.
  • CardForm#setOnCardFormSubmitListener called when the form should be submitted.
  • CardForm#setOnFormFieldFocusedListener called when a field in the form is focused.

Styling

All card form inputs use the colorAccent theme attribute, when present, to set their focused color. For more information on the colorAccent attribute, see Using the Material Theme.

The included sample app has examples of a Holo theme, Material light theme and Material dark theme.

Releases

License

Card Form is open source and available under the MIT license. See the LICENSE file for more info.