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

@webpag/card-tokenizer

v1.0.3

Published

Pacote para tokenização de cartões de crédito para uso na Webpag.

Readme

@webpag/card-tokenizer

Gera um card_token no navegador ou em Node.js para envio às APIs da Webpag. Os dados do cartão são criptografados no cliente e nunca trafegam em texto puro.

Instalação

npm install @webpag/card-tokenizer

Como funciona

A chave pública usada para tokenizar o cartão é obtida na API Webpag, no endpoint:

  • GET /card-token/public-key (requer autenticação com o token de API da sua empresa)

Importante: esse endpoint deve ser chamado no seu backend. Seu backend autentica com o token de API da Webpag, obtém a public_key e a envia para o frontend (por exemplo, ao renderizar a página de pagamento ou via um endpoint seu). O frontend não deve ter o token de API; ele só recebe a chave pública e usa este pacote para gerar o token de cartão no navegador.

Fluxo recomendado:

  1. Backend (seu servidor): chama GET /card-token/public-key com o header de autenticação (token de API Webpag) e obtém public_key.
  2. Backend → Frontend: envia a public_key para a página (inline no HTML, via API própria, etc.).
  3. Frontend: usa esta biblioteca com a public_key recebida para tokenizar os dados do cartão digitados pelo usuário.
  4. Frontend → Backend: envia o card_token gerado (por exemplo, em POST /payments/process ou POST /payers/{id}/creditcard).

Uso

No frontend, após ter a chave pública (entregue pelo seu backend):

import { createCardToken } from '@webpag/card-tokenizer';

// A publicKey deve vir do seu backend (que a obteve em GET /card-token/public-key da Webpag).
// Nunca use o token de API da Webpag no frontend.
const publicKey = 'INSIRA PUBLIC KEY DA WEBPAG'; // substituir pela chave recebida do seu backend

const cardToken = await createCardToken(
  {
    number: '4111111111111111',
    name: 'JOAO DA SILVA',
    expiration_month: '12',
    expiration_year: '2028',
    security_code: '123',
  },
  publicKey
);

// Enviar cardToken no campo card_token para /payments/process, /payers/{id}/creditcard, etc.

Com a classe CardTokenizer (útil quando você gera vários tokens com a mesma chave):

import { CardTokenizer } from '@webpag/card-tokenizer';

const publicKey = 'INSIRA PUBLIC KEY DA WEBPAG'; // obtida do seu backend

const tokenizer = new CardTokenizer(publicKey);
const token = await tokenizer.createToken({
  number: '4111111111111111',
  name: 'JOAO DA SILVA',
  expiration_month: '12',
  expiration_year: '2028',
  security_code: '123',
});

Formato dos dados do cartão

| Campo | Descrição | |---------------------|------------------------------------| | number | Número do cartão (apenas dígitos) | | name | Nome como no cartão | | expiration_month | Mês de validade (01–12) | | expiration_year | Ano (4 dígitos ou 2, ex.: 2028) | | security_code | CVV |

Observações

  • O token gerado é um payload RSA codificado em base64url.
  • A chave pública está vinculada ao token de API usado na requisição a /card-token/public-key.
  • A chave pode ser retornada sem os delimitadores PEM (-----BEGIN/END PUBLIC KEY-----); a biblioteca aceita os dois formatos.
  • Quando gerado a public-key, ela é associado ao auth-token utilizado na Webpag. Ou seja, ao gerar um auth-token novo, o public_key também muda.