Skip to content

Commit 6ab966e

Browse files
committed
Merge pull request #1 from safeguard-apis/v2
V2
2 parents aa7dea2 + 0e9db41 commit 6ab966e

16 files changed

+644
-66
lines changed

README.md

+158-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,158 @@
1-
safeguard-api-net
2-
=================
1+
# safeguard-api-net
2+
3+
## V1
4+
5+
6+
## V1.2
7+
8+
9+
## V2.0
10+
11+
### Métodos:
12+
* ValidateOTP
13+
* ValidateTransactionToken
14+
* AnalyzeRisk
15+
* IssueLocators
16+
* NotifyFailure
17+
18+
19+
### Obs:
20+
Todos os métodos lançam uma exceção (SafeGuardExcption) contendo um código de erro e uma mensagem, caso o HTTP code retornado pelo SafeGuard seja diferente de 200
21+
22+
### ValidateOtp
23+
24+
Faz a validação do token digitado pelo usuário
25+
26+
```c#
27+
public bool ValidateOtp(string transactionToken, string otp, string device_type);
28+
```
29+
30+
### ValidateTransactionToken
31+
32+
Verifica se a transactionToken é válida
33+
34+
```c#
35+
public bool ValidateTransactionToken(string transactionToken);
36+
```
37+
38+
39+
### AnalyzeRisk
40+
41+
Analisa o grau de risco de uma lista de localizadores
42+
43+
44+
```c#
45+
public List<Risk> AnalyzeRisk(List<Locator> locators, string transactionToken);
46+
```
47+
48+
#### Exemplo de uso
49+
50+
51+
52+
```c#
53+
//Instancia a API
54+
SafeGuardServerAPIV2.SafeGuardClient sg = new SafeGuardServerAPIV2.SafeGuardClient(transactionToken, "SAFEGUARD_URL");
55+
56+
//Criação de um localizador
57+
Locator loc = new Locator("LOC1", false);
58+
59+
//Criação de um ticket
60+
Ticket ticket = new Ticket("123321", new DateTime(), "MR PAX", 100, "BLR");
61+
ticket.AddFlightGroup("SAO", "RJ", new DateTime(), new DateTime());
62+
63+
//Criação de um Cartão
64+
CreditCardInfo card = new CreditCardInfo("teste", "12312312312");
65+
ticket.AddPayment(card, 100.00);//Adição de uma forma de pagamento
66+
67+
loc.AddTicket(ticket);//Adição do ticket no localizador
68+
69+
//Lista de localizadores
70+
List<Locator> locators = new List<Locator>();
71+
locators.Add(loc);
72+
73+
//Análise de risco dos localizadores
74+
List<Risk> risks = sg.AnalyzeRisk(locators, transactionToken);
75+
```
76+
77+
78+
### IssueLocators
79+
80+
Informa ao Safeguard a emissãp de uma lista de localizadores
81+
82+
83+
```c#
84+
public List<Risk> IssueLocators(List<Locator> locators, string transactionToken);
85+
```
86+
87+
#### Exemplo de uso
88+
89+
90+
```c#
91+
//Instancia a API
92+
SafeGuardServerAPIV2.SafeGuardClient sg = new SafeGuardServerAPIV2.SafeGuardClient(transactionToken, "SAFEGUARD_URL");
93+
94+
//Criação de um localizador
95+
Locator loc = new Locator("LOC1", false);
96+
97+
//Criação de um ticket
98+
Ticket ticket = new Ticket("123321", new DateTime(), "MR PAX", 100, "BLR");
99+
ticket.AddFlightGroup("SAO", "RJ", new DateTime(), new DateTime());
100+
101+
//Criação de um Cartão
102+
CreditCardInfo card = new CreditCardInfo("teste", "12312312312");
103+
ticket.AddPayment(card);//Adição de uma forma de pagamento
104+
105+
loc.AddTicket(ticket);//Adição do ticket no localizador
106+
107+
//Lista de localizadores
108+
List<Locator> locators = new List<Locator>();
109+
locators.Add(loc);
110+
111+
//Análise de risco dos localizadores
112+
List<Risk> risks = sg.IssueLocators(locators, transactionToken);
113+
```
114+
115+
### NotifyFailure
116+
117+
Notifica o Safeguard falhas de emissão
118+
119+
```c#
120+
public bool NotifyFailure(string transactionToken, List<LocatorFailure> failures);
121+
```
122+
123+
124+
#### Exemplo de Uso:
125+
```c#
126+
SafeGuardServerAPIV2.SafeGuardClient sg = new SafeGuardServerAPIV2.SafeGuardClient(transactionToken, "SAFEGUARD_URL");
127+
128+
//Criação de Falha
129+
List<LocatorFailure> failures = new List<LocatorFailure>();
130+
failures.Add(new LocatorFailure("LOC121", "Error"));
131+
132+
Boolean resp = sg.NotifyFailure(transactionToken, failures);
133+
```
134+
135+
O Objeto LocatorFailure também aceita um Locator no seu construtor:
136+
137+
```c#
138+
SafeGuardServerAPIV2.SafeGuardClient sg = new SafeGuardServerAPIV2.SafeGuardClient(transactionToken, "SAFEGUARD_URL");
139+
140+
//Criação de um localizador
141+
Locator loc = new Locator("LOC1", false);
142+
143+
//Criação de um ticket
144+
Ticket ticket = new Ticket("123321", new DateTime(), "MR PAX", 100, "BLR");
145+
ticket.AddFlightGroup("SAO", "RJ", new DateTime(), new DateTime());
146+
147+
//Criação de um Cartão
148+
CreditCardInfo card = new CreditCardInfo("teste", "12312312312");
149+
ticket.AddPayment(card);//Adição de uma forma de pagamento
150+
151+
loc.AddTicket(ticket);//Adição do ticket no localizador
152+
153+
//Criação de Falha
154+
List<LocatorFailure> failures = new List<LocatorFailure>();
155+
failures.Add(new LocatorFailure(loc, "Error"));
156+
157+
Boolean resp = sg.NotifyFailure(transactionToken, failures);
158+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Runtime.Serialization;
6+
7+
namespace SafeGuardServerAPIV2
8+
{
9+
[DataContract(Name = "info")]
10+
public class CreditCardInfo
11+
{
12+
public CreditCardInfo(String Name, String Number) {
13+
this.Name = Name;
14+
this.Number = Number;
15+
}
16+
17+
[DataMember(Name = "name")]
18+
String Name { set; get; }
19+
20+
[DataMember(Name = "number")]
21+
String Number { set; get; }
22+
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Runtime.Serialization;
6+
7+
namespace SafeGuardServerAPIV2
8+
{
9+
[DataContract(Name = "flight_group")]
10+
public class FlightGroup
11+
{
12+
public FlightGroup(String Origin, String Destination, DateTime DepartureAt, DateTime ArrivalAt) {
13+
this.Origin = Origin;
14+
this.Destination = Destination;
15+
this.DepartureAt = DepartureAt;
16+
this.ArrivalAt = ArrivalAt;
17+
}
18+
19+
[DataMember(Name = "destination")]
20+
String Destination { set; get; }
21+
22+
[DataMember(Name = "origin")]
23+
String Origin { set; get; }
24+
25+
[DataMember(Name = "departure_at")]
26+
private String DepartureAtSerializable { set; get; }
27+
28+
DateTime DepartureAt { set; get; }
29+
30+
[DataMember(Name = "arrival_at")]
31+
private String ArrivalAtSerializable { set; get; }
32+
33+
DateTime ArrivalAt { set; get; }
34+
35+
36+
[OnSerializing]
37+
void OnSerializing(StreamingContext context)
38+
{
39+
this.DepartureAtSerializable = this.DepartureAt.ToString("yyyy/MM/dd HH:mm:ss zzz");
40+
this.ArrivalAtSerializable = this.ArrivalAt.ToString("yyyy/MM/dd HH:mm:ss zzz");
41+
}
42+
43+
}
44+
45+
46+
}

SafeGuardServer.NetAPI/SafeGuardServerAPI/Locator.cs

+14-33
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,37 @@
44
using System.Text;
55
using System.Runtime.Serialization;
66

7-
namespace SafeGuardServerAPI
7+
namespace SafeGuardServerAPIV2
88
{
99
[DataContract(Name = "locator")]
1010
public class Locator
1111
{
12-
public Locator(String locator, String source, String destination, String origin, DateTime departureAt, DateTime arrivalAt, Boolean isInternational, List<Ticket> tickets)
12+
public Locator(String locator, Boolean isInternational, List<Ticket> tickets)
1313
{
1414
this.Loc = locator;
15-
this.Source = source;
16-
this.Destination = destination;
17-
this.Origin = origin;
18-
this.DepartureAt = departureAt;
19-
this.ArrivalAt = arrivalAt;
2015
this.IsInternational = isInternational;
2116
this.Tickets = tickets;
2217
}
2318

24-
[DataMember(Name = "loc")]
25-
String Loc{set; get;}
26-
27-
[DataMember(Name = "source")]
28-
String Source{set; get;}
29-
30-
[DataMember(Name = "destination")]
31-
String Destination { set; get; }
32-
33-
[DataMember(Name = "origin")]
34-
String Origin { set; get; }
35-
36-
[DataMember(Name = "departure_at")]
37-
private String DepartureAtSerializable { set; get; }
38-
39-
DateTime DepartureAt { set; get; }
19+
public Locator(String locator, Boolean isInternational)
20+
{
21+
this.Loc = locator;
22+
this.IsInternational = isInternational;
23+
this.Tickets = new List<Ticket>();
24+
}
4025

41-
[DataMember(Name = "arrival_at")]
42-
private String ArrivalAtSerializable { set; get; }
26+
public void AddTicket(Ticket ticket) {
27+
this.Tickets.Add(ticket);
28+
}
4329

44-
DateTime ArrivalAt { set; get; }
30+
[DataMember(Name = "loc")]
31+
String Loc{set; get;}
4532

4633
[DataMember(Name = "is_international")]
4734
Boolean IsInternational { set; get; }
4835

49-
[DataMember(Name = "tickets_attributes")]
36+
[DataMember(Name = "tickets")]
5037
List<Ticket> Tickets { set; get; }
5138

52-
[OnSerializing]
53-
void OnSerializing(StreamingContext context)
54-
{
55-
this.DepartureAtSerializable = this.DepartureAt.ToString("yyyy/MM/dd HH:mm:ss zzz");
56-
this.ArrivalAtSerializable = this.ArrivalAt.ToString("yyyy/MM/dd HH:mm:ss zzz");
57-
}
5839
}
5940
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Runtime.Serialization;
6+
7+
namespace SafeGuardServerAPIV2
8+
{
9+
[DataContract(Name = "errors")]
10+
public class LocatorFailure
11+
{
12+
public enum Failures { PAYMENT = 1, EXPIRED = 2, UNKNOWN = 99}
13+
14+
public LocatorFailure(String locId, String errorMessage) {
15+
this.Loc = locId;
16+
this.ErrorMessage = errorMessage;
17+
this.ErrorCode = Failures.UNKNOWN;
18+
}
19+
20+
public LocatorFailure(String locId, String errorMessage, Failures failureCode)
21+
{
22+
this.Loc = locId;
23+
this.ErrorMessage = errorMessage;
24+
this.ErrorCode = failureCode;
25+
}
26+
27+
public LocatorFailure(Locator locator, String errorMessage)
28+
{
29+
this.locator = locator;
30+
this.ErrorMessage = errorMessage;
31+
this.ErrorCode = Failures.UNKNOWN;
32+
}
33+
34+
public LocatorFailure(Locator locator, String errorMessage, Failures failureCode)
35+
{
36+
this.locator = locator;
37+
this.ErrorMessage = errorMessage;
38+
this.ErrorCode = failureCode;
39+
}
40+
41+
[DataMember(Name = "loc")]
42+
String Loc { set; get; }
43+
44+
[DataMember(Name = "locator")]
45+
Locator locator { set; get; }
46+
47+
[DataMember(Name = "error_message")]
48+
String ErrorMessage { set; get; }
49+
50+
51+
[DataMember(Name = "error_code")]
52+
Failures ErrorCode { set; get; }
53+
}
54+
}
Binary file not shown.

0 commit comments

Comments
 (0)