using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CodeCafe.Web; using System.Configuration; public partial class ProcessPayment : System.Web.UI.Page { /**********************************************************************************************************/ /// /// Handles the Load event of the Page control. /// /// The source of the event. /// The instance containing the event data. protected void Page_Load(object sender, EventArgs e) { //ltDebug.Text = Request.QueryString.ToString(); if (!IsPostBack) HandleResult(); } /**********************************************************************************************************/ /// /// Displays the result info. /// /// The code. /// The trans ID. /// public string DisplayResultInfo(int Code, string TransID) { string result = ""; switch (Code) { case 0: result = "N/A"; break; case 990017: result = "Transaction approved!

A copy of your order has been emailed to you. One of our sales consultants will contact you shortly."; break; case 900003: result = "Transaction declined due to insufficient funds.

One of our sales consultants will contact you shortly to discuss alternate arrangements."; break; case 900007: result = "Transaction declined.

One of our sales consultants will contact you shortly to discuss alternate arrangements."; break; case 900004: result = "Invalid card number

The PayGate payment portal have informed us that you have used an invalid card. If you believe this is an error please contact PayGate and use the following Transaction ID as a reference: " + TransID; break; case 990022: result = "Transaction unprocessed

One of our sales consultants will contact you shortly to discuss alternate arrangements."; break; } return result; } /**********************************************************************************************************/ /// /// Handles the transaction result. /// private void HandleResult() { try { string PAYGATE_ID = Request["PAYGATE_ID"]; string REFERENCE = Request["REFERENCE"]; string AMOUNT = Request["AMOUNT"]; string TRANSACTION_STATUS = Request["TRANSACTION_STATUS"]; string RESULT_CODE = Request["RESULT_CODE"]; string RESULT_DESC = Request["RESULT_DESC"]; string AUTH_CODE = Request["AUTH_CODE"]; string TRANSACTION_ID = Request["TRANSACTION_ID"]; string RISK_INDICATOR = Request["RISK_INDICATOR"]; string CHECKSUM = Request["CHECKSUM"]; string SUBSID = ""; if (!string.IsNullOrEmpty(Request["SUBSCRIPTION_ID"])) SUBSID = Request["SUBSCRIPTION_ID"]; //string PAYGATE_ID = "10014187480"; //string REFERENCE = "BW00017"; //string AMOUNT = "60000"; //string TRANSACTION_STATUS = "1"; //string RESULT_CODE = "990017"; //string RESULT_DESC = "Auth Done"; //string AUTH_CODE = "00896616"; //string TRANSACTION_ID = "16876108"; //string RISK_INDICATOR = "AX"; //string CHECKSUM = "F8E9669B568AB3AA36E5F9A5F363EF0A"; bool ok = false; if (string.IsNullOrEmpty(SUBSID)) //not a recurring payment... { PayGate pg = new PayGate(); pg.PayGate_ID = PAYGATE_ID; //todo: remove this once paygate sort themselves out... pg.Reference = REFERENCE; ok = pg.ConfirmChecksumResult(AMOUNT, TRANSACTION_STATUS, RESULT_CODE, RESULT_DESC, AUTH_CODE, TRANSACTION_ID, RISK_INDICATOR, CHECKSUM); } else { PayGateSubscriptions pg = new PayGateSubscriptions(); pg.PayGate_ID = PAYGATE_ID; //todo: remove this once paygate sort themselves out... pg.Reference = REFERENCE; //pg ok = pg.ConfirmChecksumResult(AMOUNT, TRANSACTION_STATUS, RESULT_CODE, RESULT_DESC, AUTH_CODE, TRANSACTION_ID, SUBSID, RISK_INDICATOR, CHECKSUM); } clsShoppingBasket basket = new clsShoppingBasket(); string basketItems = ""; //RESULT_CODE = "990022"; if (ok) { ltDebug.Text = "Checksum passed"; basket.Load(Utils.StrToIntDef(REFERENCE.Replace("BW", ""), 0)); if (basket.sb_id > 0) { PayGate pg = new PayGate(); pnlReceipt.Visible = RESULT_CODE.Equals("990017"); ltStatus.Text = DisplayResultInfo(Utils.StrToIntDef(RESULT_CODE, 0), TRANSACTION_ID); basket.sb_transactionStatus = Utils.StrToIntDef(TRANSACTION_STATUS, 0); basket.sb_resultCode = Utils.StrToIntDef(RESULT_CODE, 0); basket.sb_authCode = AUTH_CODE; basket.sb_transId = TRANSACTION_ID; basket.sb_subsId = SUBSID; basket.sb_riskIndicator = RISK_INDICATOR; basket.sb_checksum = CHECKSUM; basket.sb_status = pg.ResultCodeAsStatus(basket.sb_resultCode); basket.Save(); basket.InvoiceID = basket.sb_id; clsBasketItem items = new clsBasketItem(); basketItems = items.ListForEmail(basket.sb_id, false); ltStatus.Text += "

Order Summary

" + basketItems; string ClientEmail = ""; string OrderEmail = ""; clsUserInfo user = new clsUserInfo(); user.Load(basket.ui_id); string Reference = "BW" + basket.sb_id.ToString("00000"); if (pnlReceipt.Visible) { ClientEmail = "Dear " + user.ui_firstName + " " + user.ui_surname + ",

"; ClientEmail += "Order Reference: " + Reference + "

"; ClientEmail += "Thank you! You successfully purchased the following on " + basket.sb_date.ToString("dd MMMM yyyy") + " at " + basket.sb_date.ToString("HH:mm") + ":
"; ClientEmail += basketItems; if (items.IsRecurringPayment) { ClientEmail += Global.RecurringPaymentInfo(basket.sb_date, items.MaxTerm); //DateTime Payment = new DateTime(basket.sb_date.AddMonths(1).Year, basket.sb_date.AddMonths(1).Month, 1); //ClientEmail += "
Your first monthly payment will reflect immediately, subsequent payments will reflect on the 1st of each month starting from
"; //ClientEmail += "1st " + Payment.ToString("MMMM yyyy") + " until 1st " + Payment.AddMonths(items.MaxTerm - 2).ToString("MMMM yyyy") + "

"; } ClientEmail += "
One of our sales consultants will be in contact with you shortly.

"; ClientEmail += "Yours sincerely,
The BluWave CRM Sales Team."; Global.SendBluWaveEmail(user.ui_email, "BluWave CRM Order", ClientEmail, ConfigurationManager.AppSettings.Get("OrderAddress")); } OrderEmail = "New Online Purchase on " + basket.sb_date.ToString("dd MMMM yyyy") + " at " + basket.sb_date.ToString("HH:mm") + "

"; OrderEmail += "Order Reference: " + Reference + "

"; OrderEmail += user.ToEmail() + "
"; OrderEmail += basketItems + "
"; OrderEmail += "Order status: " + pg.GetTransactionStatus(Utils.StrToIntDef(TRANSACTION_STATUS, 0)) + "
"; OrderEmail += "Result code: " + pg.GetResultCode(Utils.StrToIntDef(RESULT_CODE, 0)) + "
"; OrderEmail += "Auth code: " + AUTH_CODE + "
"; OrderEmail += "Transaction ID: " + TRANSACTION_ID + "
"; if (!string.IsNullOrEmpty(SUBSID)) { OrderEmail += "Subscription ID: " + SUBSID + "
"; OrderEmail += "Subscription Period: " + items.MaxTerm.ToString() + "
"; } OrderEmail += "Risk Indicator: " + pg.GetRiskIndicator(RISK_INDICATOR) + "
"; Global.SendBluWaveEmail(ConfigurationManager.AppSettings.Get("OrderAddress"), "BluWave CRM Online Purchase", OrderEmail, user.ui_email); } else { ltStatus.Text = "An invalid order number was used!

Please try again."; } } else { ltDebug.Text = "Checksum failed"; ltStatus.Text = "Invalid data was returned!

Please try again."; } //ltDebug.Text += "
Checksum Result: " + pg.GetChecksumResult(AMOUNT, TRANSACTION_STATUS, RESULT_CODE, RESULT_DESC, AUTH_CODE, TRANSACTION_ID, RISK_INDICATOR, CHECKSUM); ltDebug.Text += "
PayGate ID: " + PAYGATE_ID; ltDebug.Text += "
Reference: " + REFERENCE; ltDebug.Text += "
Amount: " + AMOUNT; ltDebug.Text += "
Transaction_Status: " + TRANSACTION_STATUS; ltDebug.Text += "
Result_Code: " + RESULT_CODE; ltDebug.Text += "
Result_Desc: " + RESULT_DESC; ltDebug.Text += "
Auth_Code: " + AUTH_CODE; ltDebug.Text += "
Transaction_ID: " + TRANSACTION_ID; ltDebug.Text += "
Subscription_ID: " + SUBSID; ltDebug.Text += "
Risk_Indicator: " + RISK_INDICATOR; ltDebug.Text += "
Checksum: " + CHECKSUM.ToUpper(); } catch (Exception exp) { Logger.Log(exp); ltStatus.Text = "An error occurred!

If possible one of our consultants will contact you."; } } /**********************************************************************************************************/ }