11using System ;
22using System . Collections . Generic ;
3+ using System . Linq ;
34using System . Text ;
45using Adyen . Constants ;
56using Adyen . Model . ApplicationInformation ;
@@ -15,7 +16,14 @@ public class SaleToAcquirerDataTest
1516 private readonly string json =
1617 "{\" metadata\" :{\" key\" :\" value\" },\" shopperEmail\" :\" [email protected] \" ,\" shopperReference\" :\" 13164308\" ,\" recurringProcessingModel\" :\" Subscription\" ,\" recurringContract\" :\" RECURRING,ONECLICK\" ,\" shopperStatement\" :\" YOUR SHOPPER STATEMENT\" ,\" recurringDetailName\" :\" VALUE\" ,\" recurringTokenService\" :\" VALUE\" ,\" store\" :\" store value\" ,\" scc\" :null,\" merchantAccount\" :\" merchantAccount\" ,\" currency\" :\" EUR\" ,\" applicationInfo\" :{\" adyenLibrary\" :{\" name\" :\" adyen-dotnet-api-library\" ,\" version\" :\" " + 1718 ClientConfig . LibVersion +
18- "\" },\" externalPlatform\" :{\" integrator\" :\" externalPlatformIntegrator\" ,\" name\" :\" externalPlatformName\" ,\" version\" :\" 2.0.0\" },\" merchantDevice\" :{\" os\" :\" merchantDeviceOS\" ,\" osVersion\" :\" 10.12.6\" ,\" reference\" :\" 4c32759faaa7\" }},\" tenderOption\" :\" ReceiptHandler,AllowPartialAuthorisation,AskGratuity\" ,\" authorisationType\" :\" PreAuth\" ,\" additionalData\" :{\" key.key\" :\" value\" ,\" key.keyTwo\" :\" value2\" },\" split\" :null,\" operatorID\" :\" 1\" ,\" shiftNumber\" :\" 2\" }" ;
19+ "\" },\" externalPlatform\" :{\" integrator\" :\" externalPlatformIntegrator\" ,\" name\" :\" externalPlatformName\" ,\" version\" :\" 2.0.0\" },\" merchantDevice\" :{\" os\" :\" merchantDeviceOS\" ,\" osVersion\" :\" 10.12.6\" ,\" reference\" :\" 4c32759faaa7\" }},\" tenderOption\" :\" ReceiptHandler,AllowPartialAuthorisation,AskGratuity\" ,\" authorisationType\" :\" PreAuth\" ,\" additionalData\" :{\" key.key\" :\" value\" ,\" key.keyTwo\" :\" value2\" }}" ;
20+
21+
22+ private readonly string splitJson =
23+ "{\" metadata\" :{\" key\" :\" value\" },\" shopperEmail\" :\" [email protected] \" ,\" shopperReference\" :\" 13164308\" ,\" recurringProcessingModel\" :\" Subscription\" ,\" recurringContract\" :\" RECURRING,ONECLICK\" ,\" shopperStatement\" :\" YOUR SHOPPER STATEMENT\" ,\" recurringDetailName\" :\" VALUE\" ,\" recurringTokenService\" :\" VALUE\" ,\" store\" :\" store value\" ,\" scc\" :null,\" merchantAccount\" :\" merchantAccount\" ,\" currency\" :\" EUR\" ,\" applicationInfo\" :{\" adyenLibrary\" :{\" name\" :\" adyen-dotnet-api-library\" ,\" version\" :\" " + 24+ ClientConfig . LibVersion +
25+ "\" },\" externalPlatform\" :{\" integrator\" :\" externalPlatformIntegrator\" ,\" name\" :\" externalPlatformName\" ,\" version\" :\" 2.0.0\" },\" merchantDevice\" :{\" os\" :\" merchantDeviceOS\" ,\" osVersion\" :\" 10.12.6\" ,\" reference\" :\" 4c32759faaa7\" }},\" tenderOption\" :\" ReceiptHandler,AllowPartialAuthorisation,AskGratuity\" ,\" authorisationType\" :\" PreAuth\" ," +
26+ "\" additionalData\" :{\" key.key\" :\" value\" ,\" key.keyTwo\" :\" value2\" ,\" split.api\" :\" 1\" ,\" split.nrOfItems\" :\" 3\" ,\" split.totalAmount\" :\" 62000\" ,\" split.currencyCode\" :\" EUR\" ,\" split.item1.amount\" :\" 60000\" ,\" split.item1.type\" :\" BalanceAccount\" ,\" split.item1.account\" :\" BA00000000000000000000001\" ,\" split.item1.reference\" :\" reference_split_1\" ,\" split.item1.description\" :\" description_split_1\" ,\" split.item2.amount\" :\" 2000\" ,\" split.item2.type\" :\" Commission\" ,\" split.item2.reference\" :\" reference_commission\" ,\" split.item2.description\" :\" description_commission\" ,\" split.item3.type\" :\" PaymentFee\" ,\" split.item3.account\" :\" BA00000000000000000000001\" ,\" split.item3.reference\" :\" reference_PaymentFee\" ,\" split.item3.description\" :\" description_PaymentFee\" }}" ;
1927
2028 [ TestMethod ]
2129 public void SerializationTest ( )
@@ -34,9 +42,7 @@ public void SerializationTest()
3442 Ssc = null ,
3543 MerchantAccount = "merchantAccount" ,
3644 Currency = "EUR" ,
37- AuthorisationType = "PreAuth" ,
38- ShiftNumber = "2" ,
39- OperatorID = "1"
45+ AuthorisationType = "PreAuth"
4046 } ;
4147
4248 var applicationInfo = new ApplicationInfo ( ) ;
@@ -82,9 +88,7 @@ public void ToBase64Test()
8288 Ssc = null ,
8389 MerchantAccount = "merchantAccount" ,
8490 Currency = "EUR" ,
85- AuthorisationType = "PreAuth" ,
86- ShiftNumber = "2" ,
87- OperatorID = "1"
91+ AuthorisationType = "PreAuth"
8892 } ;
8993
9094 var applicationInfo = new ApplicationInfo ( ) ;
@@ -109,8 +113,246 @@ public void ToBase64Test()
109113 saleToAcquirerData . AdditionalData = new Dictionary < string , string > { { "key.key" , "value" } , { "key.keyTwo" , "value2" } } ;
110114
111115 string actual = Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( json ) ) ;
116+ Assert . AreEqual ( saleToAcquirerData . ToBase64 ( ) , actual ) ;
117+ }
118+
119+ [ TestMethod ]
120+ public void SplitToBase64Test ( )
121+ {
122+ SaleToAcquirerData saleToAcquirerData = new SaleToAcquirerData
123+ {
124+ Metadata = new SortedDictionary < string , string > { { "key" , "value" } } ,
125+ ShopperEmail = "[email protected] " , 126+ ShopperReference = "13164308" ,
127+ RecurringContract = "RECURRING,ONECLICK" ,
128+ ShopperStatement = "YOUR SHOPPER STATEMENT" ,
129+ RecurringDetailName = "VALUE" ,
130+ RecurringTokenService = "VALUE" ,
131+ RecurringProcessingModel = "Subscription" ,
132+ Store = "store value" ,
133+ Ssc = null ,
134+ MerchantAccount = "merchantAccount" ,
135+ Currency = "EUR" ,
136+ AuthorisationType = "PreAuth"
137+ } ;
138+
139+ var applicationInfo = new ApplicationInfo ( ) ;
140+ var externalPlatform = new ExternalPlatform
141+ {
142+ Integrator = "externalPlatformIntegrator" ,
143+ Name = "externalPlatformName" ,
144+ Version = "2.0.0"
145+ } ;
146+ applicationInfo . ExternalPlatform = externalPlatform ;
147+
148+ var merchantDevice = new MerchantDevice
149+ {
150+ Os = "merchantDeviceOS" ,
151+ OsVersion = "10.12.6" ,
152+ Reference = "4c32759faaa7"
153+ } ;
154+ applicationInfo . MerchantDevice = merchantDevice ;
155+
156+ saleToAcquirerData . ApplicationInfo = applicationInfo ;
157+ saleToAcquirerData . TenderOption = "ReceiptHandler,AllowPartialAuthorisation,AskGratuity" ;
158+ saleToAcquirerData . AdditionalData = new Dictionary < string , string > { { "key.key" , "value" } , { "key.keyTwo" , "value2" } } ;
159+
160+ var splitItem1 = new SplitItem
161+ {
162+ Amount = 60000 ,
163+ Type = SplitItemType . BalanceAccount ,
164+ Account = "BA00000000000000000000001" ,
165+ Reference = "reference_split_1" ,
166+ Description = "description_split_1"
167+ } ;
168+
169+ var splitItem2 = new SplitItem
170+ {
171+ Amount = 2000 ,
172+ Type = SplitItemType . Commission ,
173+ Account = "" ,
174+ Reference = "reference_commission" ,
175+ Description = "description_commission"
176+ } ;
177+
178+ var splitItem3 = new SplitItem
179+ {
180+ Type = SplitItemType . PaymentFee ,
181+ Account = "BA00000000000000000000001" ,
182+ Reference = "reference_PaymentFee" ,
183+ Description = "description_PaymentFee"
184+ } ;
185+
186+ var split = new Split
187+ {
188+ Api = 1 ,
189+ TotalAmount = 62000 ,
190+ CurrencyCode = "EUR" ,
191+ NrOfItems = 3 ,
192+ Items = new List < SplitItem > { splitItem1 , splitItem2 , splitItem3 }
193+ } ;
112194
195+ saleToAcquirerData . AddSplitToAdditionalData ( split ) ;
196+ string actual = Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( splitJson ) ) ;
113197 Assert . AreEqual ( saleToAcquirerData . ToBase64 ( ) , actual ) ;
114198 }
199+
200+ [ TestMethod ]
201+ public void ConvertToQueryString_EmptyItemsList_ReturnsQueryString ( )
202+ {
203+ var expected = new Dictionary < string , string >
204+ {
205+ { "split.api" , "1" } ,
206+ { "split.nrOfItems" , "0" } ,
207+ { "split.totalAmount" , "62000" } ,
208+ { "split.currencyCode" , "EUR" }
209+ } ;
210+
211+ var split = new Split
212+ {
213+ Api = 1 ,
214+ TotalAmount = 62000 ,
215+ CurrencyCode = "EUR" ,
216+ NrOfItems = 0 ,
217+ Items = new List < SplitItem > ( )
218+ } ;
219+
220+ Dictionary < string , string > actual = new SaleToAcquirerData ( ) . AddSplitToAdditionalData ( split ) ;
221+ CollectionAssert . AreEqual ( expected , actual ) ;
222+ }
223+
224+ [ TestMethod ]
225+ public void ConvertToQueryString_SingleItemList_ReturnsQueryString ( )
226+ {
227+ var expected = new Dictionary < string , string >
228+ {
229+ { "split.api" , "1" } ,
230+ { "split.nrOfItems" , "1" } ,
231+ { "split.totalAmount" , "62000" } ,
232+ { "split.currencyCode" , "EUR" } ,
233+ { "split.item1.amount" , "60000" } ,
234+ { "split.item1.type" , "BalanceAccount" } ,
235+ { "split.item1.account" , "BA00000000000000000000001" } ,
236+ { "split.item1.reference" , "reference_split_1" } ,
237+ { "split.item1.description" , "description_split_1" }
238+ } ;
239+
240+ var split = new Split
241+ {
242+ Api = 1 ,
243+ TotalAmount = 62000 ,
244+ CurrencyCode = "EUR" ,
245+ NrOfItems = 1 ,
246+ Items = new List < SplitItem >
247+ {
248+ new SplitItem
249+ {
250+ Amount = 60000 ,
251+ Type = SplitItemType . BalanceAccount ,
252+ Account = "BA00000000000000000000001" ,
253+ Reference = "reference_split_1" ,
254+ Description = "description_split_1"
255+ }
256+ }
257+ } ;
258+
259+ Dictionary < string , string > actual = new SaleToAcquirerData ( ) . AddSplitToAdditionalData ( split ) ;
260+ CollectionAssert . AreEqual ( expected , actual ) ;
261+ }
262+
263+ [ TestMethod ]
264+ public void ConvertToQueryString_SingleItemWithNullValues_ShouldNotIncludeNullProperties ( )
265+ {
266+ var expected = new Dictionary < string , string >
267+ {
268+ { "split.api" , "1" } ,
269+ { "split.nrOfItems" , "1" } ,
270+ { "split.totalAmount" , "62000" } ,
271+ { "split.currencyCode" , "EUR" } ,
272+ { "split.item1.type" , "Commission" } ,
273+ { "split.item1.reference" , "reference_split_1" }
274+ } ;
275+
276+ var split = new Split
277+ {
278+ Api = 1 ,
279+ TotalAmount = 62000 ,
280+ CurrencyCode = "EUR" ,
281+ NrOfItems = 1 ,
282+ Items = new List < SplitItem >
283+ {
284+ new SplitItem
285+ {
286+ Amount = null , // No Amount
287+ Type = SplitItemType . Commission ,
288+ Account = null , // No Account
289+ Reference = "reference_split_1" ,
290+ Description = null // No Description
291+ }
292+ }
293+ } ;
294+
295+ Dictionary < string , string > actual = new SaleToAcquirerData ( ) . AddSplitToAdditionalData ( split ) ;
296+ CollectionAssert . AreEqual ( expected , actual ) ;
297+ }
298+
299+ [ TestMethod ]
300+ public void ConvertToQueryString_MultipleItemsList_ReturnsQueryString ( )
301+ {
302+ var expected = new Dictionary < string , string >
303+ {
304+ { "split.api" , "1" } ,
305+ { "split.nrOfItems" , "3" } ,
306+ { "split.totalAmount" , "62000" } ,
307+ { "split.currencyCode" , "EUR" } ,
308+ { "split.item1.amount" , "60000" } ,
309+ { "split.item1.type" , "BalanceAccount" } ,
310+ { "split.item1.account" , "BA00000000000000000000001" } ,
311+ { "split.item1.reference" , "reference_split_1" } ,
312+ { "split.item1.description" , "description_split_1" } ,
313+ { "split.item2.amount" , "2000" } ,
314+ { "split.item2.type" , "Commission" } ,
315+ { "split.item2.reference" , "reference_commission" } ,
316+ { "split.item2.description" , "description_commission" } ,
317+ { "split.item3.type" , "PaymentFee" } ,
318+ { "split.item3.reference" , "reference_PaymentFee" } ,
319+ { "split.item3.description" , "description_PaymentFee" }
320+ } ;
321+
322+ var split = new Split
323+ {
324+ Api = 1 ,
325+ TotalAmount = 62000 ,
326+ CurrencyCode = "EUR" ,
327+ NrOfItems = 3 ,
328+ Items = new List < SplitItem >
329+ {
330+ new SplitItem
331+ {
332+ Amount = 60000 ,
333+ Type = SplitItemType . BalanceAccount ,
334+ Account = "BA00000000000000000000001" ,
335+ Reference = "reference_split_1" ,
336+ Description = "description_split_1"
337+ } ,
338+ new SplitItem
339+ {
340+ Amount = 2000 ,
341+ Type = SplitItemType . Commission ,
342+ Reference = "reference_commission" ,
343+ Description = "description_commission"
344+ } ,
345+ new SplitItem
346+ {
347+ Type = SplitItemType . PaymentFee ,
348+ Reference = "reference_PaymentFee" ,
349+ Description = "description_PaymentFee"
350+ }
351+ }
352+ } ;
353+
354+ Dictionary < string , string > actual = new SaleToAcquirerData ( ) . AddSplitToAdditionalData ( split ) ;
355+ CollectionAssert . AreEqual ( expected , actual ) ;
356+ }
115357 }
116358}
0 commit comments