forked from eWAYPayment/eway-rapid-net
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestUtil.cs
336 lines (318 loc) · 13.4 KB
/
TestUtil.cs
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
using System.Collections.Generic;
using System.Linq;
using eWAY.Rapid.Enums;
using eWAY.Rapid.Internals.Models;
using eWAY.Rapid.Internals.Response;
using eWAY.Rapid.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CardDetails = eWAY.Rapid.Models.CardDetails;
using Customer = eWAY.Rapid.Models.Customer;
using LineItem = eWAY.Rapid.Models.LineItem;
using Payment = eWAY.Rapid.Internals.Models.Payment;
using Refund = eWAY.Rapid.Models.Refund;
using VerificationResult = eWAY.Rapid.Internals.Models.VerificationResult;
namespace eWAY.Rapid.Tests
{
public static class TestUtil
{
//Third party Merchant
internal static Transaction CreateTransaction(bool capture, string tokenId = null, bool createToken = false)
{
var result = new Transaction { Capture = capture, SaveCustomer = createToken };
var cardDetails = new CardDetails() { Name = "John Smith", Number = "4444333322221111", ExpiryMonth = "12", ExpiryYear = "25", CVN = "123" };
var address = new Address()
{
Street1 = "Level 5",
Street2 = "369 Queen Street",
City = "Sydney",
State = "NSW",
Country = "au",
PostalCode = "2000",
};
result.Customer = new Customer()
{
Reference = "A12345",
Title = "Mr.",
FirstName = "John",
LastName = "Smith",
CompanyName = "Demo Shop 123",
JobDescription = "Developer",
Phone = "09 889 0986",
Mobile = "09 889 6542",
Email = "[email protected]",
Url = "http://www.ewaypayments.com",
CardDetails = cardDetails,
Address = address,
Comments = "",
Fax = "",
TokenCustomerID = tokenId
};
var shippingAddress = new Address()
{
Street1 = "Level 5",
Street2 = "369 Queen Street",
City = "Sydney",
State = "NSW",
Country = "au",
PostalCode = "2000"
};
result.ShippingDetails = new ShippingDetails()
{
ShippingAddress = shippingAddress,
ShippingMethod = ShippingMethod.NextDay,
Email = "[email protected]",
Fax = "",
FirstName = "John",
LastName = "Smith",
Phone = "09 889 0986"
};
result.LineItems = new[]
{
new LineItem()
{
SKU = "12345678901234567890",
Description = "Item Description 1",
Quantity = 1,
UnitCost = 400
},
new LineItem()
{
SKU = "123456789012",
Description = "Item Description 2",
Quantity = 1,
UnitCost = 400,
}
}.ToList();
result.Options = new[] { "Option1", "Option2" }.ToList();
result.PaymentDetails = new PaymentDetails()
{
TotalAmount = 1000,
InvoiceNumber = "Inv 21540",
InvoiceDescription = "Individual Invoice Description",
InvoiceReference = "513456",
CurrencyCode = "AUD"
};
result.TransactionType = TransactionTypes.Purchase;
result.RedirectURL = "http://www.eway.com.au";
result.DeviceID = "D1234";
result.PartnerID = "ID";
result.CustomerIP = "127.0.0.1";
return result;
}
internal static Transaction CreateTransaction()
{
return CreateTransaction(true);
}
internal static Customer CreateCustomer()
{
var customer = new Customer
{
Title = "Mr.",
FirstName = "John",
LastName = "Smith",
Reference = "A12345",
Address = new Address()
{
Country = "au",
City = "Sydney",
PostalCode = "",
State = "NSW",
Street1 = "Level 5",
Street2 = "369 Queen Street"
},
CardDetails =
new CardDetails()
{
Name = "John Smith",
Number = "4444333322221111",
ExpiryMonth = "12",
ExpiryYear = "25",
CVN = "123"
},
JobDescription = "Developer",
RedirectURL = "http://www.eway.com.au",
Comments = "empty comment",
CompanyName = "Demo Shop 123",
Fax = "",
Mobile = "09 889 0986",
Email = "[email protected]",
Phone = "09 889 6542",
Url = "http://www.ewaypayments.com"
};
return customer;
}
internal static Refund CreateRefund(int transactionId)
{
var result = new Refund
{
PartnerID = "P123",
DeviceID = "D1234",
RefundDetails = new RefundDetails()
{
TotalAmount = 100,
InvoiceNumber = "Inv 21540",
InvoiceDescription = "Individual Invoice Description",
InvoiceReference = "513456",
CurrencyCode = "AUD",
OriginalTransactionID = transactionId
},
Customer = CreateCustomer(),
ShippingDetails = new ShippingDetails()
{
ShippingMethod = ShippingMethod.NextDay,
FirstName = "John",
LastName = "Smith",
Phone = "09 889 0986",
ShippingAddress = new Address()
{
Street1 = "Level 5",
Street2 = "369 Queen Street",
City = "Sydney",
State = "NSW",
Country = "au",
PostalCode = "2000"
}
},
LineItems = new List<LineItem>()
{
new LineItem()
{
SKU = "12345678901234567890",
Description = "Item Description 1",
Quantity = 1,
UnitCost = 400,
Tax = 100,
Total = 500
},
new LineItem()
{
SKU = "123456789012",
Description = "Item Description 2",
Quantity = 1,
UnitCost = 400,
Tax = 100,
Total = 500
}
},
Options = new List<string>()
{
"Option1",
"Option2"
}
};
result.Customer.CardDetails = new CardDetails()
{
ExpiryMonth = "12",
ExpiryYear = "25"
};
return result;
}
internal static DirectPaymentResponse CreateDirectPaymentResponse()
{
return new DirectPaymentResponse()
{
AuthorisationCode = "747774",
ResponseCode = "00",
ResponseMessage = "A2000",
TransactionID = 11735855,
TransactionStatus = true,
TransactionType = "Purchase",
BeagleScore = 0,
Verification = new VerificationResult()
{
CVN = 0,
Address = 0,
Email = 0,
Mobile = 0,
Phone = 0
},
Customer = new DirectTokenCustomer()
{
CardDetails = new Internals.Models.CardDetails()
{
Number = "444433XXXXXX1111",
Name = "John Smith",
ExpiryMonth = "12",
ExpiryYear = "25",
StartMonth = null,
StartYear = null,
IssueNumber = null
},
TokenCustomerID = null,
Reference = "A12345",
Title = "Mr.",
FirstName = "John",
LastName = "Smith",
CompanyName = "Demo Shop 123",
JobDescription = "Developer",
Street1 = "Level 5",
Street2 = "369 Queen Street",
City = "Sydney",
State = "NSW",
PostalCode = "2000",
Country = "au",
Email = "[email protected]",
Phone = "09 889 0986",
Mobile = "09 889 6542",
Comments = "",
Fax = "",
Url = "http://www.ewaypayments.com"
},
Payment = new Payment()
{
TotalAmount = 1000,
InvoiceNumber = "Inv 21540",
InvoiceDescription = "Individual Invoice Description",
InvoiceReference = "513456",
CurrencyCode = "AUD"
},
Errors = null
};
}
//Assertion helpers
internal static void AssertReturnedCustomerData_VerifyAddressAreEqual(Customer responseCustomer, Customer requestCustomer)
{
Assert.AreEqual(responseCustomer.Address.State, requestCustomer.Address.State);
Assert.AreEqual(responseCustomer.Address.City, requestCustomer.Address.City);
Assert.AreEqual(responseCustomer.Address.Country, requestCustomer.Address.Country);
Assert.AreEqual(responseCustomer.Address.PostalCode, requestCustomer.Address.PostalCode);
Assert.AreEqual(responseCustomer.Address.Street1, requestCustomer.Address.Street1);
Assert.AreEqual(responseCustomer.Address.Street2, requestCustomer.Address.Street2);
}
internal static void AssertReturnedCustomerData_VerifyCardDetailsAreEqual(Customer responseCustomer, Customer requestCustomer)
{
if (!string.IsNullOrWhiteSpace(responseCustomer.CardDetails.ExpiryMonth) &&
!string.IsNullOrWhiteSpace(requestCustomer.CardDetails.ExpiryMonth))
Assert.AreEqual(responseCustomer.CardDetails.ExpiryMonth, requestCustomer.CardDetails.ExpiryMonth);
if (!string.IsNullOrWhiteSpace(responseCustomer.CardDetails.ExpiryYear) &&
!string.IsNullOrWhiteSpace(requestCustomer.CardDetails.ExpiryYear))
Assert.AreEqual(responseCustomer.CardDetails.ExpiryYear, requestCustomer.CardDetails.ExpiryYear);
if (!string.IsNullOrWhiteSpace(responseCustomer.CardDetails.IssueNumber) &&
!string.IsNullOrWhiteSpace(requestCustomer.CardDetails.IssueNumber))
Assert.AreEqual(responseCustomer.CardDetails.IssueNumber, requestCustomer.CardDetails.IssueNumber);
if (!string.IsNullOrWhiteSpace(responseCustomer.CardDetails.Name) &&
!string.IsNullOrWhiteSpace(requestCustomer.CardDetails.Name))
Assert.AreEqual(responseCustomer.CardDetails.Name, requestCustomer.CardDetails.Name);
if (!string.IsNullOrWhiteSpace(responseCustomer.CardDetails.StartMonth) &&
!string.IsNullOrWhiteSpace(requestCustomer.CardDetails.StartMonth))
Assert.AreEqual(responseCustomer.CardDetails.StartMonth, requestCustomer.CardDetails.StartMonth);
if (!string.IsNullOrWhiteSpace(responseCustomer.CardDetails.StartYear) &&
!string.IsNullOrWhiteSpace(requestCustomer.CardDetails.StartYear))
Assert.AreEqual(responseCustomer.CardDetails.StartYear, requestCustomer.CardDetails.StartYear);
}
internal static void AssertReturnedCustomerData_VerifyAllFieldsAreEqual(Customer responseCustomer, Customer requestCustomer)
{
Assert.AreEqual(responseCustomer.Comments, requestCustomer.Comments);
Assert.AreEqual(responseCustomer.CompanyName, requestCustomer.CompanyName);
Assert.AreEqual(responseCustomer.Fax, requestCustomer.Fax);
Assert.AreEqual(responseCustomer.FirstName, requestCustomer.FirstName);
Assert.AreEqual(responseCustomer.LastName, requestCustomer.LastName);
Assert.AreEqual(responseCustomer.JobDescription, requestCustomer.JobDescription);
Assert.AreEqual(responseCustomer.Mobile, requestCustomer.Mobile);
Assert.AreEqual(responseCustomer.Phone, requestCustomer.Phone);
Assert.AreEqual(responseCustomer.Reference, requestCustomer.Reference);
Assert.AreEqual(responseCustomer.Title, requestCustomer.Title);
Assert.AreEqual(responseCustomer.Url, requestCustomer.Url);
}
}
}