public override PaymentHtmlForm GenerateHtmlForm(Order order, string teaCommerceContinueUrl, string teaCommerceCancelUrl, string teaCommerceCallBackUrl, string teaCommerceCommunicationUrl, IDictionary <string, string> settings) { order.MustNotBeNull("order"); settings.MustNotBeNull("settings"); settings.MustContainKey("MerchantID", "settings"); settings.MustContainKey("TransactionType", "settings"); PaymentHtmlForm htmlForm = new PaymentHtmlForm { Action = "https://mms.paymentsensegateway.com/Pages/PublicPages/PaymentForm.aspx" }; string[] settingsToExclude = new[] { "CancelURL", "streetAddressPropertyAlias", "cityPropertyAlias", "zipCodePropertyAlias", "PreSharedKey", "Password", "Testing" }; htmlForm.InputFields = settings.Where(i => !settingsToExclude.Contains(i.Key)).ToDictionary(i => i.Key, i => i.Value); if (order.CartNumber.Length > 50) { throw new Exception("Cart number of the order can not exceed 50 characters."); } htmlForm.InputFields["OrderID"] = order.CartNumber; Currency currency = CurrencyService.Instance.Get(order.StoreId, order.CurrencyId); if (!Iso4217CurrencyCodes.ContainsKey(currency.IsoCode)) { throw new Exception("You must specify an ISO 4217 currency code for the " + currency.Name + " currency"); } htmlForm.InputFields["CurrencyCode"] = Iso4217CurrencyCodes[currency.IsoCode]; htmlForm.InputFields["Amount"] = (order.TotalPrice.Value.WithVat * 100M).ToString("0", CultureInfo.InvariantCulture); htmlForm.InputFields["CustomerName"] = order.PaymentInformation.FirstName + " " + order.PaymentInformation.LastName; if (settings.ContainsKey("streetAddressPropertyAlias")) { htmlForm.InputFields["Address1"] = order.Properties[settings["streetAddressPropertyAlias"]]; } if (settings.ContainsKey("cityPropertyAlias")) { htmlForm.InputFields["City"] = order.Properties[settings["cityPropertyAlias"]]; } if (order.PaymentInformation.CountryRegionId != null) { htmlForm.InputFields["State"] = CountryRegionService.Instance.Get(order.StoreId, order.PaymentInformation.CountryRegionId.Value).Name; } if (settings.ContainsKey("zipCodePropertyAlias")) { htmlForm.InputFields["PostCode"] = order.Properties[settings["zipCodePropertyAlias"]]; } Country country = CountryService.Instance.Get(order.StoreId, order.PaymentInformation.CountryId); if (!Iso3166CountryCodes.ContainsKey(country.RegionCode)) { throw new Exception("You must specify an ISO 3166 country code for the " + country.Name + " country"); } htmlForm.InputFields["CountryCode"] = Iso3166CountryCodes[country.RegionCode]; htmlForm.InputFields["EmailAddress"] = order.PaymentInformation.Email; htmlForm.InputFields["CallbackURL"] = teaCommerceCallBackUrl; htmlForm.InputFields["ServerResultURL"] = teaCommerceCallBackUrl; htmlForm.InputFields["ResultDeliveryMethod"] = "SERVER"; htmlForm.InputFields["PaymentFormDisplaysResult"] = bool.FalseString; htmlForm.InputFields["TransactionDateTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss zzz"); List <string> keysToHash = new List <string>(); keysToHash.Add("PreSharedKey"); keysToHash.Add("MerchantID"); keysToHash.Add("Password"); keysToHash.Add("Amount"); keysToHash.Add("CurrencyCode"); if (htmlForm.InputFields.ContainsKey("EchoAVSCheckResult")) { keysToHash.Add("EchoAVSCheckResult"); } if (htmlForm.InputFields.ContainsKey("EchoCV2CheckResult")) { keysToHash.Add("EchoCV2CheckResult"); } if (htmlForm.InputFields.ContainsKey("EchoThreeDSecureAuthenticationCheckResult")) { keysToHash.Add("EchoThreeDSecureAuthenticationCheckResult"); } if (htmlForm.InputFields.ContainsKey("EchoCardType")) { keysToHash.Add("EchoCardType"); } if (htmlForm.InputFields.ContainsKey("AVSOverridePolicy")) { keysToHash.Add("AVSOverridePolicy"); } if (htmlForm.InputFields.ContainsKey("CV2OverridePolicy")) { keysToHash.Add("CV2OverridePolicy"); } if (htmlForm.InputFields.ContainsKey("ThreeDSecureOverridePolicy")) { keysToHash.Add("ThreeDSecureOverridePolicy"); } keysToHash.Add("OrderID"); keysToHash.Add("TransactionType"); keysToHash.Add("TransactionDateTime"); keysToHash.Add("CallbackURL"); keysToHash.Add("OrderDescription"); keysToHash.Add("CustomerName"); keysToHash.Add("Address1"); keysToHash.Add("Address2"); keysToHash.Add("Address3"); keysToHash.Add("Address4"); keysToHash.Add("City"); keysToHash.Add("State"); keysToHash.Add("PostCode"); keysToHash.Add("CountryCode"); if (htmlForm.InputFields.ContainsKey("EmailAddress")) { keysToHash.Add("EmailAddress"); } if (htmlForm.InputFields.ContainsKey("PhoneNumber")) { keysToHash.Add("PhoneNumber"); } if (htmlForm.InputFields.ContainsKey("EmailAddressEditable")) { keysToHash.Add("EmailAddressEditable"); } if (htmlForm.InputFields.ContainsKey("PhoneNumberEditable")) { keysToHash.Add("PhoneNumberEditable"); } if (htmlForm.InputFields.ContainsKey("CV2Mandatory")) { keysToHash.Add("CV2Mandatory"); } if (htmlForm.InputFields.ContainsKey("Address1Mandatory")) { keysToHash.Add("Address1Mandatory"); } if (htmlForm.InputFields.ContainsKey("CityMandatory")) { keysToHash.Add("CityMandatory"); } if (htmlForm.InputFields.ContainsKey("PostCodeMandatory")) { keysToHash.Add("PostCodeMandatory"); } if (htmlForm.InputFields.ContainsKey("StateMandatory")) { keysToHash.Add("StateMandatory"); } if (htmlForm.InputFields.ContainsKey("CountryMandatory")) { keysToHash.Add("CountryMandatory"); } keysToHash.Add("ResultDeliveryMethod"); if (htmlForm.InputFields.ContainsKey("ServerResultURL")) { keysToHash.Add("ServerResultURL"); } if (htmlForm.InputFields.ContainsKey("PaymentFormDisplaysResult")) { keysToHash.Add("PaymentFormDisplaysResult"); } if (htmlForm.InputFields.ContainsKey("ServerResultURLCookieVariables")) { keysToHash.Add("ServerResultURLCookieVariables"); } if (htmlForm.InputFields.ContainsKey("ServerResultURLFormVariables")) { keysToHash.Add("ServerResultURLFormVariables"); } if (htmlForm.InputFields.ContainsKey("ServerResultURLQueryStringVariables")) { keysToHash.Add("ServerResultURLQueryStringVariables"); } htmlForm.InputFields["HashDigest"] = CreateHashDigest(keysToHash, settings, htmlForm.InputFields); return(htmlForm); }
public override string ProcessRequest(Order order, HttpRequest request, IDictionary <string, string> settings) { string response = ""; try { order.MustNotBeNull("order"); request.MustNotBeNull("request"); settings.MustNotBeNull("settings"); settings.MustContainKey("profile_id", "settings"); settings.MustContainKey("access_key", "settings"); settings.MustContainKey("locale", "settings"); settings.MustContainKey("transaction_type", "settings"); settings.MustContainKey("phonePropertyAlias", "settings"); settings.MustContainKey("streetAddressPropertyAlias", "settings"); settings.MustContainKey("cityPropertyAlias", "settings"); order.Properties[settings["phonePropertyAlias"]].MustNotBeNullOrEmpty("phone"); order.Properties[settings["streetAddressPropertyAlias"]].MustNotBeNullOrEmpty("street address"); order.Properties[settings["cityPropertyAlias"]].MustNotBeNullOrEmpty("city"); order.PaymentInformation.FirstName.MustNotBeNull("first name"); order.PaymentInformation.LastName.MustNotBeNull("last name"); order.PaymentInformation.Email.MustNotBeNull("email"); // If in test mode, write out the form data to a text file if (settings.ContainsKey("mode") && settings["mode"] == "test") { LogRequest <CyberSource>(request, logPostData: true); } //Generate input fields for the JavaScript post of the inline form IDictionary <string, string> inputFields = new Dictionary <string, string>(); inputFields["profile_id"] = settings["profile_id"]; inputFields["access_key"] = settings["access_key"]; inputFields["override_custom_receipt_page"] = order.Properties["teaCommerceCallBackUrl"]; inputFields["locale"] = settings["locale"]; inputFields["payment_method"] = "card"; inputFields["reference_number"] = order.CartNumber; inputFields["signed_date_time"] = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'"); inputFields["transaction_type"] = settings["transaction_type"]; inputFields["transaction_uuid"] = Guid.NewGuid().ToString(); inputFields["amount"] = order.TotalPrice.Value.WithVat.ToString("0.00", CultureInfo.InvariantCulture); Currency currency = CurrencyService.Instance.Get(order.StoreId, order.CurrencyId); if (!Iso4217CurrencyCodes.ContainsKey(currency.IsoCode)) { throw new Exception("You must specify an ISO 4217 currency code for the " + currency.Name + " currency"); } inputFields["currency"] = currency.IsoCode; inputFields["bill_to_forename"] = order.PaymentInformation.FirstName; inputFields["bill_to_surname"] = order.PaymentInformation.LastName; inputFields["bill_to_email"] = order.PaymentInformation.Email; inputFields["bill_to_phone"] = order.Properties[settings["phonePropertyAlias"]]; inputFields["bill_to_address_line1"] = order.Properties[settings["streetAddressPropertyAlias"]]; inputFields["bill_to_address_city"] = order.Properties[settings["cityPropertyAlias"]]; if (settings.ContainsKey("zipCodePropertyAlias")) { inputFields["bill_to_address_postal_code"] = order.Properties[settings["zipCodePropertyAlias"]]; } Country country = CountryService.Instance.Get(order.StoreId, order.PaymentInformation.CountryId); if (!Iso3166CountryCodes.ContainsKey(country.RegionCode)) { throw new Exception("You must specify an ISO 3166 country code for the " + country.Name + " country"); } inputFields["bill_to_address_country"] = country.RegionCode; inputFields["bill_to_address_state"] = order.PaymentInformation.CountryRegionId != null?CountryRegionService.Instance.Get(order.StoreId, order.PaymentInformation.CountryRegionId.Value).RegionCode : ""; inputFields["card_type"] = request.Form["card_type"]; inputFields["card_expiry_date"] = request.Form["card_expiry_date"]; inputFields["card_cvn"] = request.Form["card_cvn"]; inputFields["card_number"] = request.Form["card_number"]; inputFields["unsigned_field_names"] = ""; inputFields["signed_field_names"] = string.Join(",", inputFields.Select(kvp => kvp.Key)) + ",signed_field_names"; //Signature and card number should not be signed inputFields["signature"] = CreateSignature(inputFields, settings); foreach (KeyValuePair <string, string> kvp in inputFields) { if (request.Form[kvp.Key] != "") { response += "<input type=\"hidden\" name=\"" + kvp.Key + "\" value=\"" + kvp.Value + "\" />"; } } } catch (Exception exp) { LoggingService.Instance.Error <CyberSource>("CyberSource(" + order.CartNumber + ") - ProcessRequest", exp); } return(response); }
public static string InvalidStateCode(string state, Iso3166CountryCodes countryCode) { return String.Format(InvalidUSStateCodeTemplate, state, countryCode.ToString()); }