1.0.76 • Published 1 year ago

@tap-payments/js_card v1.0.76

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

New Tap Card SDK

Steps to integrate in 3rd party

1. Install latest version

npm

npm i @tap-payments/js_card@latest

yarn

yarn add @tap-payments/js_card@latest

2. Sample Code Create Token

import {TapCard, create} from '@tap-payments/js_card'
import { useState } from 'react';

function App() {
  const [createEnabled,setCreateEnabled] = useState(false)
  const [tokenCreated,setTokenCreated]=useState(false)

  return (
    <div style={{textAlign:"center"}}>
        <div>
        <TapCard
        onBin={(data) => {
						console.log(data)
        }}
        onFocus={(data) => {
          console.log(data)
        }}
        onChangeSaveCardLater={(data) => {
          console.log(data)
        }}
        onChangeSaveCardLaterTap={(data) => {
          console.log(data)
        }}
        onChange={(data) => {
						console.log(data)
					}}
        onTokenCreated={(token) => {
          setTokenCreated(token.id)
        }}
        isAllInputsValid={(data) => {
          setCreateEnabled(data)
        }}
        publicKey='pk_test_EtHFV4BuPQokJT6jiROls87Y' mid={null}
        themeMode='light'
        paymentOptions={{
          locale:'en',
          showBrands:true,
          showLoadingState:true,
          collectHolderName:true,
          preLoadCardName:"Dummy Name",
          cardNameEditable:false,
          currencyCode: 'all',
          labels: {
            cardNumber: 'Card Number',
            expirationDate: 'MM/YY',
            cvv: 'CVV',
            cardHolder: 'Card Holder Name'
          },
          paymentAllowed: 'all',
          TextDirection: 'ltr',
          cardFundingSource: 'all',//'all'|'credit'|'debit'
          saveCardOption: 'all',//'all' | 'merchant' | 'tap' | 'none'
        }}
        errors={{
          showErrorComponent: true
        }}
        /></div>
        <div>
          {tokenCreated!=false &&
          <div>
            Token: {tokenCreated}
          </div>}
        <button onClick={create} className='button token_button' disabled={!createEnabled}>
					Create Token
				</button>

        </div>

    </div>
  );
}

export default App;

3. Sample Code for Save Card, Load Saved Card Create Token and reset card

import {TapCard, create, loadSavedCard, reset, saveCard, threeDsRedirect } from '@tap-payments/js_card'
import { useState } from 'react';

const App = () => {
	const [createEnabled, setCreateEnabled] = useState(true)
	const [message, setMessage] = useState('')
	const [tokenCreated, setTokenCreated] = useState(false)
	const [savedCard, setSavedCard] = useState(false)
	const [threeDSResponse, setThreeDSResponse] = useState(false)
	return (
		<div style={{ textAlign: 'center' }}>
			<div>
				<TapCard
					on3dsResponse={(data) => {
						setThreeDSResponse(data)
					}}
					onRedirectUrl={(data) => {
						console.log(data)
					}}
					on3dsRedirect={(data) => {
						console.log(data)
					}}
					on3dsFail={(data) => {
						setMessage(data.message)
					}}
					onCardSaved={(data) => {
						setSavedCard(data)
					}}
					onBin={(data) => {
						console.log(data)
					}}
					onFocus={(data) => {
						console.log(data)
					}}
					onChangeSaveCardLater={(data) => {
						console.log(data)
					}}
					onChangeSaveCardLaterTap={(data) => {
						console.log(data)
					}}
					onChange={(data) => {
						console.log(data)
					}}
					onTokenCreated={(token) => {
						setTokenCreated(token.id)
					}}
					isAllInputsValid={(data) => {
						setCreateEnabled(data)
					}}
					onResetLoadedCard={() => console.log('loadedCard reset')}
					publicKey='pk_test_dpfw6e4RlD1Qt3bBhyo9g5uC'
					mid={null}
					themeMode='light'
					paymentOptions={{
						cardFundingSource: 'all',
						saveCardOption: 'all',
						locale: 'en',
						showBrands: true,
						showLoadingState: true,
						collectHolderName: true,
						preLoadCardName: 'Dummy Name',
						cardNameEditable: true,
						currencyCode: ['KWD'],
						labels: {
							cardNumber: 'Card Number',
							expirationDate: 'MM/YY',
							cvv: 'CVV',
							cardHolder: 'Card Holder Name'
						},
						paymentAllowed: 'all',
						TextDirection: 'ltr',
						customer: 'cus_TS075220212320q2RD0707283'
					}}
					errors={{
						showErrorComponent: true
					}}
				/>
			</div>
			{tokenCreated != false && <div>Token: {tokenCreated}</div>}
			{message !== '' && <div>Message: {message}</div>}
			{savedCard != false && <div>Saved Card: {JSON.stringify(savedCard)}</div>}
			{threeDSResponse != false && <div>3DS Response: {JSON.stringify(threeDSResponse)}</div>}
			<div style={{ display: 'flex', gap: '5px', justifyContent: 'center' }}>
				<button className='button token_button' onClick={create} disabled={!createEnabled}>
					Create Token
				</button>
				<button className='button token_button' onClick={saveCard} disabled={!createEnabled}>
					Save Card
				</button>
				<button className='button token_button' onClick={() => loadSavedCard('card_iOj120231017AjsM12BV1m744')}>
					Load Saved Card
				</button>
				<button className='button token_button' onClick={() => reset()}>
					Reset
				</button>
			</div>
		</div>
	)
}

export default App;

Updating payment option without reloading

import {updatePaymentOption } from '@tap-payments/js_card'
updatePaymentOption({
						currencyCode: ['SAR']
					})

3DS redirect

Before creating a charge or authorize from a token, you will also get the url to pass in redirect_url request, after getting the token you will get the url as string on callback onRedirectUrl for 3DS redirect a method is provided namely threeDsRedirect, you can pass it the exact authorize or charge object you get from the API

import {threeDsRedirect } from '@tap-payments/js_card'
//after creating a charge/authorize, pass the API response to this method
threeDsRedirect({
    "id": "chg_TS04A5620231240w4RJ2102536",
    "object": "charge",
    "live_mode": false,
    "api_version": "V2",
    "method": "CREATE",
    "status": "INITIATED",
    "amount": 1.000,
    "currency": "KWD",
    "threeDSecure": true,
    "card_threeDSecure": false,
    "save_card": false,
    "merchant_id": "",
    "product": "GOSELL",
    "statement_descriptor": "Sample",
    "description": "Test Description",
    "metadata": {
        "udf1": "test 1",
        "udf2": "test 2"
    },
    "transaction": {
        "timezone": "UTC+03:00",
        "created": "1676983256552",
        "url": "https://sandbox.payments.tap.company/test_gosell/v2/payment/tap_process.aspx?chg=Xj%2fukFm8u%2bEyC2IVLXWG0EM8ud73eUxlFky0HkmM5a8%3d",
        "expiry": {
            "period": 30,
            "type": "MINUTE"
        },
        "asynchronous": false,
        "amount": 1.000,
        "currency": "KWD"
    },
    "reference": {
        "gosell_id": "00",
        "transaction": "txn_0001",
        "order": "ord_0001"
    },
    "response": {
        "code": "100",
        "message": "Initiated"
    },
    "card": {
        "object": "card",
        "first_six": "424242",
        "last_four": "4242",
        "name": "DUMMY NAME",
        "expiry": {
            "month": "03",
            "year": "30"
        }
    },
    "receipt": {
        "email": false,
        "sms": true
    },
    "customer": {
        "first_name": "test",
        "last_name": "test",
        "email": "test@test.com",
        "phone": {
            "country_code": "965",
            "number": "50000000"
        }
    },
    "merchant": {
        "country": "KW",
        "currency": "KWD",
        "id": "1124340"
    },
    "source": {
        "object": "token",
        "id": "tok_O6g01623940FI8v21kr1F266"
    },
    "redirect": {
        "status": "PENDING",
        "url": "https://sandbox.payments.tap.company/test_gosell/v2/payment/redirect.aspx?id=redirect_TS04A5620231240Rx4g2102536"
    },
    "post": {
        "status": "PENDING",
        "url": "http://your_website.com/post_url"
    },
    "activities": [
        {
            "id": "activity_TS02A5720231240Me342102411",
            "object": "activity",
            "created": 1676983256552,
            "status": "INITIATED",
            "currency": "KWD",
            "amount": 1.000,
            "remarks": "charge - created"
        }
    ],
    "auto_reversed": false
})

when above method is invoked, the card form redirects to 3ds and upon redirecting back it retrieves authorize/charge and gives back response on callback on3dsResponse

Steps to run project independently

  1. Install dependencies
yarn install
  1. run dev server
yarn run start
1.0.62

1 year ago

1.0.61

1 year ago

1.0.65

1 year ago

1.0.64

1 year ago

1.0.63

1 year ago

1.0.69

1 year ago

1.0.68

1 year ago

1.0.67

1 year ago

1.0.73

1 year ago

1.0.72

1 year ago

1.0.71

1 year ago

1.0.70

1 year ago

1.0.77

1 year ago

1.0.76

1 year ago

1.0.75

1 year ago

1.0.74

1 year ago

1.0.78

1 year ago

1.0.60

1 year ago

1.0.51

1 year ago

1.0.50

1 year ago

1.0.55

1 year ago

1.0.54

1 year ago

1.0.53

1 year ago

1.0.52

1 year ago

1.0.59

1 year ago

1.0.58

1 year ago

1.0.57

1 year ago

1.0.56

1 year ago

1.0.48

1 year ago

1.0.47

1 year ago

1.0.46

1 year ago

1.0.45

1 year ago

1.0.49

1 year ago

1.0.39

1 year ago

1.0.38

1 year ago

1.0.40

1 year ago

1.0.44

1 year ago

1.0.43

1 year ago

1.0.42

1 year ago

1.0.41

1 year ago

1.0.33

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.37

1 year ago

1.0.36

1 year ago

1.0.35

1 year ago

1.0.34

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

2 years ago