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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@useblu/checkout-tokenization

v1.0.0

Published

SDK de tokenizacao de cartoes da Blu para checkout ecommerce (fork de @malga/tokenization). Dados sensiveis transitam apenas entre iframes seguros e a Malga; o lojista recebe apenas o tokenId.

Downloads

115

Readme

SDK de tokenizacao de cartoes da Blu para checkout ecommerce. Os dados sensiveis do cartao transitam exclusivamente entre iframes seguros e a Malga — o SDK, o lojista e a API de cobranca nunca acessam dados de cartao, apenas o tokenId (conformidade PCI DSS).

Fork de @malga/tokenization (MIT). A logica de tokenizacao e herdada do upstream; este fork adiciona branding, CI/CD, exemplos e documentacao Blu.

Installation

npm install @useblu/checkout-tokenization

or

pnpm add @useblu/checkout-tokenization

Getting Started

  1. Adicione no seu formulario os containers para cada campo do cartao:
<form onsubmit="handleGetTokenId(event)">
  <div id="card-number"></div>
  <div id="card-holder-name"></div>
  <div id="card-cvv"></div>
  <div id="card-expiration-date"></div>
  <button type="submit">Pagar</button>
</form>
  1. Configure o SDK com as credenciais do merchant e chame tokenize():
import { BluTokenization } from '@useblu/checkout-tokenization'

const tokenization = new BluTokenization({
  apiKey: '<API_KEY_DO_MERCHANT>',
  clientId: '<CLIENT_ID_DO_MERCHANT>',
  options: {
    config: {
      fields: {
        cardNumber: {
          container: 'card-number',
          placeholder: '9999 9999 9999 9999',
        },
        cardHolderName: {
          container: 'card-holder-name',
          placeholder: 'Nome impresso',
        },
        cardExpirationDate: {
          container: 'card-expiration-date',
          placeholder: 'MM/AA',
        },
        cardCvv: { container: 'card-cvv', placeholder: '999' },
      },
      styles: {
        input: { color: '#000', 'font-size': '16px' },
      },
      preventAutofill: false,
    },
    sandbox: true,
  },
})

// Eventos disponiveis
tokenization.on('cardTypeChanged', (event) => console.log('bandeira', event))
tokenization.on('validity', (event) => console.log('validity', event))
tokenization.on('focus', (event) => console.log('focus', event))
tokenization.on('blur', (event) => console.log('blur', event))

async function handleGetTokenId(event) {
  event.preventDefault()

  const { tokenId } = await tokenization.tokenize()

  // Envie o tokenId + dados da cobranca para a API de cobranca — ver abaixo.
  await criarCobranca(tokenId)
}

As credenciais (apiKey / clientId) sao por merchant e sao fornecidas pela Blu.

Fluxo completo

O fluxo tem dois passos:

  1. Gerar o token — o SDK tokeniza o cartao e retorna um tokenId (tokenize()). Os dados sensiveis ficam entre os iframes seguros e a Malga.
  2. Enviar o token para a API de cobranca — envie o tokenId, junto com os dados da cobranca, para a API de cobranca, que cria a cobranca.
async function criarCobranca(tokenId) {
  await fetch('https://<endpoint-da-api-de-cobranca>/<rota-de-cobranca>', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      client_uuid: '<identificador-do-lojista>',
      charge: {
        amount: 15000, // inteiro em centavos
        order_id: 'pedido-123',
        statement_descriptor: 'LOJA XYZ',
        description: 'Pedido 123',
        payment_method: { payment_type: 'credit', installments: 3 },
        payment_source: { source_type: 'token', token_id: tokenId },
      },
    }),
  })
}

API Reference

new BluTokenization(configurations)

| Campo | Tipo | Descricao | | -------------------------------- | --------- | ------------------------------------------------------------------------------------------- | | apiKey | string | Chave de API do merchant | | clientId | string | Identificador do merchant | | options.config.fields | object | Config dos campos seguros (cardNumber, cardHolderName, cardExpirationDate, cardCvv) | | options.config.styles | object | Estilos dos inputs | | options.config.preventAutofill | boolean | Desabilita autofill | | options.sandbox | boolean | Ambiente sandbox |

tokenize(): Promise<{ tokenId, error? }>

Retorna { tokenId } em caso de sucesso, ou { error } em caso de falha (error.type, error.declinedCode quando card_declined).

on(eventType, handler)

Eventos: validity, cardTypeChanged, focus, blur.

Ambientes

O ambiente e escolhido por options — nao ha URL a configurar:

| options | Ambiente Malga | | ---------------------------- | ------------------------------------------ | | { debug: true } | dev (hosted-fields.dev.malga.io) | | { sandbox: true } | sandbox (hosted-fields-sandbox.malga.io) | | {} ou { sandbox: false } | producao (hosted-fields.malga.io) |

Para producao, use as credenciais de producao do merchant (fornecidas pela Blu).

Tratamento de erros

const { tokenId, error } = await tokenization.tokenize()

if (error) {
  // error.type: 'api_error' | 'bad_request' | 'invalid_request_error' | 'card_declined'
  // error.declinedCode: 'insufficient_funds' | 'invalid_cvv' | 'expired_card' | ...
  console.error(error.type, error.message, error.declinedCode)
}

Examples

Seguranca (PCI DSS)

Os dados de cartao transitam apenas entre os iframes seguros e a Malga. Nem o frontend do lojista, nem o SDK, nem a API de cobranca tem acesso aos dados sensiveis — somente ao tokenId resultante.

Contributing

Whether you're helping us fix bugs, improve the docs, or spread the word, we'd love to have you as part of this project! Read below to learn how you can take part of it.

Code of Conduct

We adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Contributing Guide

Read our contributing guide to learn about our development process, how to propose bugfixes and improvements, how we sync with the upstream project, and how to build and test your changes.

Security

Found a security issue? Please do not open a public issue — follow our security policy and report it privately to [email protected].

License

Licensed under the terms of the MIT License. This project is a fork of plughacker/malga-tokenization, with attribution preserved.