Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/juanroman/emvqr
Browse files Browse the repository at this point in the history
  • Loading branch information
juanroman committed Aug 20, 2018
2 parents 8fb1939 + 09b6967 commit 8df5827
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 12 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 juanroman
Copyright (c) 2018 Juan Roman Escamilla

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
92 changes: 82 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,93 @@ Value String | Field Reference | Spec ID | Value Length | Spec Value | Explanati
52044111 | Merchant Category Code | "52" | 4 | 4111 | The Merchant Category Code (MCC) shall contain an MCC as defined by **ISO 18245**.
6011Mexico City | Merchant City | "60" | 11 | Mexico City | The Merchant City should indicate the city of the merchant's physical location.

To see the full spec reference please read the specification provided by EMV(R).
To see the full spec reference please read the specification provided by EMV(R) or read it from the [file included](../master/specs/EMVCo-Merchant-Presented-QR-Specification-v1-1.pdf)

In order to create a _dynamic_ qr code with a Transaction Amount you could do the following:
You can also go full fluent. The following example shows most of the fields used with the easier fluent approach:

```csharp
var globalUniqueIdentifier = Guid.NewGuid().ToString().Replace("-", string.Empty);

var merchantPayload = MerchantPayload.CreateDynamic(
globalUniqueIdentifier,
4111,
Iso4217Currency.MexicoPeso.Value.NumericCode,
Iso3166Countries.Mexico,
"My Super Shop",
"Mexico City")
.WithTransactionAmount(100);
var merchantPayload = MerchantPayload
.CreateDynamic(globalUniqueIdentifier, 4111, Iso4217Currency.MexicoPeso.Value.NumericCode, Iso3166Countries.Mexico, "Chocolate Powder", "Mexico City")
.WithAlternateLanguage(Iso639Languages.SpanishCastilian, "Chocolate en Polvo", "CDMX")
.WithTransactionAmount(34.95m)
.WithTipByUser()
.WithAdditionalData(
billNumber: "1234",
mobileNumber: "5512341234",
storeLabel: "The large store",
loyaltyNumber: "A12341234",
referenceLabel: "***",
terminalLabel: "T12341",
purposeOfTransaction: "We do commerce",
additionalConsumerDataRequest: "AME")
.WithUnreservedTemplate(globalUniqueIdentifier, new Dictionary<int, string>
{
{1, "Some value" },
{2, "Another value" }
});

var payload = merchantPayload.GeneratePayload();
```

## Decoding a Merchant-Presented QR
You can easily decode a QR code by using the **FromQR** static constructor. Please note that the data will be validated against the spec automatically.

```csharp
var merchantPayload = MerchantPayload.FromQR(qr);
```

### Sample
The following sample which is included in the Unit Tests shows how to generate the QR data and then decode it back to an object.
```csharp
var globalUniqueIdentifier = Guid.NewGuid().ToString().Replace("-", string.Empty);
var merchantPayload = MerchantPayload
.CreateDynamic(globalUniqueIdentifier, 4111, Iso4217Currency.MexicoPeso.Value.NumericCode, Iso3166Countries.Mexico, "Chocolate Powder", "Mexico City")
.WithAlternateLanguage(Iso639Languages.SpanishCastilian, "Chocolate en Polvo", "CDMX")
.WithTransactionAmount(34.95m)
.WithTipByUser()
.WithAdditionalData(
billNumber: "1234",
mobileNumber: "5512341234",
storeLabel: "The large store",
loyaltyNumber: "A12341234",
referenceLabel: "***",
terminalLabel: "T12341",
purposeOfTransaction: "We do commerce",
additionalConsumerDataRequest: "AME")
.WithUnreservedTemplate(globalUniqueIdentifier, new Dictionary<int, string>
{
{1, "Some value" },
{2, "Another value" }
});
merchantPayload.PostalCode = "12345";

var qr = merchantPayload.GeneratePayload();

merchantPayload = MerchantPayload.FromQR(qr);
Assert.Equal(globalUniqueIdentifier, merchantPayload.MerchantAccountInformation.First().Value.GlobalUniqueIdentifier);
Assert.Equal(4111, merchantPayload.MerchantCategoryCode);
Assert.Equal(Iso4217Currency.MexicoPeso.Value.NumericCode, merchantPayload.TransactionCurrency);
Assert.Equal(Iso3166Countries.Mexico, merchantPayload.CountyCode);
Assert.Equal("Chocolate Powder", merchantPayload.MerchantName);
Assert.Equal("Mexico City", merchantPayload.MerchantCity);
Assert.Equal(Iso639Languages.SpanishCastilian, merchantPayload.MerchantInformation.LanguagePreference);
Assert.Equal("Chocolate en Polvo", merchantPayload.MerchantInformation.MerchantNameAlternateLanguage);
Assert.Equal("CDMX", merchantPayload.MerchantInformation.MerchantCityAlternateLanguage);
Assert.Equal(34.95m, merchantPayload.TransactionAmount);
Assert.Equal(1, merchantPayload.TipOrConvenienceIndicator);
Assert.Equal("1234", merchantPayload.AdditionalData.BillNumber);
Assert.Equal("5512341234", merchantPayload.AdditionalData.MobileNumber);
Assert.Equal("The large store", merchantPayload.AdditionalData.StoreLabel);
Assert.Equal("A12341234", merchantPayload.AdditionalData.LoyaltyNumber);
Assert.Equal("***", merchantPayload.AdditionalData.ReferenceLabel);
Assert.Equal("T12341", merchantPayload.AdditionalData.TerminalLabel);
Assert.Equal("We do commerce", merchantPayload.AdditionalData.PurposeOfTransaction);
Assert.Equal("AME", merchantPayload.AdditionalData.AdditionalConsumerDataRequest);
Assert.Equal(globalUniqueIdentifier, merchantPayload.UnreservedTemplate.First().Value.GlobalUniqueIdentifier);
Assert.Equal("Some value", merchantPayload.UnreservedTemplate.First().Value.ContextSpecificData[1]);
Assert.Equal("Another value", merchantPayload.UnreservedTemplate.First().Value.ContextSpecificData[2]);
Assert.Equal("12345", merchantPayload.PostalCode);
Assert.NotNull(merchantPayload.CRC);
```
2 changes: 1 addition & 1 deletion src/StandardizedQR/StandardizedQR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Description>EMV(R) Compliant Library built in .NET Standard for generating and parsing QR Codes.</Description>
<PackageProjectUrl>https://github.com/juanroman/emvqr</PackageProjectUrl>
<Copyright>Copyright (C) 2018 Juan Roman Escamilla</Copyright>
<PackageLicenseUrl>https://raw.githubusercontent.com/juanroman/emvqr/master/README.md</PackageLicenseUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/juanroman/emvqr/master/LICENSE</PackageLicenseUrl>
<PackageReleaseNotes />
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>
Expand Down

0 comments on commit 8df5827

Please sign in to comment.