# @tap-payments/card-sdk

> Tap Card Elements

Latest version **1.0.2** (published 2024-04-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install @tap-payments/card-sdk
pnpm add @tap-payments/card-sdk
yarn add @tap-payments/card-sdk
bun add @tap-payments/card-sdk
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2024-04-04 |
| First published | 2023-07-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 56.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ahmed Elsharkawy |
| Maintainers | mostafaabobakr.tap, i.mousa, mahmoudallam, aya_tap, mud_fahmi, ahmedkaram-tap, haitham-tap, muhammadazhar007, elsharkawy, waqast, hala.q, reham_alsabbagh, kalpanatap, sadbarkhattak |

## Links

- npm: https://www.npmjs.com/package/@tap-payments/card-sdk
- npm.io page: https://npm.io/package/@tap-payments/card-sdk

## Dependencies (4)

- [react](https://npm.io/package/react.md) ^18.2.0
- [jsencrypt](https://npm.io/package/jsencrypt.md) ^3.3.2
- [react-dom](https://npm.io/package/react-dom.md) 18.2.0
- [@tap-payments/browser-info](https://npm.io/package/@tap-payments/browser-info.md) ^1.0.2

## Recent versions

- 1.0.2 (latest) — 2024-04-04
- 0.0.1-demo (demo) — 2025-01-26
- 1.0.2-beta (beta) — 2024-02-05
- 0.0.30-development (development) — 2023-10-08
- 0.0.4-staging (staging) — 2023-09-03
- 1.0.1-beta — 2024-01-08
- 1.0.1 — 2023-10-29
- 1.0.0 — 2023-10-29
- 0.0.29-development — 2023-10-08
- 0.0.28-development — 2023-10-08
- 0.0.2-locale — 2023-10-03
- 0.0.1-locale — 2023-10-03
- 0.0.27-development — 2023-10-02
- 0.0.26-development — 2023-10-02
- 0.0.25-development — 2023-10-02
- … 28 more at https://npm.io/package/@tap-payments/card-sdk/versions

## README

# web-card-sdk

Handling card payments on the web using Tap's SDK

## Install

This is a [React](https://reactjs.org/) module available through the
[npm registry](https://www.npmjs.com/). Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):

```console
npm install @tap-payments/card-sdk
```

---------------------------- OR -------------------------

```console
yarn add @tap-payments/card-sdk
```

## Examples

### ES6

```javascript
import React from 'react'
import { TapCard, Currencies, Direction, Edges, Locale, Theme } from '@tap-payments/card-sdk'

const App = () => {
	return (
		<TapCard
			publicKey='pk_test_...'
			merchant={{
				id: 'merchant id'
			}}
			transaction={{
				amount: 1,
				currency: Currencies.SAR
			}}
			customer={{
				id: 'customer id',
				name: [
					{
						lang: Locale.EN,
						first: 'Ahmed',
						last: 'Sharkawy',
						middle: 'Mohamed'
					}
				],
				nameOnCard: 'Ahmed Sharkawy',
				editable: true,
				contact: {
					email: 'ahmed@gmail.com',
					phone: {
						countryCode: '20',
						number: '1000000000'
					}
				}
			}}
			acceptance={{
				supportedBrands: ['AMEX', 'VISA', 'MASTERCARD', 'MADA'],
				supportedCards: ['CREDIT', 'DEBIT']
			}}
			fields={{
				cardHolder: true
			}}
			addons={{
				displayPaymentBrands: true,
				loader: true,
				saveCard: true
			}}
			interface={{
				locale: Locale.EN,
				theme: Theme.LIGHT,
				edges: Edges.CURVED,
				direction: Direction.LTR
			}}
			onReady={() => console.log('onReady')}
			onFocus={() => console.log('onFocus')}
			onBinIdentification={(data) => console.log('onBinIdentification', data)}
			onValidInput={(data) => console.log('onValidInputChange', data)}
			onInvalidInput={(data) => console.log('onInvalidInput', data)}
			onError={(data) => console.log('onError', data)}
			onSuccess={(data) => console.log('onSuccess', data)}
		/>
	)
}
```

### Vanilla JS

```html
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<script src="https://tap-sdks.b-cdn.net/card/1.0.2/index.js"></script>

		<title>card demo</title>
	</head>
	<body>
		<div id="card-sdk-id"></div>
		<script>
			const { renderTapCard, Theme, Currencies, Direction, Edges, Locale } = window.CardSDK
			const { unmount } = renderTapCard('card-sdk-id', {
				publicKey: 'pk_test_...',
				merchant: {
					id: 'merchant id'
				},
				transaction: {
					amount: 1,
					currency: Currencies.SAR
				},
				customer: {
					id: 'customer id',
					name: [
						{
							lang: Locale.EN,
							first: 'Ahmed',
							last: 'Sharkawy',
							middle: 'Mohamed'
						}
					],
					nameOnCard: 'Ahmed Sharkawy',
					editable: true,
					contact: {
						email: 'ahmed@gmail.com',
						phone: {
							countryCode: '20',
							number: '1000000000'
						}
					}
				},
				acceptance: {
					supportedBrands: ['AMEX', 'VISA', 'MASTERCARD', 'MADA'],
					supportedCards: ['CREDIT', 'DEBIT']
				},
				fields: {
					cardHolder: true
				},
				addons: {
					displayPaymentBrands: true,
					loader: true,
					saveCard: true
				},
				interface: {
					locale: Locale.EN,
					theme: Theme.LIGHT,
					edges: Edges.CURVED,
					direction: Direction.LTR
				},
				onReady: () => console.log('onReady'),
				onFocus: () => console.log('onFocus'),
				onBinIdentification: (data) => console.log('onBinIdentification', data),
				onValidInput: (data) => console.log('onValidInputChange', data),
				onInvalidInput: (data) => console.log('onInvalidInput', data),
				onError: (data) => console.log('onError', data),
				onSuccess: (data) => console.log('onSuccess', data)
			})
		</script>
	</body>
</html>
```

## Configurations

| Name                               | Type       | R/O        | Description                                           |
| ---------------------------------- | ---------- | ---------- | ----------------------------------------------------- |
| publicKey                          | `string`   | `required` | The public Key provided by Tap                        |
| merchant                           | `object`   | `optional` | The merchant object                                   |
| merchant.id                        | `string`   | `optional` | The merchant's Tap id.                                |
| transaction                        | `object`   | `required` | The transaction object                                |
| transaction.amount                 | `number`   | `required` | The transaction amount.                               |
| transaction.currency               | `string`   | `required` | The transaction currency.                             |
| customer                           | `object`   | `optional` | The customer object                                   |
| customer.id                        | `string`   | `optional` | The customer ID                                       |
| customer.name                      | `Array`    | `optional` | The customer name object                              |
| customer.name[index].lang          | `string`   | `optional` | The customer name language                            |
| customer.name[index].first         | `string`   | `optional` | The customer first name                               |
| customer.name[index].last          | `string`   | `optional` | The customer last name                                |
| customer.name[index].middle        | `string`   | `optional` | The customer middle name                              |
| customer.name.nameOnCard           | `string`   | `optional` | The customer name on card                             |
| customer.name.editable             | `boolean`  | `optional` | To control the name editing                           |
| customer.contact                   | `object`   | `optional` | The customer contact object                           |
| customer.contact.email             | `string`   | `optional` | The customer email                                    |
| customer.contact.phone             | `object`   | `optional` | The customer phone object                             |
| customer.contact.phone.countryCode | `string`   | `optional` | The customer phone country code                       |
| customer.contact.phone.number      | `string`   | `optional` | The customer phone number                             |
| acceptance                         | `object`   | `optional` | The acceptance object                                 |
| acceptance.supportedBrands         | `string[]` | `optional` | The supported brands                                  |
| acceptance.supportedCards          | `string[]` | `optional` | The supported cards                                   |
| fields                             | `object`   | `optional` | The fields object                                     |
| fields.cardHolder                  | `boolean`  | `optional` | To show/hide the card holder name                     |
| fields.cvv                  | `boolean`  | `optional` | To show/hide the cvv field     |
| fields.savedCardCVV                  | `boolean`  | `optional` | To show/hide the cvv field when pay with saved card     |
| addons                             | `object`   | `optional` | The addons object                                     |
| addons.loader                      | `boolean`  | `optional` | To show/hide the loader on the card                   |
| addons.saveCard                    | `boolean`  | `optional` | To show/hide the save card option                     |
| addons.displayPaymentBrands        | `boolean`  | `optional` | To show/hide the payment brands section               |
| interface                          | `object`   | `optional` | The interface object                                  |
| interface.locale                   | `string`   | `optional` | The card locale                                       |
| interface.theme                    | `string`   | `optional` | The card theme                                        |
| interface.edges                    | `string`   | `optional` | The card edges                                        |
| interface.direction                | `string`   | `optional` | The card direction                                    |
| onReady                            | `function` | `optional` | Callback function runs when card becomes ready        |
| onFocus                            | `function` | `optional` | Callback function runs when card is focused           |
| onBinIdentification                | `function` | `optional` | Callback function runs when bin is identified         |
| onValidInput                       | `function` | `optional` | Callback function runs when card inputs are valid     |
| onInvalidInput                     | `function` | `optional` | Callback function runs when card inputs are invalid   |
| onError                            | `function` | `optional` | Callback function runs when card has an error         |
| onSuccess                          | `function` | `optional` | Callback function runs when card is successfully done |

## Card Methods

You can import all the required methods from the package as follows:

```javascript
import {
	resetCardInputs,
	saveCard,
	tokenize,
	updateCardConfiguration,
	updateTheme,
	loadSavedCard
} from '@tap-payments/card-sdk'
```

| Name                    | Description                    |
| ----------------------- | ------------------------------ |
| resetCardInputs         | Reset the card inputs          |
| saveCard                | Save the card data             |
| tokenize                | Tokenize the card date         |
| updateCardConfiguration | Update the card configuration  |
| updateTheme             | Update the card theme          |
| loadSavedCard           | Load the saved card by card id |

---
_Source: https://npm.io/package/@tap-payments/card-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
