public void ProcessRequest(HttpContext hcHttpContext) { StringBuilder sbOutputString; int nStatusCode = 30; string szMessage = ""; string szHashDigest; TransactionResult trTransactionResult; string szUpdateOrderMessage; sbOutputString = new StringBuilder(); try { if (!PaymentFormHelper.GetTransactionResultFromPostVariables(hcHttpContext.Request.Form, out trTransactionResult, out szHashDigest, out szMessage)) { nStatusCode = 30; } else { if (!PaymentFormHelper.ReportTransactionResults(trTransactionResult, out szUpdateOrderMessage)) { nStatusCode = 30; szMessage = szMessage + szUpdateOrderMessage; } else { nStatusCode = 0; } } } catch (Exception exc) { nStatusCode = 30; szMessage = exc.Message; } finally { if (nStatusCode != 0 && String.IsNullOrEmpty(szMessage)) { szMessage = "Unknown error"; } } hcHttpContext.Response.ContentType = "text/plain"; sbOutputString.AppendFormat("StatusCode={0}&Message={1}", nStatusCode, szMessage); hcHttpContext.Response.Write(sbOutputString.ToString()); }
void Application_Start(object sender, EventArgs e) { // Code that runs on application startup // get the MerchantID and Password from the config file m_szMerchantID = ConfigurationManager.AppSettings["MerchantID"]; m_szPassword = ConfigurationManager.AppSettings["Password"]; // get the PaymentProcessorDomain m_szPaymentProcessorDomain = ConfigurationManager.AppSettings["PaymentProcessorDomain"]; // get the PreSharedKey m_szPreSharedKey = ConfigurationManager.AppSettings["PreSharedKey"]; // get the HashMethod m_hmHashMethod = PaymentFormHelper.GetHashMethod(ConfigurationManager.AppSettings["HashMethod"]); // get the ResultDeliveryMethod m_rdmResultDeliveryMethod = PaymentFormHelper.GetResultDeliveryMethod(ConfigurationManager.AppSettings["ResultDeliveryMethod"]); }
protected void Page_Load(object sender, EventArgs e) { string szStringToHash; m_szMerchantID = Global.MerchantID; m_szResultDeliveryMethod = PaymentFormHelper.GetResultDeliveryMethod(Global.ResultDeliveryMethod); m_szFormAction = "https://mms." + Global.PaymentProcessorDomain + "/Pages/PublicPages/PaymentForm.aspx"; // the amount in *minor* currency (i.e. £10.00 passed as "1000") m_szAmount = Convert.ToString(1000); // the currency - ISO 4217 3-digit numeric (e.g. GBP = 826) m_szCurrencyCode = Convert.ToString(826); // order ID m_szOrderID = "Order-1234"; // the transaction type - can be SALE or PREAUTH m_szTransactionType = "SALE"; // the GMT/UTC relative date/time for the transaction (MUST either be in GMT/UTC // or MUST include the correct timezone offset) m_szTransactionDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss zzz"); // order description m_szOrderDescription = "Teste"; // these variables allow the payment form to be "seeded" with initial values m_szCustomerName = "Felipe"; m_szAddress1 = "14 Some Address"; m_szAddress2 = ""; m_szAddress3 = ""; m_szAddress4 = ""; m_szCity = "Some City"; m_szState = "Some State"; m_szPostCode = "PO57 0DE"; // the country code - ISO 3166-1 3-digit numeric (e.g. UK = 826) m_szCountryCode = Convert.ToString(826); // use these to control which fields on the hosted payment form are // mandatory m_szCV2Mandatory = Convert.ToString(true); m_szAddress1Mandatory = Convert.ToString(false); m_szCityMandatory = Convert.ToString(false); m_szPostCodeMandatory = Convert.ToString(false); m_szStateMandatory = Convert.ToString(false); m_szCountryMandatory = Convert.ToString(false); // the URL on this system that the payment form will push the results to (only applicable for // ResultDeliveryMethod = "SERVER") if (Global.ResultDeliveryMethod != RESULT_DELIVERY_METHOD.SERVER) { m_szServerResultURL = ""; } else { m_szServerResultURL = PaymentFormHelper.GetSiteSecureBaseURL(Request) + "ReceiveTransactionResult.aspx"; } // set this to true if you want the hosted payment form to display the transaction result // to the customer (only applicable for ResultDeliveryMethod = "SERVER") if (Global.ResultDeliveryMethod != RESULT_DELIVERY_METHOD.SERVER) { m_szPaymentFormDisplaysResult = ""; } else { m_szPaymentFormDisplaysResult = Convert.ToString(false); } // set this to true if you want the customer to be able to cancel the transaction process once they // are on the payment form m_szDisplayCancelButton = Convert.ToString(false); // the callback URL on this site that will display the transaction result to the customer // (always required unless ResultDeliveryMethod = "SERVER" and PaymentFormDisplaysResult = "true") if (Global.ResultDeliveryMethod == RESULT_DELIVERY_METHOD.SERVER && Convert.ToBoolean(m_szPaymentFormDisplaysResult) && !Convert.ToBoolean(m_szDisplayCancelButton)) { m_szCallbackURL = ""; } else { m_szCallbackURL = PaymentFormHelper.GetSiteSecureBaseURL(Request) + "DisplayTransactionResult.aspx?MyVariable=1234"; } // get the string to be hashed szStringToHash = PaymentFormHelper.GenerateStringToHash(Global.MerchantID, Global.Password, m_szAmount, m_szCurrencyCode, m_szOrderID, m_szTransactionType, m_szTransactionDateTime, m_szDisplayCancelButton, m_szCallbackURL, m_szOrderDescription, m_szCustomerName, m_szAddress1, m_szAddress2, m_szAddress3, m_szAddress4, m_szCity, m_szState, m_szPostCode, m_szCountryCode, m_szCV2Mandatory, m_szAddress1Mandatory, m_szCityMandatory, m_szPostCodeMandatory, m_szStateMandatory, m_szCountryMandatory, PaymentFormHelper.GetResultDeliveryMethod(Global.ResultDeliveryMethod), m_szServerResultURL, m_szPaymentFormDisplaysResult, Global.PreSharedKey, Global.HashMethod); // pass this string into the hash function to create the hash digest m_szHashDigest = PaymentFormHelper.CalculateHashDigest(szStringToHash, Global.PreSharedKey, Global.HashMethod); lbAmount.Text = m_szAmount; lbCurrency.Text = m_szCurrencyCode; lbOrderID.Text = m_szOrderID; lbOrderDescription.Text = m_szOrderDescription; }
protected void Page_Load(object sender, EventArgs e) { TransactionResult trTransactionResult; string szMessage; string szMessageClass; bool boResultValidationSuccessful; string szValidateErrorMessage; bool boDuplicateTransaction; string szPreviousTransactionMessage; string szPaymentFormResultHandler; string szOutputMessage; // what we do here depends on the ResultDeliveryMethod boDuplicateTransaction = false; szPreviousTransactionMessage = ""; boResultValidationSuccessful = false; szValidateErrorMessage = null; trTransactionResult = null; // check if transaction was cancelled if (Request.QueryString["StatusCode"] != null && Request.QueryString["StatusCode"] == "25") { // validate cancel result boResultValidationSuccessful = PaymentFormHelper.ValidateTransactionResult_CANCEL(Global.MerchantID, Global.Password, Global.PreSharedKey, Global.HashMethod, Request.QueryString, out trTransactionResult, out szValidateErrorMessage); // the results need to be stored here as this is the first time // they will have touched this system if (boResultValidationSuccessful) { if (!PaymentFormHelper.ReportTransactionResults(trTransactionResult, out szOutputMessage)) { // handle the case where the results aren't stored correctly } } } else { switch (Global.ResultDeliveryMethod) { case RESULT_DELIVERY_METHOD.POST: // the results will be delivered via POST variables to this // page boResultValidationSuccessful = PaymentFormHelper.ValidateTransactionResult_POST(Global.MerchantID, Global.Password, Global.PreSharedKey, Global.HashMethod, Request.Form, out trTransactionResult, out szValidateErrorMessage); // the results need to be stored here as this is the first time // they will have touched this system if (boResultValidationSuccessful) { if (!PaymentFormHelper.ReportTransactionResults(trTransactionResult, out szOutputMessage)) { // handle the case where the results aren't stored correctly } } break; case RESULT_DELIVERY_METHOD.SERVER: // the results have already been delivered via a server-to-server // call from the payment form to the ServerResultURL // need to query these transaction results to display boResultValidationSuccessful = PaymentFormHelper.ValidateTransactionResult_SERVER(Global.MerchantID, Global.Password, Global.PreSharedKey, Global.HashMethod, Request.QueryString, out trTransactionResult, out szValidateErrorMessage); break; case RESULT_DELIVERY_METHOD.SERVER_PULL: // need to query the results from the payment form using the passed // cross reference szPaymentFormResultHandler = "https://mms." + Global.PaymentProcessorDomain + "/Pages/PublicPages/PaymentFormResultHandler.ashx"; boResultValidationSuccessful = PaymentFormHelper.ValidateTransactionResult_SERVER_PULL(Global.MerchantID, Global.Password, Global.PreSharedKey, Global.HashMethod, Request.QueryString, szPaymentFormResultHandler, out trTransactionResult, out szValidateErrorMessage); // the results need to be stored here as this is the first time // they will have touched this system if (boResultValidationSuccessful) { if (!PaymentFormHelper.ReportTransactionResults(trTransactionResult, out szOutputMessage)) { // handle the case where the results aren't stored correctly } } break; } } // display an error message if the transaction result couldn't be validated if (!boResultValidationSuccessful) { szMessageClass = "ErrorMessage"; szMessage = szValidateErrorMessage; } else { switch (trTransactionResult.StatusCode) { case 0: szMessageClass = "SuccessMessage"; break; case 4: szMessageClass = "ErrorMessage"; break; case 5: szMessageClass = "ErrorMessage"; break; case 20: boDuplicateTransaction = true; if (trTransactionResult.PreviousStatusCode.Value == 0) { szMessageClass = "SuccessMessage"; } else { szMessageClass = "ErrorMessage"; } szPreviousTransactionMessage = trTransactionResult.PreviousMessage; break; case 25: szMessageClass = "ErrorMessage"; break; case 30: szMessageClass = "ErrorMessage"; break; default: szMessageClass = "ErrorMessage"; break; } szMessage = trTransactionResult.Message; } lbMessage.Text = szMessage; pnMessagePanel.CssClass = szMessageClass; if (boDuplicateTransaction) { pnDuplicateTransactionPanel.Visible = true; lbPreviousTransactionMessage.Text = szPreviousTransactionMessage; } }