-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy patheRede.java
More file actions
90 lines (67 loc) · 3.4 KB
/
eRede.java
File metadata and controls
90 lines (67 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package br.com.userede.erede;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.logging.Logger;
import br.com.userede.erede.service.CancelTransactionService;
import br.com.userede.erede.service.CaptureTransactionService;
import br.com.userede.erede.service.CreateTransactionService;
import br.com.userede.erede.service.GetTransactionService;
public class eRede {
public static final String VERSION = "1.1.0";
public static final String ARTIFACT_ID = "br.com.userede.erede";
public static final String USER_AGENT = "eRede/" + eRede.VERSION + " (Java; %s)";
private final Store store;
private final Logger logger;
public eRede(Store store) {
this(store, Logger.getLogger(eRede.ARTIFACT_ID));
}
public eRede(Store store, Logger logger) {
this.store = store;
this.logger = logger;
}
public TransactionResponse authorize(Transaction transaction) throws URISyntaxException, IOException {
return create(transaction);
}
public TransactionResponse create(Transaction transaction) throws URISyntaxException, IOException {
CreateTransactionService createTransactionService = new CreateTransactionService(store,
transaction, logger);
createTransactionService.setUserAgent(String.format(eRede.USER_AGENT, store.getFiliation()));
return createTransactionService.execute();
}
public TransactionResponse cancel(Transaction transaction) throws IOException, URISyntaxException {
CancelTransactionService cancelTransactionService = new CancelTransactionService(store,
transaction, logger);
cancelTransactionService.setUserAgent(String.format(eRede.USER_AGENT, store.getFiliation()));
return cancelTransactionService.execute();
}
public TransactionResponse capture(Transaction transaction) throws IOException, URISyntaxException {
CaptureTransactionService captureTransactionService = new CaptureTransactionService(store,
transaction, logger);
captureTransactionService.setUserAgent(String.format(eRede.USER_AGENT, store.getFiliation()));
return captureTransactionService.execute();
}
public TransactionResponse get(String tid) throws IOException, URISyntaxException {
GetTransactionService getTransactionService = new GetTransactionService(store, null, logger);
getTransactionService.setTid(tid);
getTransactionService.setUserAgent(String.format(eRede.USER_AGENT, store.getFiliation()));
return getTransactionService.execute();
}
public TransactionResponse getByReference(String reference) throws IOException, URISyntaxException {
GetTransactionService getTransactionService = new GetTransactionService(store, null, logger);
getTransactionService.setReference(reference);
getTransactionService.setUserAgent(String.format(eRede.USER_AGENT, store.getFiliation()));
return getTransactionService.execute();
}
public TransactionResponse getRefunds(String tid) throws IOException, URISyntaxException {
GetTransactionService getTransactionService = new GetTransactionService(store, null, logger);
getTransactionService.setTid(tid);
getTransactionService.setRefund(true);
getTransactionService.setUserAgent(String.format(eRede.USER_AGENT, store.getFiliation()));
return getTransactionService.execute();
}
public TransactionResponse zero(Transaction transaction) throws Exception {
transaction.setAmount(0);
transaction.capture();
return create(transaction);
}
}