Ejemplo n.º 1
0
        // POST: api/PayTracePayment
        public PayTraceResponse Post([FromBody] PayTraceRequest request)
        {
            PayTraceResponse suceessMsg = new PayTraceResponse();
            PayTraceResponse failMsg    = new PayTraceResponse();

            Random rnd = new Random();

            long tranID = rnd.Next(10000, 99999);

            suceessMsg.transaction_id          = tranID;
            suceessMsg.success                 = true;
            suceessMsg.status_message          = "Your transaction was successfully approved.";
            suceessMsg.response_code           = 101;
            suceessMsg.approval_code           = "TAS677";
            suceessMsg.approval_message        = "EXACT MATCH - Approved and completed";
            suceessMsg.external_transaction_id = "";

            failMsg.transaction_id          = tranID;
            failMsg.success                 = false;
            failMsg.status_message          = "Your transaction was not approved.";
            failMsg.response_code           = 102;
            failMsg.approval_code           = "";
            failMsg.approval_message        = "DECLINE - Do not honor";
            failMsg.external_transaction_id = "";

            bool delayResponse = (rnd.Next(2) == 1) ? true : false;

            if (delayResponse)
            {
                int delayTime = rnd.Next(500, 3000);
                System.Threading.Thread.Sleep(delayTime);
            }

            bool successful = true;

            if (request != null)
            {
                #region Validate account numbers
                Match match = Regex.Match(request.beneficiaryAcc, "^[0-9]{10}$");

                if (!match.Success)
                {
                    successful             = false;
                    failMsg.status_message = "Invalid beneficiary account number";
                }

                match = Regex.Match(request.beneficiarySortCode, "^[0-9]{6}$");

                if (!match.Success)
                {
                    successful             = false;
                    failMsg.status_message = "Invalid beneficiary sort code";
                }

                match = Regex.Match(request.remitterAcc, "^[0-9]{10}$");

                if (!match.Success)
                {
                    successful             = false;
                    failMsg.status_message = "Invalid remitter account number";
                }

                match = Regex.Match(request.remitterSortCode, "^[0-9]{6}$");

                if (!match.Success)
                {
                    successful             = false;
                    failMsg.status_message = "Invalid remitter sort code";
                }


                if (request.amount > VALUE_LIMIT)
                {
                    successful             = false;
                    failMsg.status_message = "Amount exceeds the value limits";
                }
                #endregion Validate account numbers

                return((successful) ? suceessMsg : failMsg);
            }
            else
            {
                failMsg.status_message = "Invalid Request was sent";
                return(failMsg);
            }
        }
Ejemplo n.º 2
0
        private static Payment makePayment(Payment pay)//This is the method that communicates with the 3rd party API and that process our paymentszs
        {
            PaymentType typePay = pay.TypePayment;

            switch (typePay)
            {
            case PaymentType.Card:
                Dictionary <Expression <Func <Card, object> >, Func <Card, object> > CardFilters = new Dictionary <Expression <Func <Card, object> >, Func <Card, object> >();
                CardFilters.Add(c => c.CardNr, c => c.CardNr);
                List <Card> payCard = DatabaseHandler <Card> .getDocumentContent(new Card { CardNr = pay.PaymentNumber }, CardFilters);

                string             year        = payCard[0].Expiry.Substring(0, 4);
                string             month       = payCard[0].Expiry.Substring(5, 2);
                VisaPaymentRequest Visarequest = new VisaPaymentRequest {
                    cardNumber = pay.PaymentNumber, amount = pay.Amount, CVV = payCard[0].Cvv, cardExpirationMonth = month, cardExpirationYear = year
                };
                VisaResponse cardResponse = VendorController.MakeCardPayment(Visarequest);
                pay.Status      = (cardResponse.ApprovalCode == "1") ?"Approved":"Declined";
                pay.Description = cardResponse.Description;

                break;

            case PaymentType.EFT:
                Dictionary <Expression <Func <PaymentAccount, object> >, Func <PaymentAccount, object> > Filters = new Dictionary <Expression <Func <PaymentAccount, object> >, Func <PaymentAccount, object> >();
                Filters.Add(c => c.AccountNumber, c => c.AccountNumber);
                List <PaymentAccount> payAcc = DatabaseHandler <PaymentAccount> .getDocumentContent(new PaymentAccount { AccountNumber = pay.PaymentNumber }, Filters);

                PayTraceRequest request = new PayTraceRequest {
                    remitterAcc = pay.PaymentNumber, amount = pay.Amount, remitterName = payAcc[0].AccountHolder, beneficiaryAcc = pay.BeneficiaryAccount, beneficiaryName = pay.BeneficairyID, beneficiarySortCode = "569875", narration = "", remitterSortCode = "125469"
                };
                PayTraceResponse TraceResponse = VendorController.MakePayment(request);
                pay.Status      = (TraceResponse.response_code == 101) ?"Approved":"Declinded";
                pay.Description = TraceResponse.status_message;
                break;

            case PaymentType.Crypto:
                Dictionary <Expression <Func <Crypto, object> >, Func <Crypto, object> > crypfilters = new Dictionary <Expression <Func <Crypto, object> >, Func <Crypto, object> >();
                crypfilters.Add(c => c.Waletaddress, c => c.Waletaddress);
                List <Crypto> crypList = DatabaseHandler <Crypto> .getDocumentContent(new Crypto { Waletaddress = pay.PaymentNumber }, crypfilters);

                //PayTraceRequest request = new PayTraceRequest { number = pay.PaymentNumber, amount = pay.Amount, holder = payAcc[0].AccountHolder };
                //PayTraceResponse TraceResponse = VendorController.MakePayment(request);
                //pay.Status = (TraceResponse.response_code == 101) ? "Approved" : "Declinded";
                //pay.Description = TraceResponse.status_message;
                ///addd code for crypto here
                Crypto ct = crypList[0];
                if (ct.Amount < pay.Amount)
                {
                    pay.Description = "Failed InseficientFunds";
                    pay.Status      = "Failed";
                }
                else
                {
                    ct.Amount -= pay.Amount;
                }
                DBFilterClass <Crypto> dbF = new DBFilterClass <Crypto> {
                    Field = c => c.Waletaddress, FieldValues = c => c.Waletaddress, condition = FilterCondition.equals
                };
                DatabaseHandler <Crypto> .UpdateDocument(ct, dbF);

                break;

            default:
                break;
            }

            return(pay);
        }