@validapay/tokenize 1.0.3
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/index.js +34 -0
- package/package.json +24 -0
package/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const DEFAULT_API_URL = "https://api.validapay.com.br";
|
|
2
|
+
|
|
3
|
+
export async function tokenize({ apiUrl = DEFAULT_API_URL, token, card, customer }) {
|
|
4
|
+
if (!token) throw new Error("token é obrigatório");
|
|
5
|
+
if (!card?.number) throw new Error("card.number é obrigatório");
|
|
6
|
+
if (!card?.name) throw new Error("card.name é obrigatório");
|
|
7
|
+
if (!card?.cvv) throw new Error("card.cvv é obrigatório");
|
|
8
|
+
if (!card?.expiration) throw new Error("card.expiration é obrigatório");
|
|
9
|
+
if (!customer?.document) throw new Error("customer.document é obrigatório");
|
|
10
|
+
if (!customer?.name) throw new Error("customer.name é obrigatório");
|
|
11
|
+
if (!customer?.email) throw new Error("customer.email é obrigatório");
|
|
12
|
+
|
|
13
|
+
const res = await fetch(`${apiUrl}/v1/payment-methods/tokenize`, {
|
|
14
|
+
method: "POST",
|
|
15
|
+
headers: {
|
|
16
|
+
"Content-Type": "application/json",
|
|
17
|
+
"Authorization": `Bearer ${token}`,
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify({
|
|
20
|
+
name: card.name,
|
|
21
|
+
number: card.number,
|
|
22
|
+
cvv: card.cvv,
|
|
23
|
+
expiration: card.expiration,
|
|
24
|
+
customer,
|
|
25
|
+
}),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (!res.ok) {
|
|
29
|
+
const error = await res.json().catch(() => ({ message: res.statusText }));
|
|
30
|
+
throw new Error(error?.message || "Erro ao tokenizar cartão");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return res.json();
|
|
34
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@validapay/tokenize",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "SDK de tokenização de cartão ValidaPay",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"index.js"
|
|
12
|
+
],
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"validapay",
|
|
18
|
+
"tokenize",
|
|
19
|
+
"cartao",
|
|
20
|
+
"pagamento",
|
|
21
|
+
"sdk"
|
|
22
|
+
],
|
|
23
|
+
"license": "MIT"
|
|
24
|
+
}
|