public void ProcessRequest(HttpContext context)
        {
            string merchantId = WebConfigurationManager.AppSettings["MerchantId"];

            var processor = new HostedPaymentProcessor(merchantId, new HttpContextWrapper(context));

            try
            {
                if (!processor.ValidateRequest()) {
                    throw new InvalidOperationException("Request came from an invalid source");
                }

                var result = new ServerTransactionResult(context.Request.Form);

                processor.ValidateResult(result); // will throw if merchant ids do not match

                // at this point we can get order and work with the result
                if (result.Successful)
                {
                    // update our order to say payment sucessful
                }

                // now we need to let Cardsave know we've received the result
                context.Response.Write(
                    processor.CreateServerResponseString(TransactionStatus.Successful));

            }
            catch (Exception ex)
            {
                // let cardsave know there was a problem
                context.Response.Write(
                    processor.CreateServerResponseString(TransactionStatus.Exception, ex.Message));
            }
        }
示例#2
0
 /// <summary>
 /// Performs basic validation of the transaction result (you should also implement your own e.g. check amounts against order)
 /// </summary>
 /// <param name="result">Transaction result</param>
 public void ValidateResult(ServerTransactionResult result)
 {
     if (!(result.MerchantID.Equals(result.MerchantID, StringComparison.InvariantCultureIgnoreCase)))
     {
         throw new Exception("The merchant id of the result is invalid");
     }
 }
 /// <summary>
 /// Performs basic validation of the transaction result (you should also implement your own e.g. check amounts against order)
 /// </summary>
 /// <param name="result">Transaction result</param>
 public void ValidateResult(ServerTransactionResult result)
 {
     if (!(result.MerchantID.Equals(result.MerchantID, StringComparison.InvariantCultureIgnoreCase)))
         throw new Exception("The merchant id of the result is invalid");
 }