# @rajeshsmallarc/react-native-creditcard

> React Native Credit Card Input Form

Latest version **1.0.1** (published 2020-08-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rajeshsmallarc/react-native-creditcard
pnpm add @rajeshsmallarc/react-native-creditcard
yarn add @rajeshsmallarc/react-native-creditcard
bun add @rajeshsmallarc/react-native-creditcard
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-08-23 |
| First published | 2020-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 321 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | rajesh@smallarc.com |
| Maintainers | rajeshsmallarc |
| Keywords | react-native, credit-card, credit-card-input-form, react-native-component, react-native-payment, react-native-creditcard |

## Links

- npm: https://www.npmjs.com/package/@rajeshsmallarc/react-native-creditcard
- Repository: https://github.com/rajeshsmallarc/react-native-creditcard
- Homepage: https://github.com/rajeshsmallarc/react-native-creditcard#readme
- Issues: https://github.com/rajeshsmallarc/react-native-creditcard/issues
- npm.io page: https://npm.io/package/@rajeshsmallarc/react-native-creditcard

## Dependencies (6)

- [prop-types](https://npm.io/package/prop-types.md) ^15.6.0
- [lodash.pick](https://npm.io/package/lodash.pick.md) ^4.4.0
- [lodash.every](https://npm.io/package/lodash.every.md) ^4.6.0
- [lodash.values](https://npm.io/package/lodash.values.md) ^4.3.0
- [card-validator](https://npm.io/package/card-validator.md) ^6.2.0
- [lodash.compact](https://npm.io/package/lodash.compact.md) ^3.0.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2020-08-23
- 1.0.0 — 2020-08-23

## README

> ## This project is a modified version of this one, https://www.npmjs.com/package/react-native-input-credit-card

# React Native CreditCard
Credit Card Input for React Native Project

<p align="center">
<img src="https://github.com/rajeshsmallarc/react-native-creditcard/blob/master/example/image/Example.png?raw=true" width=200/>
</p>

Code:

```js
<CreditCardInput onChange={this._onChange} />
```


# Features
* credit-card 💳 (inspired by: [card](https://jessepollak.github.io/card/), [react-native-input-credit-card](https://www.npmjs.com/package/react-native-input-credit-card))
* Credit-card input validations & formatting while you're typing
* Form is fully navigatable using keypad
* Works on both Android and iOS

# Usage

```bash
npm i @rajeshsmallarc/react-native-creditcard --save
```

then add these lines in your react-native codebase

```js
import { CreditCardInput } from "@rajeshsmallarc/react-native-creditcard";

<CreditCardInput onChange={this._onChange} />

```

And then on your onChange handler:

```js
_onChange => card => console.log(card);

// will print:
{
  valid: true, // will be true once all fields are "valid" (time to enable the submit button)
  values: { // will be in the sanitized and formatted form
  	number: "4242 4242 4242 4242",
  	expiry: "12/25",
  	cvc: "123",
  	type: "visa", // will be one of [null, "visa", "master-card", "american-express", "diners-club", "discover", "jcb", "unionpay", "maestro"]
  	name: "Rajesh",
  	postalCode: "123456",
  },
  status: {  // will be one of ["incomplete", "invalid", and "valid"]
	number: "incomplete",
	expiry: "incomplete",
	cvc: "incomplete",
	name: "incomplete", 
	postalCode: "incomplete",
  },
};

// Notes: 
// You can enable/disable cvc, name using requiresCVC, requiresName, requiresPostalCode)

// Example: 

<CreditCardInput 
	onChange={this._onChange} 
	requiresName
	requiresPostalCode
/>
```


## CreditCardInput
| Property | Type | Description |
| --- | --- | --- |
|autoFocus | PropTypes.bool | Automatically focus Card Number field on render|
|onChange | PropTypes.func | Receives a `formData` object every time the form changes |
|onFocus | PropTypes.func | Receives the name of currently focused field |
|labels | PropTypes.object | Defaults to <br/>`{ number: "CARD NUMBER", expiry: "EXPIRY", cvc: "CVC/CCV" }` |
|placeholders | PropTypes.object | Defaults to <br/>`{ number: "1234 5678 1234 5678", expiry: "MM/YY", cvc: "CVC" }` |
|cardScale | PropTypes.number | Scales the credit-card view.<br/>Defaults to `1`, which translates to `{ width: 300, height: 190 }` |
|cardFontFamily | PropTypes.string | Font family for the CreditCardView, works best with monospace fonts. Defaults to Courier (iOS) or monospace (android) |
|cardImageFront | PropTypes.number | Image for the credit-card view `e.g. require("./card.png")` |
|cardImageBack | PropTypes.number | Image for the credit-card view `e.g. require("./card.png")` |
|labelStyle | Text.propTypes.style | Style for credit-card form's labels |
|inputStyle | Text.propTypes.style | Style for credit-card form's textInput |
|inputContainerStyle | ViewPropTypes.style | Style for textInput's container<br/> Defaults to: `{ borderBottomWidth: 1, borderBottomColor: "black" }` |
|validColor | PropTypes.string | Color that will be applied for valid text input. Defaults to: "{inputStyle.color}" |
|invalidColor | PropTypes.string | Color that will be applied for invalid text input. Defaults to: "red" |
|placeholderColor | PropTypes.string | Color that will be applied for text input placeholder. Defaults to: "gray" |
|requiresName | PropTypes.bool | Shows cardholder's name field<br/> Default to `false` |
|requiresCVC | PropTypes.bool | Shows CVC field<br/> Default to `true` |
|requiresPostalCode | PropTypes.bool | Shows postalCode field<br/> Default to `false` |
|validatePostalCode | PropTypes.func | Function to validate postalCode, expects `incomplete`, `valid`, or `invalid` as return values|
|allowScroll | PropTypes.bool | enables horizontal scrolling on CreditCardInput <br/> Defaults to `false` |
|cardBrandIcons | PropTypes.object | brand icons for CardView. see `./src/Icons.js` for details |
| additionalInputsProps | PropTypes.objectOf(TextInput.propTypes) | An object with Each key of the object corresponding to the name of the field. Allows you to change all props documented in [RN TextInput](https://facebook.github.io/react-native/docs/textinput.html).

#### Note on additionalInputsProps

additionalInputsProps gives you more control over the inputs in CreditCardInput. An example object is as follows:
```javascript
addtionalInputsProps = {
  name: {
    defaultValue: 'my name',
    maxLength: 40,
  },
  postalCode: {
    returnKeyType: 'go',
  },
};
```

The above would set the default value of the name field to `my name` and limit the input to a maximum of 40 character. In addition, it would set the returnKeyType of the postalcode field to `go`.

# Methods
## setValues
Set values into credit card form


```js
	// sets 4242 4242 4242 4242 on credit card number field
	// other fields will stay unchanged
	this.refs.CCInput.setValues({ number: "4242 4242 4242 4242" });
```

## focus
focus on to specified field

```js
	// focus to expiry field
	this.refs.CCInput.focus("expiry");
```

# Missing Something? Something is not working?
* Open a GitHub issue or Send a pull request

# TODO
* Rewrite using hooks aiming performance and simplicity
* Add unit and integration tests

---
_Source: https://npm.io/package/@rajeshsmallarc/react-native-creditcard · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
