-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode_test.go
More file actions
784 lines (770 loc) · 27.7 KB
/
Copy pathdecode_test.go
File metadata and controls
784 lines (770 loc) · 27.7 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
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
package khqr
import (
"errors"
"testing"
)
func TestDecode(t *testing.T) {
t.Parallel()
tests := []struct {
name string
qr string
want DecodedData
}{
// --- Basic cases ---
{
"individual",
"00020101021229190015john_smith@devb52045999530311654065000.05802KH5910jonh smith6010Phnom Penh62360109#INV-20030313Coffee Klaing0702#299170013161302797275763049ACF",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
TransactionCurrency: "116",
MerchantName: "jonh smith",
TransactionAmount: "5000.0",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
BillNumber: "#INV-2003",
StoreLabel: "Coffee Klaing",
TerminalLabel: "#2",
CreationTimestamp: "1613027972757",
CRC: "9ACF",
},
},
{
"merchant",
"00020101021230410015john_smith@devb01061234560208Dev Bank52045999530384054035.05802KH5916john smith actor6010Phnom Penh62130709Counter 299170013161343857579463048EF2",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantID: "123456",
AcquiringBank: "Dev Bank",
MerchantType: Merchant,
TransactionCurrency: "840",
MerchantName: "john smith actor",
TransactionAmount: "5.0",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
TerminalLabel: "Counter 2",
CreationTimestamp: "1613438575794",
CRC: "8EF2",
},
},
{
"merchant_with_bill_and_terminal",
"00020101021230410015john_smith@devb01061234560208Dev Bank52045999530384054035.05802KH5916john smith actor6010Phnom Penh62280111Invoice#0690709Counter 29917001316134385758926304384E",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantID: "123456",
AcquiringBank: "Dev Bank",
MerchantType: Merchant,
TransactionCurrency: "840",
MerchantName: "john smith actor",
TransactionAmount: "5.0",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
BillNumber: "Invoice#069",
TerminalLabel: "Counter 2",
CreationTimestamp: "1613438575892",
CRC: "384E",
},
},
{
"merchant_with_bill_only",
"00020101021230410015john_smith@devb01061234560208Dev Bank52045999530384054035.05802KH5916john smith actor6010Phnom Penh62150111Invoice#0699917001316134385758926304552D",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantID: "123456",
AcquiringBank: "Dev Bank",
MerchantType: Merchant,
TransactionCurrency: "840",
MerchantName: "john smith actor",
TransactionAmount: "5.0",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
BillNumber: "Invoice#069",
CreationTimestamp: "1613438575892",
CRC: "552D",
},
},
// --- Non-standard EMV / bank-specific ---
{
"non_standard_emv",
"000201010211021641277800000000980416518352888000006030470016abaakhppxxx@abaa01153166007701102420204abaa5204224253038405802KH5910USD OUTLET6010PHNOM PENH62250509115B02750070827CE19809924001339CA026411FDA6803mmp63043870",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "11",
BakongAccountID: "abaakhppxxx@abaa",
MerchantID: "316600770110242",
AcquiringBank: "abaa",
MerchantType: Merchant,
TransactionCurrency: "840",
MerchantName: "USD OUTLET",
MerchantCategoryCode: "2242",
CountryCode: "KH",
MerchantCity: "PHNOM PENH",
TerminalLabel: "27CE1980",
CreationTimestamp: "39CA026411FDA",
CRC: "3870",
},
},
{
"acleda_with_language",
"00020101021130470009khqr@aclb0111855124649170215ACLEDA Bank Plc5204599953038405802KH5907BUN MAO6010Phnom Penh6102126213020901050033164310002KM0107BUN MAO0210Phnom Penh6304E313",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "11",
BakongAccountID: "khqr@aclb",
MerchantID: "85512464917",
AcquiringBank: "ACLEDA Bank Plc",
MerchantType: Merchant,
TransactionCurrency: "840",
MerchantName: "BUN MAO",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
MobileNumber: "010500331",
CRC: "E313",
AltLanguagePreference: "KM",
AltMerchantName: "BUN MAO",
AltMerchantCity: "Phnom Penh",
},
},
{
"acleda_with_language_v2",
"00020101021130640009khqr@aclb0111855124649060215ACLEDA Bank Plc051385500000019425204593153038405802KH5912KHQR TESTING6010Phnom Penh6102126213020901753577164360002KM0112KHQR TESTING0210Phnom Penh6304AC1C",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "11",
BakongAccountID: "khqr@aclb",
MerchantID: "85512464906",
AcquiringBank: "ACLEDA Bank Plc",
MerchantType: Merchant,
TransactionCurrency: "840",
MerchantName: "KHQR TESTING",
MerchantCategoryCode: "5931",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
MobileNumber: "017535771",
CRC: "AC1C",
AltLanguagePreference: "KM",
AltMerchantName: "KHQR TESTING",
AltMerchantCity: "Phnom Penh",
},
},
{
"individual_all_fields",
"00020101021229310014jonhsmith@nbcq0109012345678520459995303116540750000.05802KH5910Jonh Smith6009Siam Reap62550117INV-2021-07-658220211855123456780305BKK-1070601234599170013163039583850263041134",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "jonhsmith@nbcq",
AccountInfo: "012345678",
MerchantType: Individual,
TransactionCurrency: "116",
MerchantName: "Jonh Smith",
TransactionAmount: "50000.0",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Siam Reap",
BillNumber: "INV-2021-07-65822",
StoreLabel: "BKK-1",
TerminalLabel: "012345",
MobileNumber: "85512345678",
CreationTimestamp: "1630395838502",
CRC: "1134",
},
},
// --- Minimal / edge cases ---
{
"crc_only",
"63041234",
DecodedData{
CRC: "1234",
},
},
{
"merchant_tags_reordered",
"00020101021230410015john_smith@devb01061234560208Dev Bank53038405204599954035.05802KH5916john smith actor6010Phnom Penh62150111Invoice#06999170013161343857589263040437",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantID: "123456",
AcquiringBank: "Dev Bank",
MerchantType: Merchant,
TransactionCurrency: "840",
MerchantName: "john smith actor",
TransactionAmount: "5.0",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
BillNumber: "Invoice#069",
CreationTimestamp: "1613438575892",
CRC: "0437",
},
},
{
"no_merchant_account",
"00020101021252045999530384054035.05802KH5916john smith actor6010Phnom Penh62150111Invoice#06999170013161343857589263042494",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
TransactionCurrency: "840",
MerchantName: "john smith actor",
TransactionAmount: "5.0",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
BillNumber: "Invoice#069",
CreationTimestamp: "1613438575892",
CRC: "2494",
},
},
{
"merchant_account_id_only",
"000201010212301900151234567890123456304D807",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "123456789012345",
MerchantType: Merchant,
CRC: "D807",
},
},
{
"long_account_id",
"00020101021230440040123456789012345678901234567890123456789063041747",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "1234567890123456789012345678901234567890",
MerchantType: Merchant,
CRC: "1747",
},
},
{
"pfi_too_long",
"000301001021230190015john_smith@devb630493FD",
DecodedData{
PayloadFormatIndicator: "010",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Merchant,
CRC: "93FD",
},
},
// --- Missing / invalid field tests ---
{
"missing_pfi",
"01021230190015john_smith@devb52045999530384054035.05802KH5916john smith actor6010Phnom Penh62150111Invoice#06999170013161343857589263044598",
DecodedData{
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Merchant,
TransactionCurrency: "840",
MerchantName: "john smith actor",
TransactionAmount: "5.0",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
BillNumber: "Invoice#069",
CreationTimestamp: "1613438575892",
CRC: "4598",
},
},
{
"poi_too_long",
"000201010312330190015john_smith@devb63040FC8",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "123",
BakongAccountID: "john_smith@devb",
MerchantType: Merchant,
CRC: "0FC8",
},
},
{
"mcc_three_digits",
"00020101021229190015john_smith@devb5203999630454EF",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
MerchantCategoryCode: "999",
CRC: "54EF",
},
},
{
"individual_no_mcc",
"00020101021229190015john_smith@devb530384054035.05802KH5916john smith actor6010Phnom Penh62150111Invoice#0699917001316134385758926304F926",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
TransactionCurrency: "840",
MerchantName: "john smith actor",
TransactionAmount: "5.0",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
BillNumber: "Invoice#069",
CreationTimestamp: "1613438575892",
CRC: "F926",
},
},
{
"currency_too_long",
"00020101021229190015john_smith@devb52045999530488406304FEA6",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
MerchantCategoryCode: "5999",
TransactionCurrency: "8840",
CRC: "FEA6",
},
},
{
"individual_no_currency",
"00020101021229190015john_smith@devb5204599954035.05802KH5916john smith actor6010Phnom Penh62150111Invoice#0699917001316134385758926304E7DF",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
MerchantCategoryCode: "5999",
TransactionAmount: "5.0",
CountryCode: "KH",
MerchantName: "john smith actor",
MerchantCity: "Phnom Penh",
BillNumber: "Invoice#069",
CreationTimestamp: "1613438575892",
CRC: "E7DF",
},
},
{
"country_code_too_long",
"00020101021229190015john_smith@devb52045999530384054035.05803KKH63042FD2",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
MerchantCategoryCode: "5999",
TransactionCurrency: "840",
TransactionAmount: "5.0",
CountryCode: "KKH",
CRC: "2FD2",
},
},
{
"no_country_code",
"00020101021229190015john_smith@devb52045999530384054035.05916john smith actor6010Phnom Penh62150111Invoice#06999170013161343857589263040023",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
MerchantCategoryCode: "5999",
TransactionCurrency: "840",
TransactionAmount: "5.0",
MerchantName: "john smith actor",
MerchantCity: "Phnom Penh",
BillNumber: "Invoice#069",
CreationTimestamp: "1613438575892",
CRC: "0023",
},
},
{
"city_too_long",
"00020101021229190015john_smith@devb52045999530384054035.05802KH5916john smith actor60170123456789012345663040EF3",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
MerchantCategoryCode: "5999",
TransactionCurrency: "840",
TransactionAmount: "5.0",
CountryCode: "KH",
MerchantName: "john smith actor",
MerchantCity: "01234567890123456",
CRC: "0EF3",
},
},
{
"empty_city",
"00020101021229190015john_smith@devb52045999530384054035.05802KH5916john smith actor600062150111Invoice#0699917001316134385758926304389D",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
MerchantCategoryCode: "5999",
TransactionCurrency: "840",
TransactionAmount: "5.0",
CountryCode: "KH",
MerchantName: "john smith actor",
BillNumber: "Invoice#069",
CreationTimestamp: "1613438575892",
CRC: "389D",
},
},
{
"no_city",
"00020101021229190015john_smith@devb52045999530384054035.05802KH5916john smith actor62150111Invoice#06999170013161343857589263043B26",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
MerchantCategoryCode: "5999",
TransactionCurrency: "840",
TransactionAmount: "5.0",
CountryCode: "KH",
MerchantName: "john smith actor",
BillNumber: "Invoice#069",
CreationTimestamp: "1613438575892",
CRC: "3B26",
},
},
{
"long_merchant_name",
"00020101021229190015john_smith@devb52045999530384054035.05802KH59307PL7EvxHpgpP4jT4uMgegaYqgv3Ehb6010Phnom Penh6304399D",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
MerchantCategoryCode: "5999",
TransactionCurrency: "840",
TransactionAmount: "5.0",
CountryCode: "KH",
MerchantName: "7PL7EvxHpgpP4jT4uMgegaYqgv3Ehb",
MerchantCity: "Phnom Penh",
CRC: "399D",
},
},
{
"empty_merchant_name",
"00020101021229190015john_smith@devb52045999530384054035.05802KH59006010Phnom Penh630414A7",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
MerchantCategoryCode: "5999",
TransactionCurrency: "840",
TransactionAmount: "5.0",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
CRC: "14A7",
},
},
{
"no_merchant_name",
"00020101021229190015john_smith@devb52045999530384054035.05802KH6010Phnom Penh62150111Invoice#06999170013161343857589263043518",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
MerchantCategoryCode: "5999",
TransactionCurrency: "840",
TransactionAmount: "5.0",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
BillNumber: "Invoice#069",
CreationTimestamp: "1613438575892",
CRC: "3518",
},
},
// --- Empty optional fields ---
{
"empty_bill_number",
"00020101021229190015john_smith@devb52045999530311654065000.05802KH5910jonh smith6010Phnom Penh622701000313Coffee Klaing0702#29917001316130279727576304D219",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
TransactionCurrency: "116",
MerchantName: "jonh smith",
TransactionAmount: "5000.0",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
StoreLabel: "Coffee Klaing",
TerminalLabel: "#2",
CreationTimestamp: "1613027972757",
CRC: "D219",
},
},
{
"empty_store_label",
"00020101021229190015john_smith@devb52045999530311654065000.05802KH5910jonh smith6010Phnom Penh62230109#INV-200303000702#299170013161302797275763049BD2",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
TransactionCurrency: "116",
MerchantName: "jonh smith",
TransactionAmount: "5000.0",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
BillNumber: "#INV-2003",
TerminalLabel: "#2",
CreationTimestamp: "1613027972757",
CRC: "9BD2",
},
},
{
"empty_terminal_label",
"00020101021229190015john_smith@devb52045999530311654065000.05802KH5910jonh smith6010Phnom Penh62340109#INV-20030313Coffee Klaing07009917001316130279727576304F593",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
TransactionCurrency: "116",
MerchantName: "jonh smith",
TransactionAmount: "5000.0",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
BillNumber: "#INV-2003",
StoreLabel: "Coffee Klaing",
CreationTimestamp: "1613027972757",
CRC: "F593",
},
},
{
"unsupported_currency",
"00020101021229190015john_smith@devb52045999530384954035.05802KH5916john smith actor6010Phnom Penh9917001316134385758926304951E",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
MerchantCategoryCode: "5999",
TransactionCurrency: "849",
TransactionAmount: "5.0",
CountryCode: "KH",
MerchantName: "john smith actor",
MerchantCity: "Phnom Penh",
CreationTimestamp: "1613438575892",
CRC: "951E",
},
},
// --- Tags not in order ---
{
"tags_not_in_order",
"00020101021130580016cznbkhppxxx@cznb01061007310224KB Kookmin Bank Cambodia5204599953031165802KH6010PHNOM PENH5912Le Pure Cafe62400107#1007310312Le Pure Cafe0709KHM10073199170013163047617398663048FDD",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "11",
BakongAccountID: "cznbkhppxxx@cznb",
MerchantID: "100731",
AcquiringBank: "KB Kookmin Bank Cambodia",
MerchantType: Merchant,
TransactionCurrency: "116",
MerchantName: "Le Pure Cafe",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "PHNOM PENH",
BillNumber: "#100731",
StoreLabel: "Le Pure Cafe",
TerminalLabel: "KHM100731",
CreationTimestamp: "1630476173986",
CRC: "8FDD",
},
},
{
"acleda_khr_with_language",
"00020101021130640009khqr@aclb0111855124649060215ACLEDA Bank Plc051385500000019435204593153031165802KH5912KHQR TESTING6010Phnom Penh6102126213020901753577164360002KM0112KHQR TESTING0210Phnom Penh63045451",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "11",
BakongAccountID: "khqr@aclb",
MerchantID: "85512464906",
AcquiringBank: "ACLEDA Bank Plc",
MerchantType: Merchant,
TransactionCurrency: "116",
MerchantName: "KHQR TESTING",
MerchantCategoryCode: "5931",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
MobileNumber: "017535771",
CRC: "5451",
AltLanguagePreference: "KM",
AltMerchantName: "KHQR TESTING",
AltMerchantCity: "Phnom Penh",
},
},
// --- Purpose and UPI ---
{
"individual_with_purpose",
"00020101021129180014jonhsmith@nbcq5204599953031165802KH5910Jonh Smith6010Phnom Penh62260211855123456780807Testing99170013168733590258463047929",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "11",
BakongAccountID: "jonhsmith@nbcq",
MerchantType: Individual,
TransactionCurrency: "116",
MerchantName: "Jonh Smith",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
MobileNumber: "85512345678",
Purpose: "Testing",
CreationTimestamp: "1687335902584",
CRC: "7929",
},
},
{
"individual_with_upi",
"00020101021115231234567812345678901234529180014jonhsmith@nbcq5204599953031165802KH5910Jonh Smith6010Phnom Penh9917001316873161811616304E2DC",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "11",
UPIAccountInfo: "12345678123456789012345",
BakongAccountID: "jonhsmith@nbcq",
MerchantType: Individual,
TransactionCurrency: "116",
MerchantName: "Jonh Smith",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
CreationTimestamp: "1687316181161",
CRC: "E2DC",
},
},
// --- Full fields with Khmer ---
{
"individual_khmer_full_fields",
"00020101021229460015john_smith@devb0111855122334550208Dev Bank52045999530384054031005802KH5910John Smith6010PHNOM PENH62670106#123450211855122334550311Coffee Shop0709Cashier_10810Buy coffee64280002km0108ចន ស្មីន0206ភ្នំពញ993400131726821915797011317268220357976304B73E",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
AccountInfo: "85512233455",
AcquiringBank: "Dev Bank",
MerchantType: Individual,
TransactionCurrency: "840",
MerchantName: "John Smith",
TransactionAmount: "100",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "PHNOM PENH",
BillNumber: "#12345",
MobileNumber: "85512233455",
StoreLabel: "Coffee Shop",
TerminalLabel: "Cashier_1",
Purpose: "Buy coffee",
AltLanguagePreference: "km",
AltMerchantName: "ចន ស្មីន",
AltMerchantCity: "ភ្នំពញ",
CreationTimestamp: "1726821915797",
ExpirationTimestamp: "1726822035797",
CRC: "B73E",
},
},
{
"merchant_khmer_full_fields",
"00020101021230350009khqr@devb01061234560208Dev Bank52045999530384054031005802KH5910John Smith6010PHNOM PENH62670106#123450211855122334550311Coffee Shop0709Cashier_10810Buy coffee64280002km0108ចន ស្មីន0206ភ្នំពញ993400131726822962612011317268230826126304A560",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "khqr@devb",
MerchantID: "123456",
AcquiringBank: "Dev Bank",
MerchantType: Merchant,
TransactionCurrency: "840",
MerchantName: "John Smith",
TransactionAmount: "100",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "PHNOM PENH",
BillNumber: "#12345",
MobileNumber: "85512233455",
StoreLabel: "Coffee Shop",
TerminalLabel: "Cashier_1",
Purpose: "Buy coffee",
AltLanguagePreference: "km",
AltMerchantName: "ចន ស្មីន",
AltMerchantCity: "ភ្នំពញ",
CreationTimestamp: "1726822962612",
ExpirationTimestamp: "1726823082612",
CRC: "A560",
},
},
// --- Lenient CRC ---
{
"lenient_crc",
"00020101021229190015john_smith@devb52045999530311654065000.05802KH5910jonh smith6010Phnom Penh62360109#INV-20030313Coffee Klaing0702#29917001316130279727576304FFFF",
DecodedData{
PayloadFormatIndicator: "01",
PointOfInitiationMethod: "12",
BakongAccountID: "john_smith@devb",
MerchantType: Individual,
TransactionCurrency: "116",
MerchantName: "jonh smith",
TransactionAmount: "5000.0",
MerchantCategoryCode: "5999",
CountryCode: "KH",
MerchantCity: "Phnom Penh",
BillNumber: "#INV-2003",
StoreLabel: "Coffee Klaing",
TerminalLabel: "#2",
CreationTimestamp: "1613027972757",
CRC: "FFFF",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := Decode(tt.qr)
if err != nil {
t.Fatalf("Decode() error = %v", err)
}
if *got != tt.want {
t.Errorf("Decode() mismatch\ngot: %+v\nwant: %+v", *got, tt.want)
}
})
}
}
func TestDecodeInvalid(t *testing.T) {
t.Parallel()
tests := []struct {
name string
qr string
}{
{"too_short", "EAB3"},
{"truncated", "00020101021230190015"},
{"malformed_tlv", "10263041234"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
_, err := Decode(tt.qr)
if !errors.Is(err, ErrInvalidQR) {
t.Errorf("Decode(%q) error = %v, want ErrInvalidQR", tt.qr, err)
}
})
}
}