npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@d24/sdk

v1.0.25

Published

Learn how to use our SDK in Javascript to allow integrations with our Deposits APIs

Downloads

198

Readme

D24 Credit card SDK

Learn how to use our SDK in Javascript to allow integrations with our Deposits APIs

Getting started

Start project

Project dependencies:

  • node
  • npm
  • python
  • poeditor

To start this project in a development environment follow the following steps:

  1. Run pip install poeditor
  2. Inside project folder run npm install and npm run dev.

Instalation

Load D24 as a npm module

Install the D24.js from the npm public registry.

npm install @d24/sdk

or

Manually load the D24.js script

Add the D24.js module as a script in the of your app HTML

<script
	type="module"
	src="https://d24sdk.s3.amazonaws.com/releases/d24-1.0.10.umd.js"
></script>

How to use

Instantiation

First of all, we must instantiate the SDK.

Keep in mind that the SDK can be instantiated only once, and it is a requirement to be able to use all its methods.

In order to instantiate the SDK we need to specify the public key and the environment.

  • npm
import SDK from '@d24/sdk';

new SDK('as1i2nxal12bvd', { environment: 'stg' });
  • umd
new window.D24.SDK('as1i2nxal12bvd', { environment: 'stg' });
constructor(publicKey, options)
Parameters

| Parameter | Type | Description | Required | Possible values | | ------------------- | ------ | -------------------------- | -------- | ------------------- | | publicKey | string | Public key provided by D24 | true | - | | options | object | Options | true | - | | options.environment | string | Environment | true | 'stg', 'production' |

Tokenaization a credit card

Once we instantiate the SDK, we can tokenize a card, said token will be used later to send it to the backend and generate the payment through an endpoint.

  • npm
import { generateToken } from '@d24/sdk';

const creditCard = {
	number: '4509953566233704',
	holder: 'Juan Perez',
	cvv: '123',
	expirationMonth: '11',
	expirationYear: '25',
};

const response = await generateToken({ card: creditCard });
const token = response.token;
  • umd
const creditCard = {
	number: '4509953566233704',
	holder: 'Juan Perez',
	cvv: '123',
	expirationMonth: '11',
	expirationYear: '25',
};

const response = await window.D24.generateToken({ card: creditCard });
const token = response.token;

API

Possible errors

| Error | Explanation | | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------- | | SDK was already instantiate. | The SDK has already been instantiated and you are trying to instantiate it again | | The environment [config.environment] is not supported. | The environment you passed to the constructor is not valid, remember that it only accepts "stg" or "prod" |

generateToken({card}): Promise<{token: string}>

This method validates that the card data is correct and generates a token. Although it has validations that occur at the frontend level, it uses a D24 endpoint to be able to generate the token which executes additional validations.

To validate the data structure, the joi library is used, therefore the errors returned at the frontend level are generated with said library.

Parameters

| Parameter | Type | Description | Required | Example | | -------------------- | ------ | ------------------------------------------------------------------------ | -------- | ---------------- | | card | object | Credit card values | true | - | | card.number | string | Credit card number | true | 4509953566233704 | | card.holder | string | Credit card holder | true | Juan Perez | | card.cvv | string | Credit card security code. Must be 3 digits, except for AMEX which are 4 | true | 123, 1234 | | card.expirationMonth | string | Credit card expiration month. Must be 2 digits | true | 11 | | card.expirationYear | string | Credit card expiration year. Must be 2 digits | true | 25 |

Returns

| Parameter | Type | Description | | --------- | ------ | --------------------- | | token | string | Credit card tokenized |

Possible errors

| Error | Explanation | | -------------------------------------------------------------- | ---------------------------------------------------------------------- | | You must instantiate D24CreditCardSDK before using SDK methods | You executed the method without having previously instantiated the SDK |


CreditCardForm

Fonts

Add the following fonts to your project (inside index.html or any main html):

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">

Form

After instantiating the SDK, we will be able to use the CreditCardForm component.

<CreditCardForm
    authToken="2NROUtadDbLT67UFZlvTCO9QOJhSyHhF"
    country="CL"
    lang="en"
    tokenCallBack={handleTokenCallback}
    tokenErrorCallBack={handleTokenErrorCallback}
    goBackCallBack={handleGoBack}
/>

Props

| Prop | Type | Description | Required | Example | Default | Possible values | | ------------------ | -------- | ---------------------------------------------------------------------------------- | -------- | ------- | ------- | ---------------- | | authToken | string | authToken of the merchant | true | | | country | string | Country code | true | CL | | tokenCallBack | function | Callback function that will be executed when the token is generated | true | - | | tokenErrorCallBack | function | Callback function that will be executed when an error occurs generating token | true | - | | goBackCallBack | function | Callback function that will be executed when the user clicks on the Go Back button | true | - | | lang | string | Language code | false | en | en | 'es', 'pt', 'en' |

Callbacks

tokenCallBack

This callback function will be executed when the token is generated successfully.

function handleTokenCallback(token: string) {
	console.log(token);
}

tokenErrorCallBack

This callback function will be executed when an error occurs generating token.

function handleTokenErrorCallback(error: string) {
	console.log(error);
}

goBackCallBack

This callback function will be executed when the user clicks on the Go Back button.

function handleGoBackCallback() {
	console.log('Go back');
}