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)); } }
protected void btnSubmit_Click(object sender, EventArgs e) { decimal amount = 0M; Decimal.TryParse(txtAmount.Text, out amount); if (amount == 0) { return; } // create transaction // get settings from web.config string merchantId = WebConfigurationManager.AppSettings["MerchantID"]; string merchantPassword = WebConfigurationManager.AppSettings["MerchantPassword"]; string preSharedKey = WebConfigurationManager.AppSettings["PreSharedKey"]; string serverCallBack = WebConfigurationManager.AppSettings["ServerCallBackUrl"]; string callBackUrl = WebConfigurationManager.AppSettings["CallbackUrl"]; string postUrl = "https://mms.cardsaveonlinepayments.com/Pages/PublicPages/PaymentForm.aspx"; var request = new HostedTransactionRequest { Amount = Convert.ToInt32(amount * 100), OrderID = "123456", OrderDescription = "Test Order", TransactionType = TransactionType.SALE, CallbackURL = callBackUrl, ServerResultURL = serverCallBack }; var processor = new HostedPaymentProcessor(merchantId, new HttpContextWrapper(HttpContext.Current)); processor.SubmitTransaction(request, merchantPassword, preSharedKey, postUrl); }