Skip to content

Commit 52a295b

Browse files
author
João Batista Neto
committed
SDK Node
0 parents  commit 52a295b

24 files changed

+583
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
node_modules/
3+
package-lock.json

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.git*

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Rede
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SDK Node.js
2+
3+
SDK de integração eRede
4+
5+
# Utilizando
6+
7+
## Autorizando uma transação
8+
9+
```js
10+
const eRede = require("../");
11+
const Transaction = require("./transaction");
12+
13+
let transaction = new Transaction(10, "123").creditCard(
14+
"2102102102102100",
15+
"123",
16+
"11",
17+
"20",
18+
"Fulano de tal"
19+
);
20+
21+
new eRede("pv", "token").create(transaction);
22+
23+
if (transaction.returnCode === "00") {
24+
console.log(`Transação autorizada com sucesso: ${transaction.tid}`);
25+
}
26+
```
27+
28+
Por padrão, a transação é capturada automaticamente; caso seja necessário apenas autorizar a transação, o método `Transaction.capture()` deverá ser chamado com o parâmetro `false`:
29+
30+
```js
31+
const eRede = require("../");
32+
const Transaction = require("./transaction");
33+
34+
let transaction = new Transaction(10, "123").creditCard(
35+
"2102102102102100",
36+
"123",
37+
"11",
38+
"20",
39+
"Fulano de tal"
40+
).autoCapture(false);
41+
42+
new eRede("pv", "token").create(transaction);
43+
44+
if (transaction.returnCode === "00") {
45+
console.log(`Transação autorizada com sucesso: ${transaction.tid}`);
46+
}
47+
```

lib/address.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use strict";
2+
3+
module.exports = class Address {
4+
static get BILLING() {
5+
return 1;
6+
}
7+
8+
static get SHIPPING() {
9+
return 2;
10+
}
11+
12+
static get BOTH() {
13+
return 3;
14+
}
15+
16+
static get APARTMENT() {
17+
return 1;
18+
}
19+
20+
static get HOUSE() {
21+
return 2;
22+
}
23+
24+
static get COMMERCIAL() {
25+
return 3;
26+
}
27+
28+
static get OTHER() {
29+
return 4;
30+
}
31+
};

lib/antifraud.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
3+
module.exports = class Antifraud {
4+
constructor() {
5+
this.success = false;
6+
}
7+
};

lib/authorization.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
3+
module.exports = class Authorization {
4+
};

lib/capture.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
3+
module.exports = class Capture {
4+
};

lib/cart.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"use strict";
2+
3+
const Address = require("./address");
4+
const Consumer = require("./consumer");
5+
const Iata = require("./iata");
6+
7+
module.exports = class Cart {
8+
address(type = Address.BOTH) {
9+
let address = Address();
10+
11+
if ((type & Address.BILLING) === Address.BILLING) {
12+
this.billing = address;
13+
}
14+
15+
if ((type & Address.SHIPPING) === Address.SHIPPING) {
16+
this.shipping = [address];
17+
}
18+
19+
return address;
20+
}
21+
22+
addItem(item) {
23+
if (this.items === undefined) {
24+
this.items = [];
25+
}
26+
27+
this.items.push(item);
28+
29+
return this;
30+
}
31+
32+
setConsumer(name, email, cpf) {
33+
this.consumer = new Consumer(name, email, cpf);
34+
35+
return this.consumer;
36+
}
37+
38+
setIata(code, departureTax, flight) {
39+
this.iata = new Iata(code, departureTax);
40+
this.iata.flight = flight;
41+
42+
return this;
43+
}
44+
};

lib/consumer.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
3+
const Phone = require("./phone");
4+
5+
module.exports = class Consumer {
6+
constructor(name, email, cpf) {
7+
this.name = name;
8+
this.email = email;
9+
this.cpf = cpf;
10+
}
11+
12+
static get MALE() {
13+
return "M";
14+
}
15+
16+
static get FEMALE() {
17+
return "F";
18+
}
19+
20+
addDocument(type, number) {
21+
if (this.documents === undefined) {
22+
this.documents = [];
23+
}
24+
25+
this.documents.push({type: type, number: number});
26+
27+
return this;
28+
}
29+
30+
setPhone(ddd, number, type = Phone.CELLPHONE) {
31+
this.phone = new Phone(ddd, number, type);
32+
33+
return this;
34+
}
35+
};

0 commit comments

Comments
 (0)