10
10
namespace Ticket . PayMethod
11
11
{
12
12
public class MundiPaggClient
13
- {
14
- public Action < PaymentMessage > OnCreated ;
15
- public Action < PaymentMessage > OnError ;
13
+ {
16
14
private GatewayServiceClient _serviceClient ;
17
15
18
16
public MundiPaggClient ( )
19
17
{
20
- var key = new Guid ( "5e62ba71-73d4-4ca0-8c03-26d1f78d6c71" ) ;
21
- const string link = "https://sandbox.mundipaggone.com" ;
18
+ // var key = new Guid("5e62ba71-73d4-4ca0-8c03-26d1f78d6c71");
19
+ // const string link = "https://sandbox.mundipaggone.com";
22
20
// Creates the client that will send the transaction.
23
- _serviceClient = new GatewayServiceClient ( key , new Uri ( link ) ) ;
21
+ _serviceClient = new GatewayServiceClient ( ) ;
24
22
}
25
23
26
- public void Pay ( IOrder order , params ICreditCard [ ] cards )
24
+ public IEnumerable < PaymentMessage > Pay ( IOrder order , params ICreditCard [ ] cards )
27
25
{
28
26
var transictions = new Collection < CreditCardTransaction > ( Generate ( order , cards )
29
27
. ToArray ( ) ) ;
@@ -50,44 +48,28 @@ public void Pay(IOrder order, params ICreditCard[] cards)
50
48
InstantBuyKey = creditCardTransaction . CreditCard . InstantBuyKey
51
49
52
50
} ) ;
51
+ return feedBack . ToArray ( ) ;
53
52
54
- foreach ( var msg in feedBack )
55
- {
56
- if ( OnCreated != null )
57
- OnCreated ( msg ) ;
58
- }
59
- break ;
60
- }
61
- case HttpStatusCode . InternalServerError :
62
- {
63
- InternalServerError ( ) ;
64
- break ;
65
53
}
54
+
66
55
default :
67
56
{
68
- Error ( createSaleResponse , ( int ) httpResponse . HttpStatusCode , order ) ;
69
- break ;
57
+ var payments = createSaleResponse . ErrorReport
58
+ . ErrorItemCollection
59
+ . Select ( errorItem => new PaymentMessage ( )
60
+ {
61
+ Message = errorItem . Description ,
62
+ StatusCode = ( int ) httpResponse . HttpStatusCode ,
63
+ MessageCode = errorItem . ErrorCode ,
64
+ Email = order . UserEmail
65
+ } )
66
+ . ToArray ( ) ;
67
+ return payments ;
70
68
}
71
69
}
72
70
73
71
}
74
72
75
- private void Error ( CreateSaleResponse createSaleResponse , int statusCode , IOrder order )
76
- {
77
- if ( OnError == null || createSaleResponse . ErrorReport == null ) return ;
78
- var payments =
79
- createSaleResponse . ErrorReport . ErrorItemCollection
80
- . Select ( errorItem => new PaymentMessage ( )
81
- {
82
- Message = errorItem . Description ,
83
- StatusCode = statusCode ,
84
- MessageCode = errorItem . ErrorCode ,
85
- Email = order . UserEmail
86
- } ) . ToArray ( ) ;
87
-
88
- foreach ( var msg in payments )
89
- OnError ( msg ) ;
90
- }
91
73
92
74
private IEnumerable < CreditCardTransaction > Generate ( IOrder order , ICreditCard [ ] cards )
93
75
{
@@ -109,7 +91,7 @@ private IEnumerable<CreditCardTransaction> Generate(IOrder order, ICreditCard[]
109
91
InstantBuyKey = card . InstantBuyKey . Value
110
92
} ;
111
93
yield return transaction ;
112
- continue ;
94
+ continue ;
113
95
}
114
96
transaction . CreditCard = card . Copiar < ICreditCard , CreditCard > ( ) ;
115
97
Contract . Assert ( card . CreditCardBrand . HasValue ) ;
0 commit comments