// PUT api/<controller>/5 public HttpResponseMessage Put([FromBody] PaymentAccount pay) { if (pay.BeneficiaryID != null && pay.UserID == null) { DBFilterClass <PaymentAccount> pa = new DBFilterClass <PaymentAccount> { Field = c => c.BeneficiaryID, FieldValues = c => c.BeneficiaryID, condition = FilterCondition.equals }; DatabaseHandler <PaymentAccount> .UpdateDocument(pay, pa); return(new HttpResponseMessage(HttpStatusCode.OK)); } else if (pay.BeneficiaryID == null && pay.UserID != null) { DBFilterClass <PaymentAccount> pa = new DBFilterClass <PaymentAccount> { Field = c => c.UserID, FieldValues = c => c.UserID, condition = FilterCondition.equals }; DatabaseHandler <PaymentAccount> .UpdateDocument(pay, pa); return(new HttpResponseMessage(HttpStatusCode.OK)); } else { return(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } }
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); }