public async Task <IActionResult> ChargeSvc(string cardCode, decimal price)
        {
            SVCChargeOperationViewModel svcBody = new SVCChargeOperationViewModel();

            svcBody.StoredValueCardCodeCollection.Add(cardCode);

            svcBody.CashbackType = SVCCashbackType.None;

            Issuer issuer = new Issuer();

            issuer.Name      = "Vittorio";
            issuer.Address   = "via centomani 11";
            issuer.Telephone = "0000000";
            issuer.EMail     = "*****@*****.**";
            issuer.VATNumber = "222222";

            svcBody.StoredValueCardReceipt.IssuerData = issuer;

            ReceiptProduct receiptProduct = new ReceiptProduct();

            receiptProduct.Code     = cardCode;
            receiptProduct.Name     = "VittorioCard";
            receiptProduct.Price    = price;
            receiptProduct.Quantity = 1;
            receiptProduct.Family   = "";
            receiptProduct.Mode     = "";

            svcBody.StoredValueCardReceipt.Products.Add(receiptProduct);

            Payment payment = new Payment();

            payment.CardCode = cardCode;

            svcBody.StoredValueCardReceipt.Payments.Add(payment);

            ShopReceipt shopReceipt = new ShopReceipt();

            shopReceipt.IssueDate = DateTime.Now;
            shopReceipt.UserData  = "";

            svcBody.StoredValueCardReceipt.IssueDate = DateTime.Now;
            svcBody.StoredValueCardReceipt.UserData  = "";

            SenderData senderData = new SenderData();

            senderData.Shop       = Constants.SHOP;
            senderData.Terminal   = Constants.TERMINAL;
            senderData.Type       = 0;
            senderData.Number     = 0;
            senderData.CashDrawer = 0;
            senderData.Operator   = "";

            svcBody.StoredValueCardReceipt.SenderData = senderData;

            var charge = await _svcService.Charge(svcBody);

            return(View("AssociaCarta", charge));
        }
Example #2
0
        public async Task <SVCResultViewModel> Charge(SVCChargeOperationViewModel model)
        {
            SVCResultViewModel result = new SVCResultViewModel(Constants.MSG_RESULT_MESSAGE_OK, Constants.MSG_RESULT_STATUS_OK, Constants.MSG_RESULT_CODE_OK);

            _logger.LogInformation(string.Format("-- ApiManager - Create started"));

            string jsonMessage = "";

            try
            {
                // Read token from ServerLogin
                string token = await _authentication.GetToken();

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Constants.BASE_ADDRESS);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                    //Read endpoint from CampaignType
                    string endpoint = Constants.API_CHARGE;

                    HttpResponseMessage response = await client.PutAsync(endpoint, new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"));

                    using (Stream responseStream = await response.Content.ReadAsStreamAsync())
                    {
                        jsonMessage = new StreamReader(responseStream).ReadToEnd();
                    }
                    result = JsonConvert.DeserializeObject <SVCResultViewModel>(jsonMessage);
                }
            }
            catch (System.Exception ex)
            {
                result.ResultMessage = ex.Message;
                result.ResultStatus  = Constants.MSG_RESULT_STATUS_NOK;
                result.ResultCode    = Constants.MSG_RESULT_CODE_KO;
            }

            return(result);
        }