1.0.2 • Published 2 months ago

@tap-payments/card-sdk v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

web-card-sdk

Handling card payments on the web using Tap's SDK

Install

This is a React module available through the npm registry. Installation is done using the npm install command:

npm install @tap-payments/card-sdk

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

yarn add @tap-payments/card-sdk

Examples

ES6

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

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

NameTypeR/ODescription
publicKeystringrequiredThe public Key provided by Tap
merchantobjectoptionalThe merchant object
merchant.idstringoptionalThe merchant's Tap id.
transactionobjectrequiredThe transaction object
transaction.amountnumberrequiredThe transaction amount.
transaction.currencystringrequiredThe transaction currency.
customerobjectoptionalThe customer object
customer.idstringoptionalThe customer ID
customer.nameArrayoptionalThe customer name object
customer.nameindex.langstringoptionalThe customer name language
customer.nameindex.firststringoptionalThe customer first name
customer.nameindex.laststringoptionalThe customer last name
customer.nameindex.middlestringoptionalThe customer middle name
customer.name.nameOnCardstringoptionalThe customer name on card
customer.name.editablebooleanoptionalTo control the name editing
customer.contactobjectoptionalThe customer contact object
customer.contact.emailstringoptionalThe customer email
customer.contact.phoneobjectoptionalThe customer phone object
customer.contact.phone.countryCodestringoptionalThe customer phone country code
customer.contact.phone.numberstringoptionalThe customer phone number
acceptanceobjectoptionalThe acceptance object
acceptance.supportedBrandsstring[]optionalThe supported brands
acceptance.supportedCardsstring[]optionalThe supported cards
fieldsobjectoptionalThe fields object
fields.cardHolderbooleanoptionalTo show/hide the card holder name
fields.cvvbooleanoptionalTo show/hide the cvv field
fields.savedCardCVVbooleanoptionalTo show/hide the cvv field when pay with saved card
addonsobjectoptionalThe addons object
addons.loaderbooleanoptionalTo show/hide the loader on the card
addons.saveCardbooleanoptionalTo show/hide the save card option
addons.displayPaymentBrandsbooleanoptionalTo show/hide the payment brands section
interfaceobjectoptionalThe interface object
interface.localestringoptionalThe card locale
interface.themestringoptionalThe card theme
interface.edgesstringoptionalThe card edges
interface.directionstringoptionalThe card direction
onReadyfunctionoptionalCallback function runs when card becomes ready
onFocusfunctionoptionalCallback function runs when card is focused
onBinIdentificationfunctionoptionalCallback function runs when bin is identified
onValidInputfunctionoptionalCallback function runs when card inputs are valid
onInvalidInputfunctionoptionalCallback function runs when card inputs are invalid
onErrorfunctionoptionalCallback function runs when card has an error
onSuccessfunctionoptionalCallback function runs when card is successfully done

Card Methods

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

import {
	resetCardInputs,
	saveCard,
	tokenize,
	updateCardConfiguration,
	updateTheme,
	loadSavedCard
} from '@tap-payments/card-sdk'
NameDescription
resetCardInputsReset the card inputs
saveCardSave the card data
tokenizeTokenize the card date
updateCardConfigurationUpdate the card configuration
updateThemeUpdate the card theme
loadSavedCardLoad the saved card by card id
1.0.2

2 months ago

1.0.2-beta

4 months ago

1.0.1-beta

4 months ago

1.0.1

7 months ago

1.0.0

7 months ago

0.0.30-development

8 months ago

0.0.29-development

8 months ago

0.0.28-development

8 months ago

0.0.2-locale

8 months ago

0.0.1-locale

8 months ago

0.0.27-development

8 months ago

0.0.26-development

8 months ago

0.0.25-development

8 months ago

0.0.24-development

8 months ago

0.0.23-development

8 months ago

0.0.22-development

8 months ago

0.0.21-development

8 months ago

0.0.20-development

8 months ago

0.0.19-development

8 months ago

0.0.18-development

8 months ago

0.0.17-development

8 months ago

0.0.16-development

8 months ago

0.0.15-development

8 months ago

0.0.14-development

8 months ago

0.0.13-development

8 months ago

0.0.12-development

8 months ago

0.0.11-development

8 months ago

0.0.4-staging

9 months ago

0.0.10-development

9 months ago

1.0.0-beta

9 months ago

0.0.3-staging

9 months ago

0.0.2-staging

9 months ago

0.0.1-staging

9 months ago

0.0.9-development

10 months ago

0.0.8-development

10 months ago

0.0.7-development

10 months ago

0.0.6-development

10 months ago

0.0.5-development

10 months ago

0.0.4-development

10 months ago

0.0.2-development

10 months ago

0.0.1-development

10 months ago

0.0.0-development

10 months ago