M
MyDiscount API
v1.0

mydiscount.eservicii.md
API Key (GUID)
JSON · REST
INTELECTSOFT

curl -X POST "https://mydiscount.eservicii.md/MyDiscountApp/erp/CheckApiKey" \
  -H "Content-Type: application/json" \
  -d '{
    "mAPIKey": "00000000-0000-0000-0000-000000000000"
  }'
using System.Net.Http;
using System.Net.Http.Json;

var client = new HttpClient { BaseAddress = new Uri("https://mydiscount.eservicii.md/MyDiscountApp/erp/") };
var payload = new { mAPIKey = Guid.Parse("00000000-0000-0000-0000-000000000000") };
var response = await client.PostAsJsonAsync("CheckApiKey", payload);
var result = await response.Content.ReadFromJsonAsync<ResponseCheckApiKey>();

{
  "ErrorCode": 0,
  "ErrorMessage": null
}

Company
Card
Cash
CashTransaction
ValidatedCard
DiscountProfile

POS / ERP AuthorizeCard GET endpoint MyDiscount Key : CardID (GUID) Amount : 250.00 UserName : "Ion Popescu"

curl -X POST "https://mydiscount.eservicii.md/MyDiscountApp/erp/AddBonus" \
  -H "Content-Type: application/json" \
  -d '{
    "APIKey": "11111111-2222-3333-4444-555555555555",
    "CardID": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
    "Amount": 25.00,
    "CashBack": 5.0,
    "Details": "Invoice #INV-12345",
    "DateTimeOfSale": "2026-04-30T14:35:00",
    "PlaceOfSale": "Central Store, Cashier 3"
  }'
var request = new CashData
{
    APIKey         = Guid.Parse(apiKey),
    CardID         = cardId,
    Amount         = 25.00m,
    CashBack       = 5.0m,
    Details        = "Invoice #INV-12345",
    DateTimeOfSale = DateTime.Now,
    PlaceOfSale    = "Central Store, Cashier 3"
};
var response = await client.PostAsJsonAsync("AddBonus", request);
var result = await response.Content.ReadFromJsonAsync<ResponseSetCashBack>();

CheckApiKey

POST/MyDiscountApp/erp/CheckApiKey

mAPIKeyGuid

ErrorCodeEnErrorCode
ErrorMessagestring?

curl -X POST "https://mydiscount.eservicii.md/MyDiscountApp/erp/CheckApiKey" \
  -H "Content-Type: application/json" \
  -d '{ "mAPIKey": "YOUR-API-KEY-HERE" }'
var payload = new { mAPIKey = Guid.Parse(apiKey) };
var resp = await client.PostAsJsonAsync("CheckApiKey", payload);

AuthorizeCard

GET/MyDiscountApp/erp/AuthorizeCard

TIDstring
APIKeyGuid
PlaceOfSalestring

ErrorCodeEnErrorCode
KeyGuid
Amountdecimal
UserNamestring
PHIDstring
PushTokenstring
DiscountPercentdecimal

curl -X GET "https://mydiscount.eservicii.md/MyDiscountApp/erp/AuthorizeCard?TID=abc12345-...&APIKey=YOUR-KEY&PlaceOfSale=Casa%203"
var qs = $"AuthorizeCard?TID={Uri.EscapeDataString(tid)}" +
         $"&APIKey={apiKey}&PlaceOfSale={Uri.EscapeDataString(placeOfSale)}";
var resp = await client.GetAsync(qs);
var data = await resp.Content.ReadFromJsonAsync<ResponseAuthorizeCard>();

GetInfoBonusAmount

POST/MyDiscountApp/erp/GetInfoBonusAmount

CardIDGuid
mAPIKeyGuid

Amountdecimal
ErrorCodeEnErrorCode
ErrorMessagestring?
curl -X POST "https://mydiscount.eservicii.md/MyDiscountApp/erp/GetInfoBonusAmount" \
  -H "Content-Type: application/json" \
  -d '{ "CardID": "...", "mAPIKey": "YOUR-API-KEY" }'
var payload = new { CardID = cardId, mAPIKey = apiKey };
var resp = await client.PostAsJsonAsync("GetInfoBonusAmount", payload);

AddBonus

POST/MyDiscountApp/erp/AddBonus

APIKeyGuid
CardIDGuid
Amountdecimal
CashBackdecimal
Detailsstring
DateTimeOfSaleDateTime
PlaceOfSalestring

TransactionIDGuid
ErrorCodeEnErrorCode
ErrorMessagestring?

GetBonus

POST/MyDiscountApp/erp/GetBonus

Transaction

POST/MyDiscountApp/erp/Transaction

APIKeyGuid
CardIDGuid
Amountdecimal
BillIDstring

BulkImport

POST/MyDiscountApp/CompanyCards/bulk-import

APIKeyGuid
UniqueIdentifierUniqueField
PurgeExistingbool
ItemsCompanyCardImportItem[]

0Barcode
1ExternalId
2Phone

Barcodestring
ExternalIdstring
Phonestring
AccumulatedAmountdecimal
CategoryCardCategory
StatusCardStatus
IssuedAtDateTime
ExpiresAtDateTime?
Notestring
Descriptionstring

Okbool
InsertedCountint
UpdatedCountint
DeletedCountint
SkippedCountint
Errorsstring[]

curl -X POST "https://mydiscount.eservicii.md/MyDiscountApp/CompanyCards/bulk-import" \
  -H "Content-Type: application/json" \
  -d '{
    "APIKey": "11111111-2222-3333-4444-555555555555",
    "UniqueIdentifier": 0,
    "PurgeExisting": false,
    "Items": [
      {
        "Barcode": "5949000000017",
        "ExternalId": "ERP-1001",
        "Phone": "+37369123456",
        "AccumulatedAmount": 250.50,
        "Category": 1,
        "Status": 0,
        "IssuedAt": "2026-01-15T10:00:00Z",
        "ExpiresAt": "2028-01-15T00:00:00Z",
        "Note": "VIP customer"
      },
      {
        "Barcode": "5949000000024",
        "ExternalId": "ERP-1002",
        "Phone": "+37369765432",
        "Category": 0,
        "Status": 0
      }
    ]
  }'
var request = new BulkImportRequest
{
    APIKey           = Guid.Parse(apiKey),
    UniqueIdentifier = UniqueField.Barcode,
    PurgeExisting    = false,
    Items = new List<CompanyCardImportItem>
    {
        new() {
            Barcode           = "5949000000017",
            ExternalId        = "ERP-1001",
            Phone             = "+37369123456",
            AccumulatedAmount = 250.50m,
            Category          = CardCategory.VIP,
            Status            = CardStatus.Active,
            IssuedAt          = DateTime.UtcNow,
            ExpiresAt         = DateTime.UtcNow.AddYears(2),
            Note              = "VIP customer"
        },
        new() {
            Barcode    = "5949000000024",
            ExternalId = "ERP-1002",
            Phone      = "+37369765432",
            Category   = CardCategory.Standard,
            Status     = CardStatus.Active
        }
    }
};

var resp = await client.PostAsJsonAsync("CompanyCards/bulk-import", request);
var result = await resp.Content.ReadFromJsonAsync<BulkImportResult>();

Console.WriteLine($"Inserted: {result.InsertedCount}, Updated: {result.UpdatedCount}, Skipped: {result.SkippedCount}");
if (result.Errors?.Count > 0)
    Console.WriteLine($"Errors: {string.Join('\n', result.Errors)}");

{
  "Ok": true,
  "InsertedCount": 2,
  "UpdatedCount": 0,
  "DeletedCount": 0,
  "SkippedCount": 0,
  "Errors": []
}

CashData

JSON Schema
{
  "APIKey":         Guid,
  "CardID":         Guid,
  "Amount":         decimal,
  "CashBack":       decimal,
  "Details":        string,
  "DateTimeOfSale": DateTime,
  "PlaceOfSale":    string     // max 200 chars
}

BillData

JSON Schema
{
  "APIKey": Guid,
  "CardID": Guid,
  "Amount": decimal,
  "BillID": string
}

ResponseAuthorizeCard

JSON Schema
{
  "ErrorCode":       EnErrorCode,
  "ErrorMessage":    string,
  "Key":             Guid,
  "Amount":          decimal,
  "UserName":        string,
  "PHID":            string,
  "PushToken":       string,
  "DiscountPercent": decimal
}

ResponseSetCashBack

JSON Schema
{
  "ErrorCode":     EnErrorCode,
  "ErrorMessage":  string,
  "TransactionID": Guid
}

ResponseGetInfoBonusAmount

JSON Schema
{
  "ErrorCode":    EnErrorCode,
  "ErrorMessage": string,
  "Amount":       decimal
}

BulkImportRequest

JSON Schema
{
  "APIKey":           Guid,
  "UniqueIdentifier": UniqueField,   // 0=Barcode, 1=ExternalId, 2=Phone
  "PurgeExisting":    bool,
  "Items":            CompanyCardImportItem[]
}

CompanyCardImportItem

JSON Schema
{
  "Barcode":           string,
  "ExternalId":        string,
  "Phone":             string,
  "AccumulatedAmount": decimal,
  "Category":          CardCategory,
  "Status":            CardStatus,
  "IssuedAt":          DateTime,
  "ExpiresAt":         DateTime?,
  "Note":              string,         // max 500
  "Description":       string          // max 5000
}

BulkImportResult

JSON Schema
{
  "Ok":            bool,
  "InsertedCount": int,
  "UpdatedCount":  int,
  "DeletedCount":  int,
  "SkippedCount":  int,
  "Errors":        string[]
}

0NoError
Invalid_ID
Card_not_exist
Expired_token
Time_card_ID_expired
Insufficient_amount_on_card
The_amount_is_incorrect
APIKey_not_exist
Internal_error

// 1. 
var auth = await client.GetFromJsonAsync<ResponseAuthorizeCard>(
    $"AuthorizeCard?TID={tid}&APIKey={apiKey}&PlaceOfSale=Casa-1");

if (auth.ErrorCode != EnErrorCode.NoError)
    throw new Exception($"Invalid card: {auth.ErrorCode}");

// 2. 
var info = await client.PostAsJsonAsync("GetInfoBonusAmount",
    new { CardID = auth.Key, mAPIKey = apiKey });
var infoData = await info.Content.ReadFromJsonAsync<ResponseGetInfoBonusAmount>();

// 3. 
decimal deUsing = Math.Min(infoData.Amount, 80m);
var use = await client.PostAsJsonAsync("GetBonus", new CashData
{
    APIKey = apiKey, CardID = auth.Key, Amount = deUsing,
    Details = "Partial cashback",
    DateTimeOfSale = DateTime.Now, PlaceOfSale = "Casa-1"
});

// 4. 
decimal dePlatit = 80m - deUsing;

decimal totalBon = 200m;
decimal bonusDeAdaugat = totalBon * 0.05m;

var add = await client.PostAsJsonAsync("AddBonus", new CashData
{
    APIKey = apiKey, CardID = cardId,
    Amount = bonusDeAdaugat, CashBack = 5m,
    Details = $"Cashback 5% on bill {billId}",
    DateTimeOfSale = DateTime.Now, PlaceOfSale = "Casa-1"
});

var result = await add.Content.ReadFromJsonAsync<ResponseSetCashBack>();

// 1. 
var allErpCards = await _erp.GetAllLoyaltyCardsAsync();  // e.g. 12,500 cards

// 2. 
const int batchSize = 1500;
int totalInserted = 0, totalUpdated = 0, totalSkipped = 0;

for (int i = 0; i < allErpCards.Count; i += batchSize)
{
    var batch = allErpCards.Skip(i).Take(batchSize).ToList();

    var request = new BulkImportRequest
    {
        APIKey           = apiKey,
        UniqueIdentifier = UniqueField.ExternalId,  // match după ID-ul ERP
        PurgeExisting    = false,                    // sync, nu reset
        Items = batch.Select(c => new CompanyCardImportItem
        {
            ExternalId        = c.ErpId,
            Barcode           = c.Barcode,
            Phone             = c.CustomerPhone,
            AccumulatedAmount = c.Balance,
            Category          = c.IsVip ? CardCategory.VIP : CardCategory.Standard,
            Status            = c.IsActive ? CardStatus.Active : CardStatus.Blocked,
            IssuedAt          = c.CreatedAt,
            ExpiresAt         = c.ValidUntil
        }).ToList()
    };

    var resp = await client.PostAsJsonAsync("CompanyCards/bulk-import", request);
    var res  = await resp.Content.ReadFromJsonAsync<BulkImportResult>();

    if (!res.Ok)
    {
        _logger.LogError($"Batch {i} failed: {string.Join(';', res.Errors)}");
        continue;  // batch-urile sunt independente
    }

    totalInserted += res.InsertedCount;
    totalUpdated  += res.UpdatedCount;
    totalSkipped  += res.SkippedCount;
}

_logger.LogInformation(
    $"Sync complete: +{totalInserted} inserted, ~{totalUpdated} updated, {totalSkipped} skipped");