-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.go
99 lines (81 loc) · 3.48 KB
/
main.go
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
package main
import (
"log"
"github.com/dongri/emv-qrcode/emv/cpm"
"github.com/dongri/emv-qrcode/emv/mpm"
)
func main() {
// MPM Encode
emvqr := new(mpm.EMVQR)
emvqr.SetPayloadFormatIndicator("01")
emvqr.SetPointOfInitiationMethod("12") // 11 is static qrcode
merchantAccountInformationJCB := new(mpm.MerchantAccountInformation)
merchantAccountInformationJCB.SetGloballyUniqueIdentifier("D123456")
merchantAccountInformationJCB.AddPaymentNetworkSpecific("13", "JCB1234567890")
emvqr.AddMerchantAccountInformation(mpm.ID("29"), merchantAccountInformationJCB)
merchantAccountInformationMaster := new(mpm.MerchantAccountInformation)
merchantAccountInformationMaster.SetGloballyUniqueIdentifier("M123456")
merchantAccountInformationMaster.AddPaymentNetworkSpecific("04", "MASTER1234567890")
emvqr.AddMerchantAccountInformation(mpm.ID("31"), merchantAccountInformationMaster)
emvqr.SetMerchantCategoryCode("5311")
emvqr.SetTransactionCurrency("392")
emvqr.SetTransactionAmount("999.123")
emvqr.SetCountryCode("JP")
emvqr.SetMerchantName("DONGRI")
emvqr.SetMerchantCity("TOKYO")
additionalTemplate := new(mpm.AdditionalDataFieldTemplate)
additionalTemplate.SetBillNumber("hoge")
additionalTemplate.SetReferenceLabel("fuga")
additionalTemplate.SetTerminalLabel("piyo")
emvqr.SetAdditionalDataFieldTemplate(additionalTemplate)
code, err := mpm.Encode(emvqr)
if err != nil {
log.Println(err.Error())
return
}
log.Println(code) // 0002010102121313JCB12345678900416MASTER12345678905204531153033925407999.1235802JP5906DONGRI6005TOKYO62240104hoge0504fuga0704piyo6304C343
// MPM Decode
emvqr, err = mpm.Decode("00020101021229300012D156000000000510A93FO3230Q31280012D15600000001030812345678520441115802CN5914BEST TRANSPORT6007BEIJING64200002ZH0104最佳运输0202北京540523.7253031565502016233030412340603***0708A60086670902ME91320016A0112233449988770708123456786304A13A")
if err != nil {
log.Println(err)
return
}
log.Println(emvqr)
// Print Raw Data
raw := emvqr.RawData()
log.Println("\n" + raw)
// Print Binary Data
binary := emvqr.BinaryData()
log.Println("\n" + binary)
// Print JSON
json := emvqr.JSON()
log.Println(json)
// CPM
qr := new(cpm.EMVQR)
qr.DataPayloadFormatIndicator = "CPV01"
appTemplate1 := new(cpm.ApplicationTemplate)
appTemplate1.DataApplicationDefinitionFileName = "A0000000555555"
appTemplate1.DataApplicationLabel = "Product1"
qr.ApplicationTemplates = append(qr.ApplicationTemplates, *appTemplate1)
appTemplate2 := new(cpm.ApplicationTemplate)
appTemplate2.DataApplicationDefinitionFileName = "A0000000666666"
appTemplate2.DataApplicationLabel = "Product2"
qr.ApplicationTemplates = append(qr.ApplicationTemplates, *appTemplate2)
cdt := new(cpm.CommonDataTemplate)
cdt.DataApplicationPAN = "1234567890123458"
cdt.DataCardholderName = "CARDHOLDER/EMV"
cdt.DataLanguagePreference = "ruesdeen"
cdtt := new(cpm.CommonDataTransparentTemplate)
cdtt.DataIssuerApplicationData = "06010A03000000"
cdtt.DataApplicationCryptogram = "584FD385FA234BCC"
cdtt.DataApplicationTransactionCounter = "0001"
cdtt.DataUnpredictableNumber = "6D58EF13"
cdt.CommonDataTransparentTemplates = append(cdt.CommonDataTransparentTemplates, *cdtt)
qr.CommonDataTemplates = append(qr.CommonDataTemplates, *cdt)
comQRCode, err := qr.GeneratePayload()
if err != nil {
log.Println(err)
}
log.Println(comQRCode)
// hQVDUFYwMWETTwegAAAAVVVVUAhQcm9kdWN0MWETTwegAAAAZmZmUAhQcm9kdWN0MmJJWggSNFZ4kBI0WF8gDkNBUkRIT0xERVIvRU1WXy0IcnVlc2RlZW5kIZ8QBwYBCgMAAACfJghYT9OF+iNLzJ82AgABnzcEbVjvEw==
}