private string AccuserReception() { string sResult = ""; string montant = ""; string reference = ""; string MAC = ""; string TexteLibre = ""; string CodeRetour = ""; string dateConfirmation = ""; string Cvx = ""; string Vld = ""; string Brand = ""; string Status3DS = ""; string NumAuto = ""; string MotifRefus = ""; string OrigineCB = ""; string BinCB = ""; string HPanCB = ""; string IPClient = ""; string OrigineTr = ""; string VeRes = ""; string PaRes = ""; string MontantEch = ""; try { if (Request.ServerVariables["REQUEST_METHOD"] == "GET") { montant += Request.QueryString["montant"]; reference += Request.QueryString["reference"]; MAC += Request.QueryString["MAC"]; TexteLibre += Request.QueryString["texte-libre"]; CodeRetour += Request.QueryString["code-retour"]; dateConfirmation += Request.QueryString["date"]; Cvx += Request.QueryString["cvx"]; Vld += Request.QueryString["vld"]; Brand += Request.QueryString["brand"]; Status3DS += Request.QueryString["status3ds"]; NumAuto += Request.QueryString["numauto"]; MotifRefus += Request.QueryString["motifrefus"]; OrigineCB += Request.QueryString["originecb"]; BinCB += Request.QueryString["bincb"]; HPanCB += Request.QueryString["hpancb"]; IPClient += Request.QueryString["ipclient"]; OrigineTr += Request.QueryString["originetr"]; VeRes += Request.QueryString["veres"]; PaRes += Request.QueryString["pares"]; MontantEch += Request.QueryString["montantech"]; } else { if (Request.ServerVariables["REQUEST_METHOD"] == "POST") { montant += Request.Form["montant"]; reference += Request.Form["reference"]; MAC += Request.Form["MAC"]; TexteLibre += Request.Form["texte-libre"]; CodeRetour += Request.Form["code-retour"]; dateConfirmation += Request.Form["date"]; Cvx += Request.Form["cvx"]; Vld += Request.Form["vld"]; Brand += Request.Form["brand"]; Status3DS += Request.Form["status3ds"]; NumAuto += Request.Form["numauto"]; MotifRefus += Request.Form["motifrefus"]; OrigineCB += Request.Form["originecb"]; BinCB += Request.Form["bincb"]; HPanCB += Request.Form["hpancb"]; IPClient += Request.Form["ipclient"]; OrigineTr += Request.Form["originetr"]; VeRes += Request.Form["veres"]; PaRes += Request.Form["pares"]; MontantEch += Request.Form["montantech"]; } } bool bProdServer = (ConfigurationManager.ServerType == ConfigurationManager.EnumServerType.PROD.ToString()) ? true : false; Upsilab.Data.Model.Payment.CMCIC_Page CMICIC_Page = new Data.Model.Payment.CMCIC_Page("FR", bProdServer); CMICIC_Page.sDataToValidate = CMICIC_Page.sNumero + "*" + dateConfirmation + "*" + montant + "*" + reference + "*" + TexteLibre + "*" + CMICIC_Page.sVersion + "*"; CMICIC_Page.sDataToValidate += CodeRetour + "*" + Cvx + "*" + Vld + "*" + Brand + "*" + Status3DS + "*" + NumAuto + "*" + MotifRefus + "*"; CMICIC_Page.sDataToValidate += OrigineCB + "*" + BinCB + "*" + HPanCB + "*" + IPClient + "*" + OrigineTr + "*" + VeRes + "*" + PaRes + "*"; //Just for test******************** //TODO : Comment this code //CodeRetour = "payetest"; //Annulation //reference = "65"; //idsouscription //MotifRefus = ""; //if (true) //Is valid hmac //Fin test************************* if (CMICIC_Page.oHmac.isValidHmac(CMICIC_Page.HmacString, MAC)) { switch (CodeRetour) { case "Annulation": /* * Payment has been refused * put your code here (email sending / Database update) * Attention : an authorization may still be delivered later */ break; case "payetest": /* * Payment has been accepted on the test server * put your code here (email sending / Database update) */ this.UpdateDBAndSendMail(int.Parse(reference)); break; case "paiement": /* * Payment has been accepted on the productive server * put your code here (email sending / Database update) */ this.UpdateDBAndSendMail(int.Parse(reference)); break; /*** ONLY FOR MULTIPART PAYMENT ***/ case "paiement_pf2": case "paiement_pf3": case "paiement_pf4": /* * Payment has been accepted on the productive server for the part #N * return code is like paiement_pf[#N] * put your code here (email sending / Database update) * You have the amount of the payment part in MontantEch */ break; case "Annulation_pf2": case "Annulation_pf3": case "Annulation_pf4": /* * Payment has been refused on the productive server for the part #N * return code is like Annulation_pf[#N] * put your code here (email sending / Database update) * You have the amount of the payment part in MontantEch */ break; } //Result to return to the API sResult = "0"; //Ok } else { /* * your code if the HMAC doesn't match */ MotifRefus = (!string.IsNullOrEmpty(MotifRefus)) ? MotifRefus : string.Format("HMAC {0} does not match", CMICIC_Page.HmacString); sResult = "1\n" + CMICIC_Page.HmacString; } } catch (Exception ex) { CodeRetour += "UPSIRECUEIL_EXCEPTION"; MotifRefus += ex.Message; sResult = "1"; } //Log payment PaymentLog paymentLog = new PaymentLog() { idSubscription = (!string.IsNullOrEmpty(reference)) ? int.Parse(reference) : 1, // default 1 ReturnCode = (!string.IsNullOrEmpty(CodeRetour)) ? CodeRetour : "UPSIRECUEIL_EXCEPTION", ReasonRefusal = MotifRefus, DatePayment = DateTime.Now }; Upsilab.Business.Log.PaymentLogBL.Save(paymentLog); return sResult; }
/// <summary> /// Send data to API CMCIC /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Aller(int id) { try { Subscription subscription = db.Subscription.Include("FirmInstitution").Where(s => s.IdSubscription == id).FirstOrDefault(); if (subscription != null) { //1- Set value to CMICIC_class // ---------------------------------------------------------------------------- // CheckOut Stub setting fictious Merchant and Order datas. // That's your job to set actual order fields. Here is a stub. // ----------------------------------------------------------------------------- bool bProdServer = (ConfigurationManager.ServerType == ConfigurationManager.EnumServerType.PROD.ToString()) ? true : false; Upsilab.Data.Model.Payment.CMCIC_Page CMCIC_Page = new Data.Model.Payment.CMCIC_Page("FR", bProdServer) { // Reference: unique, alphaNum (A-Z a-z 0-9), 12 characters max sReference = subscription.IdSubscription.ToString(), //Id command (= Id souscription) // Currency : ISO 4217 compliant sDevise = "EUR", // Amount : format "xxxxx.yy" (no spaces) sMontant = subscription.TotalAmount.ToString().Replace(",", "."), // Language of the company code sLangue = "FR", // free texte : a bigger reference, session context for the return on the merchant website sTexteLibre = HttpUtility.HtmlEncode(string.Format("{0} {1}", subscription.FirmInstitution.FirmInstitutionName, subscription.IdFirmInstitution)), // customer email sEmail = subscription.FirmInstitution.E_mail, sOptions = "", // transaction date : format d/m/y:h:m:s sDate = DateTime.Now.ToString("dd/MM/yyyy:HH:mm:ss"), // ---------------------------------------------------------------------------- // between 2 and 4 //sNbrEch = "4", sNbrEch = "", // date echeance 1 - format dd/mm/yyyy sDateEcheance1 = "", // montant échéance 1 - format "xxxxx.yy" (no spaces) //sMontantEcheance1 = "0.26" + sDevise; sMontantEcheance1 = "", // date echeance 2 - format dd/mm/yyyy sDateEcheance2 = "", // montant échéance 2 - format "xxxxx.yy" (no spaces) //sMontantEcheance2 = "0.25" + sDevise; sMontantEcheance2 = "", // date echeance 3 - format dd/mm/yyyy sDateEcheance3 = "", // montant échéance 3 - format "xxxxx.yy" (no spaces) //sMontantEcheance3 = "0.25" + sDevise; sMontantEcheance3 = "", // date echeance 4 - format dd/mm/yyyy sDateEcheance4 = "", // montant échéance 4 - format "xxxxx.yy" (no spaces) //sMontantEcheance4 = "0.25" + sDevise; sMontantEcheance4 = "", // ---------------------------------------------------------------------------- }; // Data to certify CMCIC_Page.sDataToValidate = CMCIC_Page.sNumero + "*" + CMCIC_Page.sDate + "*" + CMCIC_Page.sMontantForm + "*" + CMCIC_Page.sReference + "*" + CMCIC_Page.sTexteLibre + "*" + CMCIC_Page.sVersion + "*" + CMCIC_Page.sLangueForm + "*" + CMCIC_Page.sCodeSociete + "*" + CMCIC_Page.sEmail + "*" + CMCIC_Page.sNbrEch + "*" + CMCIC_Page.sDateEcheance1 + "*" + CMCIC_Page.sMontantEcheance1 + "*" + CMCIC_Page.sDateEcheance2 + "*" + CMCIC_Page.sMontantEcheance2 + "*" + CMCIC_Page.sDateEcheance3 + "*" + CMCIC_Page.sMontantEcheance3 + "*" + CMCIC_Page.sDateEcheance4 + "*" + CMCIC_Page.sMontantEcheance4 + "*" + CMCIC_Page.sOptions; //2- Create payment model Upsilab.Data.Model.Payment.PaymentModel paymentModel = new Data.Model.Payment.PaymentModel() { url_paiement = CMCIC_Page.sUrlPaiement, version = CMCIC_Page.sVersion, TPE = CMCIC_Page.sNumero, date = CMCIC_Page.sDate, montant = CMCIC_Page.sMontantForm, reference = CMCIC_Page.sReference, MAC = CMCIC_Page.sMAC, url_retour = CMCIC_Page.sUrlKo, url_retour_ok = CMCIC_Page.sUrlOkForm, // url_retour_err = CMCIC_Page.sUrlKo, lgue = CMCIC_Page.sLangueForm, societe = CMCIC_Page.sCodeSociete, texte_libre = CMCIC_Page.sTexteLibre, mail = CMCIC_Page.sEmail }; return View(paymentModel); } else { //Rediriger vers la page souscription return RedirectToAction("Identification", "Souscrire"); } } catch { return RedirectToAction("Identification", "Souscrire"); } }