/// <summary> /// Calculates HMACSHA256 from response. /// This method uses /// <see cref="PaymentUtils.CalculateHashHMAC(byte[], byte[])"/> /// </summary> /// <returns>computed hash value in string format</returns> public string HashHMAC() { string macString = ""; string macDelimiter = "&"; macString = this.Version + macDelimiter + //1. this.Stamp + macDelimiter + // 2. this.Reference + macDelimiter + // 3. this.Payment + macDelimiter + // 4. this.Status + macDelimiter + // 5. this.Algorithm; // 6. string hashMac = PaymentUtils.CalculateHashHMAC(Encoding.UTF8.GetBytes(this.MerchantSecretKey), Encoding.UTF8.GetBytes(macString)); return(hashMac); }
/// <summary> /// 9. Calculates MAC, MD5-turvatarkiste lasketaan /// </summary> /// <returns>MAC</returns> public string CalculateMac() { string macString = ""; string macDelimiter = "+"; macString = this.Version + macDelimiter + // 1. this.Stamp + macDelimiter + // 2. this.Reference + macDelimiter + // 3. this.MerchantId + macDelimiter + // 4. this.Amount + macDelimiter + // 5. this.Currency + macDelimiter + // 6. this.Format + macDelimiter + // 7. this.Algorithm + macDelimiter + // 8. this.MerchantSecretKey; macString = PaymentUtils.CalculateMD5HashUTF8(macString); //9. this.MAC = macString; return(macString); }
protected void Page_Load(object sender, EventArgs e) { PaymentResponse paymentResponse = new PaymentResponse(); paymentResponse.SetValues(merchantSecretKey, Request.Params); //if response valid (ok data) if (paymentResponse.IsValid()) { this.paymentResponseMessage.Text = PaymentUtils.GetPaymentResponseStatusMessage(paymentResponse.Status); } else //invalid response (corrupt data) { Response.Redirect("~/PaymentErrorWebForm.aspx?error=response invalid"); } //save values ready for payment status query //Session used just for testign Session["Stamp"] = paymentResponse.Stamp; Session["Reference"] = paymentResponse.Reference; }
protected void Page_Load(object sender, EventArgs e) { //testing query functionality Query query = new Query(); query.InitializeValues((string)Session["Stamp"], (string)Session["Reference"], this.merchantId, (string)Session["Amount"], this.merchantSecretKey); //send Query to Checkout Finland string queryResponse = ""; try { queryResponse = CheckoutClient.postQueryData(query.FormData()); } catch (WebException ex) { //exception handling for testing string errorMessage = ex.ToString(); errorMessage = (errorMessage.Length > 1000) ? errorMessage.Substring(0, 1000) : errorMessage; Response.Redirect("~/PaymentErrorWebForm.aspx?error=" + HttpUtility.UrlEncode(errorMessage)); } XDocument xmlDoc = XDocument.Parse(queryResponse); XElement statusNode = (XElement)xmlDoc.FirstNode; string statusValue = statusNode.Value; this.queryResponseMessage.Text = PaymentUtils.GetPaymentResponseStatusMessage(statusValue); XElement tradeElem = (XElement)xmlDoc.FirstNode; XElement statusElem = (XElement)tradeElem.FirstNode; this.tradeBegin.Text = tradeElem.Name.ToString(); this.tradeEnd.Text = tradeElem.Name.ToString(); this.statusBegin.Text = statusElem.Name.ToString(); this.statusEnd.Text = statusElem.Name.ToString(); this.statusValue.Text = statusElem.Value; }
/// <summary> /// 24. Calculates MAC, MD5-turvatarkiste lasketaan. /// This method uses /// <see cref="PaymentUtils.CalculateMD5HashUTF8(string)"/> /// </summary> /// <returns>MAC</returns> public string CalculateMac() { string macString = ""; string macDelimiter = "+"; macString = this.Version + macDelimiter + //1. P this.Stamp + macDelimiter + // 2. P this.Amount + macDelimiter + // 3. P this.Reference + macDelimiter + // 4. P this.Message + macDelimiter + // 5. V this.Language + macDelimiter + // 6. V this.MerchantId + macDelimiter + // 7. P this.ReturnUrl + macDelimiter + // 8. P this.CancelUrl + macDelimiter + // 9. P this.RejectUrl + macDelimiter + // 10. V this.DelayedUrl + macDelimiter + // 11. V this.Country + macDelimiter + // 12. V this.Currency + macDelimiter + // 13. P this.Device + macDelimiter + // 14. P this.Content + macDelimiter + // 15. P this.Type + macDelimiter + // 16. P this.Algorithm + macDelimiter + // 17. P this.DeliveryDate + macDelimiter + // 18. P this.FirstName + macDelimiter + // 19. V this.FamilyName + macDelimiter + // 20. V this.Address + macDelimiter + // 21. V this.Postcode + macDelimiter + // 22. V this.PostOffice + macDelimiter + // 23. V this.MerchantSecretKey; macString = PaymentUtils.CalculateMD5HashUTF8(macString); //24. this.MAC = macString; return(macString); }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { //the below creates for example //URL: http://localhost:53416/PaymentResponseWebForm.aspx"; string urlBeginning = this.TestUrl(); string returnURL = urlBeginning + "/PaymentResponseWebForm.aspx"; string cancelURL = urlBeginning + "/PaymentResponseWebForm.aspx"; string rejectURL = urlBeginning + "/PaymentResponseWebForm.aspx"; string delayedURL = urlBeginning + "/PaymentResponseWebForm.aspx"; //Create Payment Payment payment = new Payment(); //set merchant data (required) payment.InitializeValues(merchantId, merchantSecretKey); //other required parameters payment.Stamp = DateTime.Now.ToString("MMddyyyyhhmmssfff"); string modifiedAmount = PaymentUtils.ModifyAmount(this.AmountTextBox.Text); // remove comma or dot payment.Amount = modifiedAmount; // 1 Euro minimum purchase (100 cents) Session["Amount"] = modifiedAmount; //store Amount in Session for Query (just for testing) payment.Reference = "123456"; payment.ReturnUrl = returnURL; payment.CancelUrl = cancelURL; payment.DeliveryDate = DateTime.Now.ToString("yyyyMMdd"); payment.Language = this.LanguageDropDownList.SelectedValue; // (required param) payment.Country = "FIN"; // (required) payment.Device = this.DeviceDropDownList.SelectedValue; //HTML or XML //Optional payment.RejectUrl = rejectURL; payment.DelayedUrl = delayedURL; payment.FirstName = this.FirstNameTextBox.Text; payment.FamilyName = this.FamilyNameTextBox.Text; payment.Address = this.AddressTextBox.Text; payment.Postcode = this.PostcodeTextBox.Text; payment.PostOffice = this.PostcodeTextBox.Text; payment.Message = this.MessageTextBox.Text; payment.Validate(); //optional validation (Checkout Finland validates data too) //Send payment data to Checkout Finland, //then make received payment options available //to the Web Form try { this.BankPaymentOptions = CheckoutClient.postPaymentData(payment.FormData()); } catch (WebException ex) { //exception handling for testing string errorMessage = ex.ToString(); errorMessage = (errorMessage.Length > 1000) ? errorMessage.Substring(0, 1000) : errorMessage; Response.Redirect("~/PaymentErrorWebForm.aspx?error=" + HttpUtility.UrlEncode(errorMessage)); } //if device HTML (1), then use WebForm for HTML page if (payment.Device.Equals(Checkout.Payment.Device_HTML)) { Server.Transfer("PaymentOptionsHTML.aspx"); } else //WebForm for XML format { this.Payment = payment; Server.Transfer("PaymentOptionsXML.aspx"); } } }