Esempio n. 1
0
        public async Task UpdateInvoiceOnNotification(ePayRecieveViewModel ePayReceive)
        {
            //int invoiceForUpdateId = int.Parse(ePayReceive.Invoice);
            Invoices invoiceToUpdate = await unitOfWork.InvoicesRepository
                                       .Where(i => i.InvoiceNumber == ePayReceive.Invoice && i.Status == null)
                                       .OrderByDescending(i => i.CreatedOn.Year)
                                       .FirstOrDefaultAsync();

            if (invoiceToUpdate == null)
            {
                throw new ContentNotFoundException();
            }
            invoiceToUpdate.Status   = ePayReceive.Status;
            invoiceToUpdate.Stan     = string.IsNullOrEmpty(ePayReceive.Stan) ? null : (int?)int.Parse(ePayReceive.Stan);
            invoiceToUpdate.PayDate  = string.IsNullOrEmpty(ePayReceive.PayDate) ? null : (DateTime?)DateTime.ParseExact(ePayReceive.PayDate, "yyyyMMddHHmmss", null);
            invoiceToUpdate.BankCode = string.IsNullOrEmpty(ePayReceive.BankCode) ? null : ePayReceive.BankCode;

            unitOfWork.InvoicesRepository.Edit(invoiceToUpdate);
            await unitOfWork.SaveAsync();
        }
Esempio n. 2
0
        public async Task <ContentResult> PaymentAccept(string encoded, string checksum)
        {
            var infoStatus            = "";
            var ePayQueryDataAsString = Encoding.UTF8.GetString(Convert.FromBase64String(encoded)); //ex. INVOICE=00050:STATUS=PAID:PAY_TIME=20171204163636:STAN=058030:BCODE=058030
            var ePayQueryData         = ePayQueryDataAsString.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var ePayTransaction in ePayQueryData)
            {
                if (checksum != ePayHelpers.HMAC_SHA1_Encoding(encoded))
                {
                    return(Content($"INVOICE={ePayQueryDataAsString[1]}:STATUS=ERR\n")); //"ERR=Not valid CHECKSUM\n", "plain/text"
                }
                if (RegexExtentions.preg_match(@"^INVOICE=(\d+):STATUS=(PAID|DENIED|EXPIRED)(:PAY_TIME=(\d+):STAN=(\d+):BCODE=([0-9a-zA-Z]+))?$", ePayTransaction, out var ePayQueryDataProperties))
                {
                    ePayRecieveViewModel paymentData = new ePayRecieveViewModel()
                    {
                        Invoice  = int.Parse(ePayQueryDataProperties[1]),
                        Status   = ePayQueryDataProperties[2],
                        PayDate  = ePayQueryDataProperties[4],
                        Stan     = ePayQueryDataProperties[5],
                        BankCode = ePayQueryDataProperties[6]
                    };

                    switch (paymentData.Status)
                    {
                    case "PAID":
                        try      // if invoice with this id is not found
                        {
                            await invoicesManager.UpdateInvoiceOnNotification(paymentData);

                            infoStatus = $"INVOICE={paymentData.Invoice}:STATUS=OK\n";
                            await paymentsManager.AcceptPayment(paymentData.Invoice);
                        }
                        catch (ContentNotFoundException)
                        {
                            infoStatus = $"INVOICE={paymentData.Invoice}:STATUS=NO\n";
                        }
                        catch (Exception)
                        {
                            infoStatus = $"INVOICE={paymentData.Invoice}:STATUS=ERR\n";
                        }
                        //Increase the balance of the user
                        break;

                    case "DENIED":
                    case "EXPIRED":
                        try     // if invoice with this id is not found
                        {
                            await invoicesManager.UpdateInvoiceOnNotification(paymentData);

                            infoStatus = $"INVOICE={paymentData.Invoice}:STATUS=OK\n";
                        }
                        catch (ContentNotFoundException)
                        {
                            infoStatus = $"INVOICE={paymentData.Invoice}:STATUS=NO\n";
                        }
                        break;

                    default:
                        infoStatus = $"INVOICE={paymentData.Invoice}:STATUS=ERR\n";
                        break;
                    }
                }
                else
                {
                    infoStatus = "The RegularExpression Does not Match the entry";
                }
            }
            return(Content(infoStatus, "plain/text"));
        }