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);
        }
Beispiel #2
0
        /// <summary>
        /// Create payment
        /// </summary>
        /// <param name="hostingDomain"></param>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public async Task <ResultModel <MobilpayEncrypt> > CreatePaymentAsync(string hostingDomain, Guid?orderId)
        {
            var response     = new ResultModel <MobilpayEncrypt>();
            var encrypt      = new MobilpayEncrypt();
            var encDec       = new MobilpayEncryptDecrypt.MobilpayEncryptDecrypt();
            var orderRequest = await _orderProductService.GetOrderByIdAsync(orderId);

            if (!orderRequest.IsSuccess)
            {
                return(response);
            }

            var isPayedRequest = await _paymentService.IsOrderPayedAsync(orderId);

            if (isPayedRequest.IsSuccess)
            {
                return(response);
            }

            var order          = orderRequest.Result;
            var addressRequest = await _userAddressService.GetAddressByIdAsync(order.BillingAddress);

            var address = addressRequest.IsSuccess ? addressRequest.Result : new Address();
            var user    = await _userManager.UserManager.FindByIdAsync(order.UserId.ToString());

            try
            {
                var card        = new Mobilpay_Payment_Request_Card();
                var invoice     = new Mobilpay_Payment_Invoice();
                var billing     = new Mobilpay_Payment_Address();
                var shipping    = new Mobilpay_Payment_Address();
                var contactInfo = new Mobilpay_Payment_Request_Contact_Info();
                var url         = new Mobilpay_Payment_Request_Url();

                var enc = new MobilpayEncryptDecrypt.MobilpayEncryptDecrypt();
                card.OrderId     = CreateMobilPayOrderId(order.Id);
                card.Type        = "card";
                card.Signature   = _configuration.Signature;
                url.ConfirmUrl   = $"{hostingDomain}/MobilPay/ConfirmCard";
                url.ReturnUrl    = $"{hostingDomain}/MobilPay/ReturnCard";
                card.Url         = url;
                card.TimeStamp   = DateTime.Now.ToString("yyyyMMddhhmmss");
                invoice.Amount   = order.Total;
                invoice.Currency = order.Currency?.Code;
                invoice.Details  = $"#{orderId}";

                billing.FirstName  = user?.FirstName;
                billing.LastName   = user?.LastName;
                billing.Email      = user?.Email;
                billing.MobilPhone = address.Phone;
                billing.Address    = address.AddressLine1;
                billing.ZipCode    = address.ZipCode;
                billing.Country    = address.Country?.Name;
                billing.City       = address.StateOrProvince?.Name;

                contactInfo.Billing             = billing;
                shipping.Sameasbilling          = "1";
                contactInfo.Shipping            = shipping;
                invoice.ContactInfo             = contactInfo;
                card.Invoice                    = invoice;
                encrypt.Data                    = enc.GetXmlText(card);
                encrypt.X509CertificateFilePath = GetPathToCertificate();
                encDec.EncryptWithCng(encrypt);
                await _orderProductService.ChangeOrderStateAsync(orderId, OrderState.PendingPayment);

                response.IsSuccess = true;
                response.Result    = encrypt;
                return(response);
            }
            catch (Exception ex)
            {
                response.Errors.Add(new ErrorModel(string.Empty, ex.Message));
            }

            return(response);
        }
        public MobilpayEncrypt CreatePaymentForNetopia(int invoiceId)
        {
            MobilpayEncrypt encrypt = new MobilpayEncrypt();

            Mobilpay_Payment_Request_Card            card     = new Mobilpay_Payment_Request_Card();
            Mobilpay_Payment_Invoice                 invoice  = new Mobilpay_Payment_Invoice();
            Mobilpay_Payment_Address                 billing  = new Mobilpay_Payment_Address();
            Mobilpay_Payment_Address                 shipping = new Mobilpay_Payment_Address();
            Mobilpay_Payment_Invoice_Item            itmm     = new Mobilpay_Payment_Invoice_Item();
            Mobilpay_Payment_Invoice_Item            itmm1    = new Mobilpay_Payment_Invoice_Item();
            Mobilpay_Payment_ItemCollection          itmColl  = new Mobilpay_Payment_ItemCollection();
            Mobilpay_Payment_Exchange_RateCollection exColl   = new Mobilpay_Payment_Exchange_RateCollection();
            Mobilpay_Payment_Exchange_Rate           ex       = new Mobilpay_Payment_Exchange_Rate();
            Mobilpay_Payment_Request_Contact_Info    ctinfo   = new Mobilpay_Payment_Request_Contact_Info();
            Mobilpay_Payment_Confirm                 conf     = new Mobilpay_Payment_Confirm();
            Mobilpay_Payment_Request_Url             url      = new Mobilpay_Payment_Request_Url();



            MobilpayEncryptDecrypt.MobilpayEncryptDecrypt encdecr = new MobilpayEncryptDecrypt.MobilpayEncryptDecrypt();
            card.OrderId   = new Random().Next().ToString();
            card.Type      = "card";
            card.Signature = m_PaymentConfiguration.Signature;
            url.ConfirmUrl = m_PaymentConfiguration.ConfirmUrl;
            url.ReturnUrl  = m_PaymentConfiguration.ReturnUrl;
            //card.Service = service;
            card.Url         = url;
            card.TimeStamp   = DateTime.Now.ToString("yyyyMMddhhmmss");
            invoice.Amount   = youramount;
            invoice.Currency = yourcurrency;

            invoice.Details        = yourdetails;
            invoice.Items          = new Mobilpay_Payment_ItemCollection();
            billing.FirstName      = "ceva";
            billing.LastName       = "ceva";
            billing.IdentityNumber = "ceva";
            billing.FiscalNumber   = "ceva";
            billing.MobilPhone     = "ceva";
            billing.Type           = "person";
            billing.ZipCode        = "ceva";
            billing.Iban           = "ceva";
            billing.Address        = "ceva";
            billing.Bank           = "ceva";
            billing.City           = "ceva";
            billing.Country        = "ceva";
            billing.County         = "ceva";
            billing.Email          = "*****@*****.**";

            shipping.Sameasbilling = "1";


            ctinfo.Billing  = billing;
            ctinfo.Shipping = shipping;


            invoice.ContactInfo = ctinfo;


            card.Invoice = invoice;
            if (String.IsNullOrWhiteSpace(m_UserToken) == false)
            {
                card.Invoice.TokenId = m_UserToken;
            }

            encrypt.Data = encdecr.GetXmlText(card);
            encrypt.X509CertificateFilePath = GetPathToCertificate();
            m_Logger.LogInformation($"X509CertificateFilePath= [{encrypt.X509CertificateFilePath}]");
            //encdecr.Encrypt(encrypt);
            //Apelul urmator nu arunca exceptie
            encdecr.EncryptWithCng(encrypt);


            return(encrypt);
        }