payment-token-efi 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +18 -0
- package/README.md +216 -199
- package/assets/css/bootstrap.min.css +6 -0
- package/assets/css/bootstrap.min.css.map +1 -0
- package/assets/css/custom.css +31 -0
- package/assets/img/favicon.png +0 -0
- package/assets/img/logo-ef.svg +1 -0
- package/dist/payment-token-efi-cjs.min.js +3 -0
- package/dist/payment-token-efi-esm.min.js +3 -0
- package/dist/payment-token-efi-umd.min.js +3 -0
- package/dist/payment-token-efi.min.js +3 -0
- package/examples/app-angular.ts +54 -0
- package/examples/app-browser.html +55 -0
- package/examples/app-react.js +63 -0
- package/examples/app-react.tsx +59 -0
- package/examples/app-vue.vue +70 -0
- package/index.html +383 -0
- package/package.json +8 -12
- package/types/payment-token-efi.d.ts +49 -0
- package/distNode/payment-token-efi.js +0 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import EfiPay from '../dist/payment-token-efi-umd.min.js';
|
|
4
|
+
|
|
5
|
+
const App = () => {
|
|
6
|
+
const [paymentToken, setPaymentToken] = useState('');
|
|
7
|
+
const [cardMask, setCardMask] = useState('');
|
|
8
|
+
const [loading, setLoading] = useState(false);
|
|
9
|
+
|
|
10
|
+
const runEfiJsCode = async () => {
|
|
11
|
+
setLoading(true);
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const result = await EfiPay.CreditCard
|
|
15
|
+
.debugger(true, true)
|
|
16
|
+
.setAccount('Identificador_de_conta_aqui')
|
|
17
|
+
.setEnvironment('sandbox') // 'production' or 'sandbox'
|
|
18
|
+
.setCreditCardData({
|
|
19
|
+
brand: 'visa',
|
|
20
|
+
number: '4485785674290087',
|
|
21
|
+
cvv: '123',
|
|
22
|
+
expirationMonth: '05',
|
|
23
|
+
expirationYear: '2031',
|
|
24
|
+
reuse: false
|
|
25
|
+
})
|
|
26
|
+
.getPaymentToken();
|
|
27
|
+
|
|
28
|
+
setPaymentToken(result.payment_token);
|
|
29
|
+
setCardMask(result.card_mask);
|
|
30
|
+
console.log('payment_token', result.payment_token);
|
|
31
|
+
console.log('card_mask', result.card_mask);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.log(err);
|
|
34
|
+
console.log('Código: ', err.code);
|
|
35
|
+
console.log('Nome: ', err.error);
|
|
36
|
+
console.log('Mensagem: ', err.error_description);
|
|
37
|
+
} finally {
|
|
38
|
+
setLoading(false);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div>
|
|
44
|
+
<button onClick={runEfiJsCode} disabled={loading}>
|
|
45
|
+
{loading ? 'Fetching...' : 'Fetch Payment Token'}
|
|
46
|
+
</button>
|
|
47
|
+
{paymentToken && cardMask && (
|
|
48
|
+
<div>
|
|
49
|
+
Payment Token: {paymentToken}<br />
|
|
50
|
+
Card Mask: {cardMask}
|
|
51
|
+
</div>
|
|
52
|
+
)}
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default function Home() {
|
|
58
|
+
return (
|
|
59
|
+
<div>
|
|
60
|
+
<App />
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import "./App.css";
|
|
3
|
+
import EfiPay from "../dist/payment-token-efi-esm.min.js";
|
|
4
|
+
|
|
5
|
+
const App: React.FC = () => {
|
|
6
|
+
const [paymentToken, setPaymentToken] = useState<string>("");
|
|
7
|
+
const [cardMask, setCardMask] = useState<string>("");
|
|
8
|
+
const [loading, setLoading] = useState<boolean>(false);
|
|
9
|
+
|
|
10
|
+
const runEfiJsCode = async () => {
|
|
11
|
+
setLoading(true);
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const result = await EfiPay.CreditCard.debugger(true, true)
|
|
15
|
+
.setAccount("Identificador_de_conta_aqui")
|
|
16
|
+
.setEnvironment("sandbox") // 'production' or 'sandbox'
|
|
17
|
+
.setCreditCardData({
|
|
18
|
+
brand: "visa",
|
|
19
|
+
number: "4485785674290087",
|
|
20
|
+
cvv: "123",
|
|
21
|
+
expirationMonth: "05",
|
|
22
|
+
expirationYear: "2031",
|
|
23
|
+
reuse: false,
|
|
24
|
+
})
|
|
25
|
+
.getPaymentToken();
|
|
26
|
+
|
|
27
|
+
setPaymentToken(result.payment_token);
|
|
28
|
+
setCardMask(result.card_mask);
|
|
29
|
+
console.log("payment_token", result.payment_token);
|
|
30
|
+
console.log("card_mask", result.card_mask);
|
|
31
|
+
} catch (err: any) {
|
|
32
|
+
console.log(err);
|
|
33
|
+
console.log("Código: ", err.code);
|
|
34
|
+
console.log("Nome: ", err.error);
|
|
35
|
+
console.log("Mensagem: ", err.error_description);
|
|
36
|
+
} finally {
|
|
37
|
+
setLoading(false);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div className="App">
|
|
43
|
+
<header className="App-header">
|
|
44
|
+
<button onClick={runEfiJsCode} disabled={loading}>
|
|
45
|
+
{loading ? "Fetching..." : "Fetch Payment Token"}
|
|
46
|
+
</button>
|
|
47
|
+
{paymentToken && cardMask && (
|
|
48
|
+
<div>
|
|
49
|
+
Payment Token: {paymentToken}
|
|
50
|
+
<br />
|
|
51
|
+
Card Mask: {cardMask}
|
|
52
|
+
</div>
|
|
53
|
+
)}
|
|
54
|
+
</header>
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default App;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div id="app">
|
|
3
|
+
<button @click="runEfiJsCode" :disabled="loading">
|
|
4
|
+
{{ loading ? 'Fetching...' : 'Fetch Payment Token' }}
|
|
5
|
+
</button>
|
|
6
|
+
<div v-if="paymentToken && cardMask">
|
|
7
|
+
Payment Token: {{ paymentToken }}<br />
|
|
8
|
+
Card Mask: {{ cardMask }}
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script>
|
|
14
|
+
import { ref } from 'vue';
|
|
15
|
+
import EfiPay from '../dist/payment-token-efi-umd.min.js';
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
name: 'App',
|
|
19
|
+
setup() {
|
|
20
|
+
const paymentToken = ref('');
|
|
21
|
+
const cardMask = ref('');
|
|
22
|
+
const loading = ref(false);
|
|
23
|
+
|
|
24
|
+
const runEfiJsCode = async () => {
|
|
25
|
+
loading.value = true;
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
await EfiPay.CreditCard
|
|
29
|
+
.debugger(true, true)
|
|
30
|
+
.setAccount('Identificador_de_conta_aqui')
|
|
31
|
+
.setEnvironment('sandbox'); // 'production' or 'sandbox'
|
|
32
|
+
|
|
33
|
+
const result = await EfiPay.CreditCard
|
|
34
|
+
.setCreditCardData({
|
|
35
|
+
brand: 'visa',
|
|
36
|
+
number: '4485785674290087',
|
|
37
|
+
cvv: '123',
|
|
38
|
+
expirationMonth: '05',
|
|
39
|
+
expirationYear: '2031',
|
|
40
|
+
reuse: false
|
|
41
|
+
})
|
|
42
|
+
.getPaymentToken();
|
|
43
|
+
|
|
44
|
+
paymentToken.value = result.payment_token;
|
|
45
|
+
cardMask.value = result.card_mask;
|
|
46
|
+
console.log('payment_token', result.payment_token);
|
|
47
|
+
console.log('card_mask', result.card_mask);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.error(err);
|
|
50
|
+
console.log('Código: ', err.code);
|
|
51
|
+
console.log('Nome: ', err.error);
|
|
52
|
+
console.log('Mensagem: ', err.error_description);
|
|
53
|
+
} finally {
|
|
54
|
+
loading.value = false;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
paymentToken,
|
|
60
|
+
cardMask,
|
|
61
|
+
loading,
|
|
62
|
+
runEfiJsCode,
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<style scoped>
|
|
69
|
+
/* Adicione seu estilo aqui */
|
|
70
|
+
</style>
|
package/index.html
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="pt-br">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
7
|
+
<link id="favicon" href="./assets/img/favicon.png" rel="shortcut icon" type="image/png">
|
|
8
|
+
<title>Exemplo Payment Token | Efí</title>
|
|
9
|
+
|
|
10
|
+
<!-- CSS -->
|
|
11
|
+
<link href="./assets/css/bootstrap.min.css" rel="stylesheet">
|
|
12
|
+
<link href="./assets/css/custom.css" rel="stylesheet">
|
|
13
|
+
|
|
14
|
+
<!-- Script -->
|
|
15
|
+
<script src="./dist/payment-token-efi-umd.min.js"></script>
|
|
16
|
+
|
|
17
|
+
<script>
|
|
18
|
+
document.addEventListener('DOMContentLoaded', () => { // Aguarda o carregamento da página para iniciar os scripts
|
|
19
|
+
// Configuração
|
|
20
|
+
var inputIdentificadorConta = document.getElementById("identificadorConta");
|
|
21
|
+
var inputValorTotal = document.getElementById("valorTotal");
|
|
22
|
+
// Dados cartão
|
|
23
|
+
var inputNumeroCartao = document.getElementById("numeroCartao");
|
|
24
|
+
var inputBandeira = document.getElementById("bandeira");
|
|
25
|
+
var inputMesVencimento = document.getElementById("mesVencimento");
|
|
26
|
+
var inputAnoVencimento = document.getElementById("anoVencimento");
|
|
27
|
+
var inputCvv = document.getElementById("cvv");
|
|
28
|
+
// Resultados
|
|
29
|
+
var inputParcelas = document.getElementById("opcoesParcelamento");
|
|
30
|
+
var inputPaymentToken = document.getElementById("paymentToken");
|
|
31
|
+
var inputmascaraCartao = document.getElementById("mascaraCartao");
|
|
32
|
+
// Botão de acionamento
|
|
33
|
+
var btnGerarToken = document.getElementById("gerarPaymentToken");
|
|
34
|
+
|
|
35
|
+
const efi = EfiPay.CreditCard;
|
|
36
|
+
|
|
37
|
+
efi
|
|
38
|
+
.debugger(false)
|
|
39
|
+
.setEnvironment('sandbox') // 'production' or 'sandbox';
|
|
40
|
+
|
|
41
|
+
inputNumeroCartao.addEventListener("input", async function () {
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* Identifica a bandeira a partir do número do cartão
|
|
45
|
+
* @params { numeroCartao }
|
|
46
|
+
*/
|
|
47
|
+
if (inputNumeroCartao.value.length >= 15) {
|
|
48
|
+
try {
|
|
49
|
+
resultBandeira = await efi
|
|
50
|
+
.setCardNumber(inputNumeroCartao.value)
|
|
51
|
+
.verifyCardBrand();
|
|
52
|
+
|
|
53
|
+
inputBandeira.value = resultBandeira;
|
|
54
|
+
buscarParcelamemto(resultBandeira); // aciona a função para buscar as opções de parcelamento
|
|
55
|
+
} catch (error) {
|
|
56
|
+
alert(`Erro ao obter a bandeira!\n\nCódigo: ${error.code}\nNome: ${error.error}\nMensagem: ${error.error_description}`);
|
|
57
|
+
console.warn(`Algo deu errado ao verificar a bandeira.\n ${error}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/*
|
|
61
|
+
* FIM - Identifica a bandeira a partir do número do cartão
|
|
62
|
+
*/
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
async function buscarParcelamemto(bandeira) {
|
|
66
|
+
|
|
67
|
+
/*
|
|
68
|
+
* Retorna as informações de parcelamento
|
|
69
|
+
* @params { identificadorConta, ambiente, bandeira, valorTotal }
|
|
70
|
+
*/
|
|
71
|
+
try {
|
|
72
|
+
const resultParcelas = await efi
|
|
73
|
+
.setAccount(inputIdentificadorConta.value)
|
|
74
|
+
.setBrand(bandeira)
|
|
75
|
+
.setTotal(parseInt(inputValorTotal.value))
|
|
76
|
+
.getInstallments();
|
|
77
|
+
|
|
78
|
+
const opcoes = resultParcelas.installments.map(installment => `
|
|
79
|
+
<option value="${installment.installment}">
|
|
80
|
+
${installment.installment} x de R$${installment.currency} ${installment.has_interest === false ? "sem juros" : ""}
|
|
81
|
+
</option>`
|
|
82
|
+
).join('');
|
|
83
|
+
|
|
84
|
+
inputParcelas.innerHTML = `<option value="0">Escolha como deseja pagar</option>${opcoes}`;
|
|
85
|
+
|
|
86
|
+
} catch (error) {
|
|
87
|
+
alert(`Erro ao buscar as parcelas!\n\nCódigo: ${error.code}\nNome: ${error.error}\nMensagem: ${error.error_description}`);
|
|
88
|
+
throw new Error(`Something went wrong.\n ${error}`);
|
|
89
|
+
}
|
|
90
|
+
/*
|
|
91
|
+
* FIM - Retorna as informações de parcelamento
|
|
92
|
+
*/
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
btnGerarToken.addEventListener("click", async function () {
|
|
96
|
+
btnGerarToken.classList.add('disabled');
|
|
97
|
+
|
|
98
|
+
btnGerarToken.innerHTML = '<div class="spinner-border spinner-border-sm text-info" role="status"> <span class="visually-hidden">Loading...</span></div>';
|
|
99
|
+
|
|
100
|
+
/*
|
|
101
|
+
* Retorna o payment_token e card_mask
|
|
102
|
+
* @params { identificadorConta, ambiente, {bandeira, numeroCartao, cvv, mesVencimento, anoVencimento, reuse} }
|
|
103
|
+
*/
|
|
104
|
+
try {
|
|
105
|
+
const resultPaymentToken = await efi
|
|
106
|
+
.setAccount(inputIdentificadorConta.value)
|
|
107
|
+
.setEnvironment('sandbox') // 'production' or 'sandbox'
|
|
108
|
+
.setCreditCardData({
|
|
109
|
+
brand: inputBandeira.value,
|
|
110
|
+
number: inputNumeroCartao.value,
|
|
111
|
+
cvv: inputCvv.value,
|
|
112
|
+
expirationMonth: inputMesVencimento.value,
|
|
113
|
+
expirationYear: inputAnoVencimento.value,
|
|
114
|
+
reuse: false
|
|
115
|
+
})
|
|
116
|
+
.getPaymentToken();
|
|
117
|
+
|
|
118
|
+
let payment_token = resultPaymentToken.payment_token;
|
|
119
|
+
let card_mask = resultPaymentToken.card_mask;
|
|
120
|
+
|
|
121
|
+
inputPaymentToken.value = payment_token;
|
|
122
|
+
mascaraCartao.value = card_mask;
|
|
123
|
+
|
|
124
|
+
btnGerarToken.classList.remove('btn-primary');
|
|
125
|
+
btnGerarToken.classList.add('btn-success');
|
|
126
|
+
btnGerarToken.innerHTML = 'Gerar novamente';
|
|
127
|
+
btnGerarToken.classList.remove('disabled');
|
|
128
|
+
} catch (error) {
|
|
129
|
+
alert(`Erro ao buscar ao gerar o payment_token!\n\nCódigo: ${error.code}\nNome: ${error.error}\nMensagem: ${error.error_description}`);
|
|
130
|
+
btnGerarToken.innerHTML = 'Gerar payment_token';
|
|
131
|
+
btnGerarToken.classList.remove('disabled');
|
|
132
|
+
throw new Error(`Something went wrong.\n ${error}`);
|
|
133
|
+
}
|
|
134
|
+
/*
|
|
135
|
+
* FIM - Retorna o payment_token e card_mask
|
|
136
|
+
*/
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
inputValorTotal.addEventListener("input", function () {
|
|
140
|
+
if (inputIdentificadorConta.value.length === 32 && inputNumeroCartao.value.length >= 16 && inputValorTotal.value.length >= 3) {
|
|
141
|
+
buscarParcelamemto(inputBandeira.value);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
inputIdentificadorConta.addEventListener("input", function () {
|
|
146
|
+
if (inputIdentificadorConta.value.length === 32 && inputNumeroCartao.value.length >= 16) {
|
|
147
|
+
buscarParcelamemto(inputBandeira.value);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
inputParcelas.addEventListener("change", function () {
|
|
152
|
+
btnGerarToken.classList.remove('disabled');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
</script>
|
|
156
|
+
|
|
157
|
+
</head>
|
|
158
|
+
|
|
159
|
+
<body>
|
|
160
|
+
|
|
161
|
+
<div class="container">
|
|
162
|
+
|
|
163
|
+
<header class="d-flex flex-wrap justify-content-center py-2 mb-2">
|
|
164
|
+
<a href="" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-dark text-decoration-none">
|
|
165
|
+
<img style="height: 80px;" src="./assets/img/logo-ef.svg" alt="Logo Efí">
|
|
166
|
+
</a>
|
|
167
|
+
|
|
168
|
+
<ul class="nav nav-pills">
|
|
169
|
+
<li class="nav-item">
|
|
170
|
+
<a href="https://github.com/efipay/frontend-payment-token-efi" target="_blank"
|
|
171
|
+
class="nav-link">Github</a>
|
|
172
|
+
</li>
|
|
173
|
+
<li class="nav-item">
|
|
174
|
+
<a href="https://dev.sejaefi.com.br/docs/pagamento-com-cartao#1-obten%C3%A7%C3%A3o-do-payment_token"
|
|
175
|
+
target="_blank" class="nav-link">Documentação</a>
|
|
176
|
+
</li>
|
|
177
|
+
<li class="nav-item">
|
|
178
|
+
<a href="https://comunidade.sejaefi.com.br/" target="_blank" class="nav-link">Comunidade</a>
|
|
179
|
+
</li>
|
|
180
|
+
</ul>
|
|
181
|
+
|
|
182
|
+
<div class="py-2 text-center">
|
|
183
|
+
<h2>Página de demonstração - Gerar payment_token</h2>
|
|
184
|
+
<p class="lead">Um payment_token é um conjunto de caracteres gerado de forma segura pela API Efí que
|
|
185
|
+
representa os
|
|
186
|
+
dados do cartão de crédito do pagador.</p>
|
|
187
|
+
</div>
|
|
188
|
+
</header>
|
|
189
|
+
|
|
190
|
+
<main>
|
|
191
|
+
|
|
192
|
+
<form method="POST" action="./" novalidate>
|
|
193
|
+
<!-- Início - Configuração para funcionamento do script - Identificador de conta -->
|
|
194
|
+
<!-- Veja aqui onde oncontrá-lo: https://sejaefi.link/rJeE-NNOm2 -->
|
|
195
|
+
<h4 class="mb-3">Configuração</h4>
|
|
196
|
+
<div class="row">
|
|
197
|
+
<div class="col-md-8">
|
|
198
|
+
<label for="identificadorConta" class="form-label">Identificador de conta
|
|
199
|
+
<code>
|
|
200
|
+
<a target="_blank" href="https://s3.amazonaws.com/gerencianet-pub-prod-1/printscreen/2023/03/08/matheus.rodrigues/24fa15-dda30019-a643-409e-8813-c7cc68adcc40.png"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-link-45deg" viewBox="0 0 16 16">
|
|
201
|
+
<path d="M4.715 6.542 3.343 7.914a3 3 0 1 0 4.243 4.243l1.828-1.829A3 3 0 0 0 8.586 5.5L8 6.086a1.002 1.002 0 0 0-.154.199 2 2 0 0 1 .861 3.337L6.88 11.45a2 2 0 1 1-2.83-2.83l.793-.792a4.018 4.018 0 0 1-.128-1.287z"/>
|
|
202
|
+
<path d="M6.586 4.672A3 3 0 0 0 7.414 9.5l.775-.776a2 2 0 0 1-.896-3.346L9.12 3.55a2 2 0 1 1 2.83 2.83l-.793.792c.112.42.155.855.128 1.287l1.372-1.372a3 3 0 1 0-4.243-4.243L6.586 4.672z"/>
|
|
203
|
+
</svg>onde encontro?</a>
|
|
204
|
+
</code>
|
|
205
|
+
</label>
|
|
206
|
+
<input type="text" class="form-control" name="identificadorConta" id="identificadorConta">
|
|
207
|
+
</div>
|
|
208
|
+
<div class="col-md-4">
|
|
209
|
+
<label for="valorTotal" class="form-label">Valor total
|
|
210
|
+
<code data-bs-toggle="tooltip" data-bs-placement="top"
|
|
211
|
+
title="(Integer) Ex: '24990' equivale a R$249,90">
|
|
212
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16">
|
|
213
|
+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
|
|
214
|
+
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/>
|
|
215
|
+
</svg>
|
|
216
|
+
</code>
|
|
217
|
+
</label>
|
|
218
|
+
<input type="number" class="form-control" name="valorTotal" id="valorTotal" value="24990">
|
|
219
|
+
</div>
|
|
220
|
+
</div>
|
|
221
|
+
<!-- Fim - Configuração para funcionamento do script - Identificador de conta -->
|
|
222
|
+
|
|
223
|
+
<hr>
|
|
224
|
+
|
|
225
|
+
<!-- Início - Inputs com informações do cartão de crédito -->
|
|
226
|
+
<h4 class="mb-3">Informação do cartão
|
|
227
|
+
<code>
|
|
228
|
+
<a target="_blank" href="https://www.4devs.com.br/gerador_de_numero_cartao_credito"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-link-45deg" viewBox="0 0 16 16">
|
|
229
|
+
<path d="M4.715 6.542 3.343 7.914a3 3 0 1 0 4.243 4.243l1.828-1.829A3 3 0 0 0 8.586 5.5L8 6.086a1.002 1.002 0 0 0-.154.199 2 2 0 0 1 .861 3.337L6.88 11.45a2 2 0 1 1-2.83-2.83l.793-.792a4.018 4.018 0 0 1-.128-1.287z"/>
|
|
230
|
+
<path d="M6.586 4.672A3 3 0 0 0 7.414 9.5l.775-.776a2 2 0 0 1-.896-3.346L9.12 3.55a2 2 0 1 1 2.83 2.83l-.793.792c.112.42.155.855.128 1.287l1.372-1.372a3 3 0 1 0-4.243-4.243L6.586 4.672z"/>
|
|
231
|
+
</svg>cartão fictício</a>
|
|
232
|
+
</code>
|
|
233
|
+
</h4>
|
|
234
|
+
<div class="row gy-3">
|
|
235
|
+
<div class="col-md-7">
|
|
236
|
+
<label for="numeroCartao" class="form-label">Número do cartão
|
|
237
|
+
<code data-bs-toggle="tooltip" data-bs-placement="top"
|
|
238
|
+
title="(String - 'XXXXXXXXXXXXXXXX')"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16">
|
|
239
|
+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
|
|
240
|
+
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/>
|
|
241
|
+
</svg>
|
|
242
|
+
</code>
|
|
243
|
+
</label>
|
|
244
|
+
<input type="text" class="form-control" name="numeroCartao" id="numeroCartao">
|
|
245
|
+
</div>
|
|
246
|
+
|
|
247
|
+
<div class="col-md-5">
|
|
248
|
+
<!-- Bandeira será preenchida dinamicamente de acordo com o número do cartão informado -->
|
|
249
|
+
<label for="bandeira" class="form-label">Bandeira
|
|
250
|
+
<code data-bs-toggle="tooltip" data-bs-placement="top"
|
|
251
|
+
title="(String - 'visa', 'mastercard', 'amex', 'elo', 'hipercard') Obtida a partir do número do cartão"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16">
|
|
252
|
+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
|
|
253
|
+
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/>
|
|
254
|
+
</svg>
|
|
255
|
+
</code>
|
|
256
|
+
</label>
|
|
257
|
+
<input type="text" class="form-control" name="bandeira" id="bandeira" readonly>
|
|
258
|
+
</div>
|
|
259
|
+
|
|
260
|
+
<div class="col-md-4">
|
|
261
|
+
<label for="mesVencimento" class="form-label">Mês de vencimento
|
|
262
|
+
<code data-bs-toggle="tooltip" data-bs-placement="top" title="(String - 'MM')"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16">
|
|
263
|
+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
|
|
264
|
+
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/>
|
|
265
|
+
</svg>
|
|
266
|
+
</code>
|
|
267
|
+
</label>
|
|
268
|
+
<select class="form-select" name="mesVencimento" id="mesVencimento">
|
|
269
|
+
<option selected>01</option>
|
|
270
|
+
<option>02</option>
|
|
271
|
+
<option>03</option>
|
|
272
|
+
<option>04</option>
|
|
273
|
+
<option>05</option>
|
|
274
|
+
<option>06</option>
|
|
275
|
+
<option>07</option>
|
|
276
|
+
<option>08</option>
|
|
277
|
+
<option>09</option>
|
|
278
|
+
<option>10</option>
|
|
279
|
+
<option>11</option>
|
|
280
|
+
<option>12</option>
|
|
281
|
+
</select>
|
|
282
|
+
</div>
|
|
283
|
+
|
|
284
|
+
<div class="col-md-4">
|
|
285
|
+
<label for="anoVencimento" class="form-label">Ano de vencimento
|
|
286
|
+
<code data-bs-toggle="tooltip" data-bs-placement="top" title="(String - 'YYYY')">
|
|
287
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16">
|
|
288
|
+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
|
|
289
|
+
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/>
|
|
290
|
+
</svg>
|
|
291
|
+
</code>
|
|
292
|
+
</label>
|
|
293
|
+
<select class="form-select" name="anoVencimento" id="anoVencimento">
|
|
294
|
+
<option>2023</option>
|
|
295
|
+
<option>2024</option>
|
|
296
|
+
<option selected>2025</option>
|
|
297
|
+
<option>2026</option>
|
|
298
|
+
<option>2027</option>
|
|
299
|
+
<option>2028</option>
|
|
300
|
+
<option>2029</option>
|
|
301
|
+
<option>2030</option>
|
|
302
|
+
<option>2031</option>
|
|
303
|
+
<option>2032</option>
|
|
304
|
+
<option>2033</option>
|
|
305
|
+
<option>2034</option>
|
|
306
|
+
<option>2035</option>
|
|
307
|
+
</select>
|
|
308
|
+
</div>
|
|
309
|
+
|
|
310
|
+
<div class="col-md-4">
|
|
311
|
+
<label for="cvv" class="form-label">Código de segurança (cvv)
|
|
312
|
+
<code data-bs-toggle="tooltip" data-bs-placement="top" title="(String - '123')">
|
|
313
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16">
|
|
314
|
+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
|
|
315
|
+
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/>
|
|
316
|
+
</svg>
|
|
317
|
+
</code>
|
|
318
|
+
</label>
|
|
319
|
+
<input type="text" class="form-control" name="cvv" id="cvv">
|
|
320
|
+
</div>
|
|
321
|
+
|
|
322
|
+
<div class="col-md-12">
|
|
323
|
+
<label for="opcoesParcelamento" class="form-label">Opções de parcelamento
|
|
324
|
+
<code data-bs-toggle="tooltip" data-bs-placement="top"
|
|
325
|
+
title="Obtida quando definida a bandeira">
|
|
326
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16">
|
|
327
|
+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
|
|
328
|
+
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/>
|
|
329
|
+
</svg>
|
|
330
|
+
</code>
|
|
331
|
+
</label>
|
|
332
|
+
<select class="form-select" id="opcoesParcelamento" name="opcoesParcelamento">
|
|
333
|
+
<option value="0">Digite o número do cartão</option>
|
|
334
|
+
</select>
|
|
335
|
+
</div>
|
|
336
|
+
</div>
|
|
337
|
+
<!-- Fim - Inputs com informações do cartão de crédito -->
|
|
338
|
+
|
|
339
|
+
<hr>
|
|
340
|
+
|
|
341
|
+
<!-- Início - Informação de parcelamento e botão para acionar a geração do payment_token -->
|
|
342
|
+
<div class="row g-3">
|
|
343
|
+
<div class="col-md-12">
|
|
344
|
+
<button class="w-100 btn btn-primary btn-lg disabled" id="gerarPaymentToken" type="button">Gerar
|
|
345
|
+
Payment Token</button>
|
|
346
|
+
</div>
|
|
347
|
+
</div>
|
|
348
|
+
<!-- Fim - Informação de parcelamento e botão para acionar a geração do payment_token -->
|
|
349
|
+
|
|
350
|
+
<hr>
|
|
351
|
+
|
|
352
|
+
<h4 class="mb-3">Resultado <code data-bs-toggle="tooltip" data-bs-placement="top"
|
|
353
|
+
title="Obtidas após execução das funções acionadas pelo botão">
|
|
354
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16">
|
|
355
|
+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
|
|
356
|
+
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/>
|
|
357
|
+
</svg>
|
|
358
|
+
</code>
|
|
359
|
+
</h4>
|
|
360
|
+
<div class="row g-3">
|
|
361
|
+
<div class="col-md-6"> <!-- Input que receberá o payment_token gerado -->
|
|
362
|
+
<label for="paymentToken" class="form-label">Payment Token <code data-bs-toggle="tooltip"
|
|
363
|
+
data-bs-placement="top" title="payment_token gerado para ambiente de homologação">
|
|
364
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16">
|
|
365
|
+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
|
|
366
|
+
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/>
|
|
367
|
+
</svg></label>
|
|
368
|
+
</code>
|
|
369
|
+
<input type="text" class="form-control" name="paymentToken" id="paymentToken" readonly>
|
|
370
|
+
</div>
|
|
371
|
+
|
|
372
|
+
<div class="col-md-6"> <!-- Input que receberá o card_mask gerado -->
|
|
373
|
+
<label for="mascaraCartao" class="form-label">Máscara do cartão</label>
|
|
374
|
+
<input type="text" class="form-control" name="mascaraCartao" id="mascaraCartao" readonly>
|
|
375
|
+
</div>
|
|
376
|
+
</div>
|
|
377
|
+
|
|
378
|
+
<br>
|
|
379
|
+
</form>
|
|
380
|
+
</main>
|
|
381
|
+
</body>
|
|
382
|
+
|
|
383
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-token-efi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Módulo Javascript que permite a criptografia dos dados do cartão do cartão a partir do browser do cliente para gerar o payment_token e identificar a bandeira do cartão.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"API",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"access": "public",
|
|
15
15
|
"registry": "https://registry.npmjs.org/"
|
|
16
16
|
},
|
|
17
|
-
"author": "
|
|
17
|
+
"author": "Consultoria Tecnica Efí | Guilherme Cota",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
20
|
"url": "https://github.com/efipay/js-payment-token-efi.git"
|
|
@@ -22,14 +22,10 @@
|
|
|
22
22
|
"bugs": {
|
|
23
23
|
"url": "https://github.com/efipay/js-payment-token-efi/issues"
|
|
24
24
|
},
|
|
25
|
-
"homepage": "https://dev.
|
|
26
|
-
"main": "
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"license": "MIT",
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"jsdom": "^22.1.0"
|
|
34
|
-
}
|
|
25
|
+
"homepage": "https://dev.efipay.com.br/docs/api-cobrancas/cartao/#obten%C3%A7%C3%A3o-do-payment_token",
|
|
26
|
+
"main": "dist/payment-token-efi-cjs.min.js",
|
|
27
|
+
"module": "dist/payment-token-efi-esm.min.js",
|
|
28
|
+
"browser": "dist/payment-token-efi-umd.min.js",
|
|
29
|
+
"types": "types/payment-token-efi.d.ts",
|
|
30
|
+
"license": "MIT"
|
|
35
31
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
declare module "payment-token-efi" {
|
|
2
|
+
export namespace EfiJs {
|
|
3
|
+
namespace CreditCard {
|
|
4
|
+
function setEnvironment(environment: "production" | "sandbox"): typeof CreditCard;
|
|
5
|
+
function setCardNumber(cardNumber: string): typeof CreditCard;
|
|
6
|
+
function verifyCardBrand(): Promise<string>;
|
|
7
|
+
function setAccount(accountIdentifier: string): typeof CreditCard;
|
|
8
|
+
function setBrand(brand: string): typeof CreditCard;
|
|
9
|
+
function setTotal(total: number): typeof CreditCard;
|
|
10
|
+
function getInstallments(): Promise<InstallmentsResponse | ErrorResponse>;
|
|
11
|
+
function setCreditCardData(data: CreditCardData): typeof CreditCard;
|
|
12
|
+
function getPaymentToken(): Promise<PaymentTokenResponse | ErrorResponse>;
|
|
13
|
+
|
|
14
|
+
interface Installment {
|
|
15
|
+
installment: number;
|
|
16
|
+
has_interest: boolean;
|
|
17
|
+
value: number;
|
|
18
|
+
currency: string;
|
|
19
|
+
interest_percentage: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface InstallmentsResponse {
|
|
23
|
+
rate: number;
|
|
24
|
+
name: string;
|
|
25
|
+
installments: Installment[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ErrorResponse {
|
|
29
|
+
code: string;
|
|
30
|
+
error: string;
|
|
31
|
+
error_description: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface CreditCardData {
|
|
35
|
+
brand: string;
|
|
36
|
+
number: string;
|
|
37
|
+
cvv: string;
|
|
38
|
+
expirationMonth: string;
|
|
39
|
+
expirationYear: string;
|
|
40
|
+
reuse: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface PaymentTokenResponse {
|
|
44
|
+
payment_token: string;
|
|
45
|
+
card_mask: string;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|