public PaymentResult ConfirmPayment(string textxml, string env_key)
        {
            var contentRootPath = m_HostingEnvironment.ContentRootPath.AddBackslash();
            var keypath         = Path.GetFullPath(Path.Combine(contentRootPath, m_PaymentConfiguration.PathToPrivateKey));

            PaymentResult result = new PaymentResult();

            MobilpayEncryptDecrypt.MobilpayEncryptDecrypt encdecrypt = new MobilpayEncryptDecrypt.MobilpayEncryptDecrypt();
            MobilpayDecrypt decrypt = new MobilpayDecrypt();

            decrypt.Data               = textxml;
            decrypt.EnvelopeKey        = env_key;
            decrypt.PrivateKeyFilePath = keypath;
            //encdecrypt.Decrypt(decrypt);
            encdecrypt.Decrypt(decrypt);
            Mobilpay_Payment_Request_Card card = new Mobilpay_Payment_Request_Card();

            card = encdecrypt.GetCard(decrypt.DecryptedData);

            var panMasked = card.Confirm.PanMasked;

            m_UserToken = card.Confirm.TokenId;
            m_Logger.LogInformation($"User token retrieved: {String.IsNullOrEmpty(card.Confirm.TokenId)}");
            var tokenExpirationDate = card.Confirm.TokenExpirationDate;

            m_Logger.LogInformation($"Rezultatul tranzactiei este: {card.Confirm.Action}");

            switch (card.Confirm.Action)
            {
            case "confirmed": //plata efectuata
            case "paid":      //bani blocati
            {
                decimal paidAmount = card.Confirm.Original_Amount;
                result.ErrorMessage = card.Confirm.Crc;
                if (card.Confirm.Action == "confirmed" && card.Confirm.Error.Code == "0")
                {
                    //var invoice = m_Repository.All<Invoice>().Where(i => i.Id == nMessage.InvoiceId).First();
                    //if (!invoice.IsPaid)
                    //{
                    //    m_NetopiaSystem.RecordInvoicePayment(invoice.Id, paidAmount);
                    //}
                }
                break;
            }

            default:
            {
                result.ErrorType    = "0x02";
                result.ErrorCode    = "0x300000f6";
                result.ErrorMessage = "mobilpay_refference_action paramaters is invalid";
                break;
            }
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Confirm payment
        /// </summary>
        /// <param name="textXml"></param>
        /// <param name="envKey"></param>
        /// <returns></returns>
        public async Task <MobilPayPaymentResponse> ConfirmPaymentAsync(string textXml, string envKey)
        {
            var rootPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var filePath = Path.GetFullPath(Path.Combine(rootPath, _configuration.PathToPrivateKey));

            var result = new MobilPayPaymentResponse
            {
                ErrorCode = "0"
            };

            var encryptDecrypt = new MobilpayEncryptDecrypt.MobilpayEncryptDecrypt();
            var decrypt        = new MobilpayDecrypt
            {
                Data               = textXml,
                EnvelopeKey        = envKey,
                PrivateKeyFilePath = filePath
            };

            encryptDecrypt.Decrypt(decrypt);
            var card         = encryptDecrypt.GetCard(decrypt.DecryptedData);
            var orderId      = ExtractOrderId(card.OrderId);
            var orderRequest = await _orderProductService.GetOrderByIdAsync(orderId);

            if (!orderRequest.IsSuccess)
            {
                return(new MobilPayPaymentResponse
                {
                    ErrorType = "0x02",
                    ErrorCode = "0x300000f6",
                    ErrorMessage = "mobilpay_refference_action paramaters is invalid"
                });
            }

            var order   = orderRequest.Result;
            var payment = new Payment
            {
                PaymentMethodId      = MobilPayResources.MobilPay,
                GatewayTransactionId = card.OrderId,
                PaymentStatus        = PaymentStatus.Failed,
                Total          = order.Total,
                UserId         = order.UserId,
                FailureMessage = card.Card.SerializeAsJson()
            };
            var orderState = order.OrderState;

            switch (card.Confirm.Action)
            {
            case "confirmed":
            case "paid":
            {
                result.ErrorMessage = card.Confirm.Crc;
                if (card.Confirm.Action == "confirmed" && card.Confirm.Error.Code == "0")
                {
                    payment.PaymentStatus = PaymentStatus.Succeeded;
                    orderState            = OrderState.PaymentReceived;
                }
                break;
            }

            default:
            {
                result.ErrorType    = "0x02";
                result.ErrorCode    = "0x300000f6";
                result.ErrorMessage = "mobilpay_refference_action paramaters is invalid";
                orderState          = OrderState.PaymentFailed;
                break;
            }
            }

            var addPaymentRequest = await _paymentService.AddPaymentAsync(orderId, payment);

            if (addPaymentRequest.IsSuccess)
            {
                await _orderProductService.ChangeOrderStateAsync(orderId, orderState);
            }

            return(result);
        }