npm

@tap-payments/card-web
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-development • Public • Published

Card-Web

We at Tap Payments strive to make your payments easier than ever. We as a PCI compliant company, provide you a from the self solution to process card payments in your Web applications.

demo

Steps overview

sequenceDiagram

participant  A  as  App
participant  T  as  Tap
participant  C  as  Card Web

A->>T:  Regsiter app.
T-->>A: Public key.
A ->> C : Install SDK
A ->> C : InitSDK(configurations)
C -->> A: onReady()
C -->> C : Enter card data
C -->> A : onBinIdentification(data)
C -->> A : onValidInput
A ->> C : CardSDK.tokenize()
C -->> A : onSuccess(data)

Get your keys

You can always use the example keys within our example app, but we do recommend you to head to our onboarding page. You will need to register your domain to get your Key that you will need to activate our Card-Web.

Install

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

npm install @tap-payments/card-web

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

yarn add @tap-payments/card-web

Examples

Simple Code Integration

ES6

import React from 'react'
import { TapCard, Currencies, Scope, Locale } from '@tap-payments/card-web'

const App = () => {
	return (
		<TapCard
			scope={Scope.TOKEN}
			operator={{
				publicKey: 'pk_test_...'
			}}
			order={{
				amount: 1,
				currency: Currencies.SAR,
				reference: ""	
			}}
			customer={{
				name: [
					{
						lang: Locale.EN,
						first: 'Ahmed',
						last: 'Sharkawy',
						middle: 'Mohamed'
					}
				],
				contact: {
					email: 'ahmed@gmail.com',
					phone: {
						countryCode: '20',
						number: '1000000000'
					}
				}
			}}
			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.0-development/index.js"></script>

		<title>card demo</title>
	</head>

	<body>
		<div id="card-web-id"></div>
		<script>
			const { renderTapCard, Currencies, Scope, Locale } = window.CardSDK
			const { unmount } = renderTapCard('card-web-id', {
				scope: Scope.TOKEN,
				operator: {
					publicKey: 'pk_test_YhUjg9PNT8oDlKJ1aE2fMRz7'
				},
				order: {
					amount: 1,
					currency: Currencies.SAR,
					reference: ""
				},
				customer: {
					name: [
						{
							lang: Locale.EN,
							first: 'Ahmed',
							last: 'Sharkawy',
							middle: 'Mohamed'
						}
					],
					contact: {
						email: 'ahmed@gmail.com',
						phone: {
							countryCode: '20',
							number: '1000000000'
						}
					}
				},
				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>

Tokenizing a card

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

import { resetCardInputs, tokenize } from '@tap-payments/card-web'
Name Description
resetCardInputs Reset the card inputs
tokenize Tokenize the card date

Advanced Code Integration

ES6

import React from 'react'
import { TapCard, Currencies, Direction, Edges, Locale, Theme, Scope, ColorStyle } from '@tap-payments/card-web'

const App = () => {
	return (
		<TapCard
			scope={Scope.TOKEN}
			operator={{
				publicKey: 'pk_test_...'
			}}
			transaction={{
				reference: 'transaction_xxx',
				paymentAgreement: {
					id: '',
					contract: {
						id: ''
					}
				}
			}}
			order={{
				id: '',
				amount: 1,
				currency: Currencies.SAR,
				description: 'description',
				reference: '',
				metadata: { key: 'value' }
			}}
			invoice={{
				id: 'invoice_xxx'
			}}
			customer={{
				id: 'cus_xxx',
				name: [
					{
						lang: Locale.EN,
						first: 'test',
						last: 'test',
						middle: 'test'
					}
				],
				nameOnCard: 'test',
				editable: false,
				contact: {
					email: 'example@tap.com',
					phone: {
						countryCode: '20',
						number: '1000000000'
					}
				}
			}}
			merchant={{
				id: ''
			}}
			interface={{
				locale: Locale.EN,
				cardDirection: Direction.DYNAMIC,
				edges: Edges.CURVED,
				theme: Theme.DARK,
				powered: true,
				colorStyle: ColorStyle.COLORED,
				loader: true
			}}
			features={{
				acceptanceBadge: true,
				customerCards: {
					saveCard: true,
					autoSaveCard: true
				}
			}}
			fieldsVisibility={{
				card: {
					cardHolder: true
				}
			}}
			acceptance={{
				supportedSchemes: ['AMEX', 'VISA', 'MASTERCARD', 'MADA'],
				supportedFundSource: ['CREDIT', 'DEBIT'],
				supportedPaymentAuthentications: ['3DS']
			}}
			post={{
				url: 'https://...'
			}}
			onReady={() => console.log('onReady')}
			onFocus={() => console.log('onFocus')}
			onBinIdentification={(data) => console.log('onBinIdentification', data)}
			onValidInput={(data) => console.log('onValidInputChange', 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.0-development/index.js"></script>

    <title>card demo</title>
</head>

<body>
    <div id="card-web-id"></div>
    <script>
        const { renderTapCard, Currencies, Scope, Locale, Direction, Theme, Edges, ColorStyle } = window.CardSDK
        const { unmount } = renderTapCard('card-web-id', {
            scope: Scope.TOKEN,
            operator: {
                publicKey: 'pk_test_YhUjg9PNT8oDlKJ1aE2fMRz7'
            },
            transaction: {
                reference: 'transaction_xxx',
                paymentAgreement: {
                    id: '',
                    contract: {
                        id: ''
                    }
                }
            },
            order: {
                id: '',
                amount: 1,
                currency: Currencies.SAR,
                description: 'description',
                reference: '',
                metadata: { key: 'value' }
            },
            invoice: {
                id: 'invoice_xxx'
            },
            customer: {
                id: '',
                name: [
                    {
                        lang: Locale.EN,
                        first: 'test',
                        last: 'test',
                        middle: 'test'
                    }
                ],
                nameOnCard: 'test',
                editable: false,
                contact: {
                    email: 'example@tap.com',
                    phone: {
                        countryCode: '20',
                        number: '1000000000'
                    }
                }
            },
            merchant: {
                id: ''
            },
            interface: {
                locale: Locale.EN,
                cardDirection: Direction.DYNAMIC,
                edges: Edges.CURVED,
                theme: Theme.DARK,
                powered: true,
                colorStyle: ColorStyle.COLORED,
                loader: true
            },
            features: {
                acceptanceBadge: true,
                customerCards: {
                    saveCard: true,
                    autoSaveCard: true
                }
            },
            fieldsVisibility: {
                card: {
                    cardHolder: true
                }
            },
            acceptance: {
                supportedSchemes: ['AMEX', 'VISA', 'MASTERCARD', 'MADA'],
                supportedFundSource: ['CREDIT', 'DEBIT'],
                supportedPaymentAuthentications: ['3DS']
            },
            post: {
                url: 'https://...'
            },
            onReady: () => console.log('onReady'),
            onFocus: () => console.log('onFocus'),
            onBinIdentification: (data) => console.log('onBinIdentification', data),
            onValidInput: (data) => console.log('onValidInputChange', data),
            onError: (data) => console.log('onError', data),
            onSuccess: (data) => console.log('onSuccess', data)
        })
    </script>
</body>

</html>

Configurations

Configuration Description Required Type Sample
operator This is the Key that you will get after registering you domain. True String {"publicKey":"pk_test_YhUjg9PNT8oDlKJ1aE2fMRz7"}
scope Defines the intention of using the Card-SDK. True String "Token"
purpose Defines the intention of using the Token after generation. True String "Transaction"
transaction Needed to define transaction metadata and reference, if you are generating an authenticated token. False Object {"reference":"A reference to this transaciton in your system"],"paymentAgreement":{"id":"", "contract":{"id":"If you created a contract id with the client to save his card, pass its is here. Otherwise, we will create one for you."}}
order This is the order id that you created before or amount and currency to generate a new order. It will be linked this token. True Object {"id":"", "amount":1, "currency":"SAR", "description": "Authentication description","reference":"","metadata":{}}
invoice This is the invoice id that you want to link this token to if any. False Object {"id":""}
merchant This is the Merchant id that you will get after registering you bundle id. True Object {"id":""}
customer The customer details you want to attach to this tokenization process. True Object {"id":"", "name":[{"lang":"en","first":"TAP","middle":"","last":"PAYMENTS"}], "nameOnCard":"TAP PAYMENTS", "editble":true, "contact":{"email":"tap@tap.company", "phone":{"countryCode":"+965","number":"88888888"}}}
features Some extra features that you can enable/disable based on the experience you want to provide.. False Object {"acceptanceBadge":true, "customerCards":{"saveCard":false, "autoSaveCard":false}}
acceptance The acceptance details for the transaction. Including, which card brands and types you want to allow for the customer to tokenize/save. False Object {"supportedSchemes":["AMERICAN_EXPRESS","VISA","MASTERCARD","OMANNET","MADA"], "supportedFundSource":["CREDIT","DEBIT"], "supportedPaymentAuthentications":["3DS"]}
fieldsVisibility Needed to define visibility of the optional fields in the card form. False Object {"card":{"cardHolder":true}}
interface Needed to defines look and feel related configurations. False Object {"locale": "en", "theme": "light", "edges": "curved", "direction": "dynamic", "powered": true, "colorStyle": "colored", "loader": true}
post This is the webhook for your server, if you want us to update you server to server. False Object {"url":""}

Documentation per variable

  • operator:
    • Responsible for passing the data that defines you as a merchant within Tap system.
  • operator.publicKey:
    • A string, which you get after registering the app bundle id within the Tap system. It is required to correctly identify you as a merchant.
    • You will receive a sandbox and a production key. Use, the one that matches your environment at the moment of usage.
  • scope:
    • Defines the intention of the token you are generating.
    • When the token is used afterwards, the usage will be checked against the original purpose to make sure they are a match.
    • Possible values:
      • Token : This means you will get a Tap token to use afterwards.
      • AuthenticatedToken This means you will get an authenticated Tap token to use in our charge api right away.
      • SaveToken This means you will get a token to use multiple times with authentication each time.
      • SaveAuthenticatedToken This means you will get an authenticated token to use in multiple times right away.
  • purpose:
    • Defines the intention of using the Token after generation.
    • Possible values:
      • Transaction Using the token for a single charge.
      • Milestone Transaction Using the token for paying a part of a bigger order, when reaching a certain milestone.
      • Installment Transaction Using the token for a charge that is a part of an installement plan.
      • Billing Transaction Using the token for paying a bill.
      • Subscription Transaction Using the token for a recurring based transaction.
      • Verify Cardholder Using the token to verify the ownership of the card.
      • Save Card Using the token to save this card and link it to a certain customer.
  • transaction:
    • Provides essential information about this transaction.
  • transaction.reference:
    • Pass this value if you want to link this transaction to the a one you have within your system.
  • transaction.paymentAgreement.id:
    • The id the payment agreement you created using our Apis.
    • This is an agreement between you and your client to allow saving his card for further payments.
    • If not passed, it will be created on the fly.
  • transaction.paymentAgreement.contract.id:
    • The id the contract you created using our Apis.
    • This is a contract between you and your client to allow saving his card for further payments.
    • If not passed, it will be created on the fly.
  • order:
    • The details about the order that you will be using the token you are generating within.
  • order.id:
    • The id of the order if you already created it using our apis.
  • order.currency:
    • The intended currency you will perform the order linked to this token afterwards.
  • order.amount:
    • The intended amount you will perform the order linked to this token afterwards.
  • order.description:
    • Optional string to put some clarifications about the order if needed.
  • order.reference:
    • Optional string to put a reference to link it to your system.
  • order.metadata:
    • Optional, It is a key-value based parameter. You can pass it to attach any miscellaneous data with this order for your own convenience.
  • invoice.id:
    • Optional string to pass an invoice id, that you want to link to this token afterwards.
  • merchant.id:
    • Optional string to pass to define a sub entity registered under your key in Tap. It is the Merchant id that you get from our onboarding team.
  • customer.id:
    • If you have previously have created a customer using our apis and you want to link this token to him. please pass his id.
  • customer.name:
    • It is a list of localized names. each name will have:
      • lang : the 2 iso code for the locale of this name for example en
      • first : The first name.
      • middle: The middle name.
      • last : The last name.
  • customer.nameOnCard:
    • If you want to prefill the card holder's name field.
  • customer.editable:
    • A boolean that controls whether the customer can edit the card holder's name field or not.
  • customer.contact.email:
    • An email string for the customer we are creating. At least the email or the phone is required.
  • customer.contact.phone:
    • The customer's phone:
      • countryCode
      • number
  • features:
    • Some extra features/functionalities that can be configured as per your needs.
  • features.acceptanceBadge:
    • A boolean to indicate wether or not you want to display the list of supported card brands that appear beneath the card form itself.
  • features.customerCards.saveCard:
    • A boolean to indicate wether or not you want to display the save card option to the customer.
    • Must be used with a combination of these scopes:
      • SaveToken
      • SaveAuthenticatedToken
  • features.customerCards.autoSave:
    • A boolean to indicate wether or not you want the save card switch to be on by default.
  • acceptance:
    • List of configurations that control the payment itself.
  • acceptance.supportedSchemes:
    • A list to control which card schemes the customer can pay with. For example:
      • AMERICAN_EXPRESS
      • VISA
      • MASTERCARD
      • MADA
      • OMANNET
  • acceptance.supportedFundSource:
    • A list to control which card types are allowed by your customer. For example:
      • DEBIT
      • CREDIT
  • acceptance.supportedPaymentAuthentications:
    • A list of what authentication techniques you want to enforce and apple. For example:
      • 3DS
  • fieldsVisibility.card.cardHolder:
    • A boolean to indicate wether or not you want to show/collect the card holder name.
  • interface.loader:
    • A boolean to indicate wether or not you want to show a loading view on top of the card form while it is performing api requests.
  • interface.locale:
    • The language of the card form. Accepted values as of now are:
      • en
      • ar
  • interface.theme:
    • The display style of the card form. Accepted values as of now are:
      • light
      • dark
      • dynamic // follow the device's display style
  • interface.edges:
    • How do you want the edges of the card form to. Accepted values as of now are:
      • curved
      • flat
  • interface.cardDirection:
    • The layout of the fields (card logo, number, date & CVV) within the card element itself. Accepted values as of now are:
      • ltr // fields will inflate from left to right
      • rtl // fields will inflate from right to left
      • dynamic // fields will inflate in the locale's direction
  • interface.powered:
    • A boolean to indicate wether or not you want to show powered by tap.
    • Note, that you have to have the permission to hide it from the integration team. Otherwise, you will get an error if you pass it as false.
  • interface.colorStyle:
    • How do you want the icons rendered inside the card form to. Accepted values as of now are:
      • colored
      • monochrome

Readme

Keywords

none

Package Sidebar

Install

npm i @tap-payments/card-web

Weekly Downloads

207

Version

1.0.0-development

License

ISC

Unpacked Size

101 kB

Total Files

47

Last publish

Collaborators

  • sherifashraftap
  • mostafaabobakr.tap
  • i.mousa
  • mahmoudallam
  • aya_tap
  • mud_fahmi
  • ahmedkaram-tap
  • haitham-tap
  • muhammadazhar007
  • elsharkawy
  • waqast
  • hala.q
  • reham_alsabbagh
  • kalpanatap
  • sadbarkhattak