Git Product home page Git Product logo

creditcardentry's Introduction

CreditCardEntry

Join the chat at https://gitter.im/dbachelder/CreditCardEntry

Introduction

This library provides an elegant form for credit card entry that can be easily added to a activity or fragment. Regex is used to validate credit card types and a Luhn check is performed on the card numbers. This form was inspired by the credit entry UI on Square.

  • Smooth interface
  • Identifies credit card type
  • Hides number for privacy
  • Supports VISA, MasterCard, Discover and AMEX

Including in your project

This project uses JitPack to build and release.

Add JitPack to the end of your repositories

    repositories {

        ...

        maven { url "https://jitpack.io" }
    }

Add the project to your dependencies

    dependencies {

        ...

        compile 'com.github.dbachelder:CreditCardEntry:1.0.1'
    }

Using the library

Please see below for an example.

XML

        <com.devmarvel.creditcardentry.library.CreditCardForm
            android:id="@+id/credit_card_form"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:helper_text_color="@color/yellow_500"
            app:include_helper="false"
            app:include_zip="false"/>

app:helper_text_color - change the text color of the hints that appear below the widget by default. app:include_helper - boolean to show/hide the helper text under the widget (true by default (i.e. helper is shown)) app:include_zip - boolean to show/hide the zip code in the form (true by default (i.e. zip is shown))

In code:

    public class MainActivity extends Activity {
  
      private LinearLayout linearLayout;
      private CreditCardForm form;
  
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
  
        setContentView(R.layout.activity_main);
    	linearLayout = (LinearLayout) findViewById(R.id.layer);
		
        form = new CreditCardForm(this);
    	linearLayout.addView(form);
    	
    	buttonAuthorize = (Button) findViewById(R.id.buttonAuthorize);
    	buttonAuthorize.setOnClickListener(new OnClickListener() {
    		
    		@Override
    		public void onClick(View arg0) {
    			if(form.isCreditCardValid())
    			{
    				CreditCard card = form.getCreditCard();
    				//Pass credit card to service
    			}
    			else
    			{
    				//Alert Credit card invalid
    			}
    		}
    	});
    }

TODO

  • Diner's Club is not yet implemented, although the assets and regex seem to be in place

Version History

###4/2/2013

  • Initial Commit

###5/11/2013

  • Updated Demo added screenshots

###4/7/2015

  • Made zip code optional (app:include_zip="false")
  • added callback when data entry is complete and card is valid
  • optionally specify helper text color in XML attrs

###4/8/2015

  • Always return CreditCard object when requested even when invalid

###4/18/2015

  • Made helper optional (app:include_helper="false")
  • Fixed a ton of lint warnings
  • Fixed vertical alignment of form fields
  • Fixed over excited animation scroll
  • Last 4 of card now tappable to enter edit mode
  • updated image assets

###4/19/2015

  • Don't scroll when scrolling is already happening

###4/20/2015

  • Flip the card image back to the front after CVV field loses focus
  • Expose CardType on CreditCard object
  • Transferred repo ownership

creditcardentry's People

Contributors

dbachelder avatar evyatar-via avatar gitter-badger avatar jgrana avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.