/// <summary> /// Calls GestPay's decryption service to decode the information we received. /// </summary> /// <param name="shop"></param> /// <param name="cryptedInfo"></param> /// <param name="testEnvironmanet"></param> /// <returns></returns> private XmlNode Decrypt(string shop, string cryptedInfo, bool testEnvironmanet) { XmlNode outcome; if (testEnvironmanet) { string endpoint = string.Format(Endpoints.TestWSEntry, Endpoints.CryptDecryptEndPoint); endpoint = endpoint.Substring(0, endpoint.Length - 4); BasicHttpBinding binding = new BasicHttpBinding(); endpoint = Regex.Replace(endpoint, "(https)", "http"); //https gives errors EndpointAddress address = new EndpointAddress(endpoint); using (var client = new CryptDecryptTest.WSCryptDecryptSoapClient(binding, address)) { outcome = client.Decrypt(shop, cryptedInfo); } } else { string endpoint = string.Format(Endpoints.ProdWSEntry, Endpoints.CryptDecryptEndPoint); endpoint = endpoint.Substring(0, endpoint.Length - 4); BasicHttpBinding binding = new BasicHttpBinding(); endpoint = Regex.Replace(endpoint, "(https)", "http"); //https gives errors EndpointAddress address = new EndpointAddress(endpoint); using (var client = new CryptDecryptProd.WSCryptDecryptSoapClient(binding, address)) { outcome = client.Decrypt(shop, cryptedInfo); } } return(outcome); }
/// <summary> /// This gets called by the Action actually starting the transaction. /// </summary> /// <param name="paymentId">The id corresponding to a <type>PaymentRecord</type> for the transaction we want to start.</param> /// <returns>The url of a page to which we redirect the client's browser to complete the payment.</returns> private string StartGestPayTransactionURL(int paymentId) { var settings = _orchardServices .WorkContext .CurrentSite .As <PaymentGestPaySettingsPart>(); var pRecord = GetPaymentInfo(paymentId); if (pRecord.PaymentTransactionComplete) { //this avoids repeat payments when the user is dumb and goes back in the browser to try and pay again return(GetPaymentInfoUrl(paymentId)); } var user = _orchardServices.WorkContext.CurrentUser; if (pRecord.UserId > 0 && pRecord.UserId != user.Id) { //not the same user who started the payment throw new Exception(); } var gpt = new GestPayTransaction(pRecord); //parameter validation if (gpt == null) { //Log the error Logger.Error(T("Transaction object cannot be null.").Text); //update the PaymentRecord for this transaction EndPayment(paymentId, false, null, T("Failed to create a transaction object based on the PaymentRecord").Text); //return the url of a suitable error page (call this.GetPaymentInfoUrl after inserting the error in the PaymentRecord) return(GetPaymentInfoUrl(paymentId)); } try { Validator.ValidateObject(gpt, new ValidationContext(gpt), true); } catch (Exception ex) { //Log the error Logger.Error(T("Transaction information not valid: {0}", ex.Message).Text); //update the PaymentRecord for this transaction EndPayment(paymentId, false, null, T("Transaction information not valid: {0}", ex.Message).Text); //return the URL of a suitable error page (call this.GetPaymentInfoUrl after inserting the error in the PaymentRecord) return(GetPaymentInfoUrl(paymentId)); } //get the encrypted parameter string EncryptDecryptTransactionResult res = null; string urlFormat = ""; XmlNode encryptXML = null; try { if (settings.UseTestEnvironment) { string endpoint = string.Format(Endpoints.TestWSEntry, Endpoints.CryptDecryptEndPoint); endpoint = endpoint.Substring(0, endpoint.Length - 4); //WSHttpBinding binding = new WSHttpBinding(); //binding.Security.Mode = SecurityMode.Transport; //binding.MessageEncoding = WSMessageEncoding.Text; BasicHttpBinding binding = new BasicHttpBinding(); endpoint = Regex.Replace(endpoint, "(https)", "http"); //https gives errors EndpointAddress address = new EndpointAddress(endpoint); using (var client = new CryptDecryptTest.WSCryptDecryptSoapClient(binding, address)) { encryptXML = client.Encrypt( shopLogin: settings.GestPayShopLogin, uicCode: gpt.uicCode, amount: gpt.amount, shopTransactionId: gpt.shopTransactionID, cardNumber: gpt.cardNumber, expiryMonth: gpt.expiryMonth, expiryYear: gpt.expiryYear, buyerName: gpt.buyerName, buyerEmail: gpt.buyerEmail, languageId: gpt.languageId, cvv: gpt.cvv, customInfo: gpt.customInfo, requestToken: gpt.requestToken, ppSellerProtection: gpt.ppSellerProtection, shippingDetails: gpt.shippingDetails.TestVersion(), paymentTypes: gpt.paymentTypes.ToArray(), paymentTypeDetail: gpt.paymentTypeDetail.TestVersion(), redFraudPrevention: gpt.redFraudPrevention, Red_CustomerInfo: gpt.Red_CustomerInfo.TestVersion(), Red_ShippingInfo: gpt.Red_ShippingInfo.TestVersion(), Red_BillingInfo: gpt.Red_BillingInfo.TestVersion(), Red_CustomerData: gpt.Red_CustomerData.TestVersion(), Red_CustomInfo: gpt.Red_CustomInfo.ToArray(), Red_Items: gpt.Red_Items.TestVersion(), Consel_MerchantPro: gpt.Consel_MerchantPro, Consel_CustomerInfo: gpt.Consel_CustomerInfo.TestVersion(), payPalBillingAgreementDescription: gpt.payPalBillingAgreementDescription, OrderDetails: gpt.OrderDetails.TestVersion() ); urlFormat = string.Format(Endpoints.TestPayEntry, Endpoints.PaymentPage); } } else { string endpoint = string.Format(Endpoints.ProdWSEntry, Endpoints.CryptDecryptEndPoint); endpoint = endpoint.Substring(0, endpoint.Length - 4); BasicHttpBinding binding = new BasicHttpBinding(); endpoint = Regex.Replace(endpoint, "(https)", "http"); //https gives errors EndpointAddress address = new EndpointAddress(endpoint); using (var client = new CryptDecryptProd.WSCryptDecryptSoapClient(binding, address)) { encryptXML = client.Encrypt( shopLogin: settings.GestPayShopLogin, uicCode: gpt.uicCode, amount: gpt.amount, shopTransactionId: gpt.shopTransactionID, cardNumber: gpt.cardNumber, expiryMonth: gpt.expiryMonth, expiryYear: gpt.expiryYear, buyerName: gpt.buyerName, buyerEmail: gpt.buyerEmail, languageId: gpt.languageId, cvv: gpt.cvv, customInfo: gpt.customInfo, requestToken: gpt.requestToken, ppSellerProtection: gpt.ppSellerProtection, shippingDetails: gpt.shippingDetails.ProdVersion(), paymentTypes: gpt.paymentTypes.ToArray(), paymentTypeDetail: gpt.paymentTypeDetail.ProdVersion(), redFraudPrevention: gpt.redFraudPrevention, Red_CustomerInfo: gpt.Red_CustomerInfo.ProdVersion(), Red_ShippingInfo: gpt.Red_ShippingInfo.ProdVersion(), Red_BillingInfo: gpt.Red_BillingInfo.ProdVersion(), Red_CustomerData: gpt.Red_CustomerData.ProdVersion(), Red_CustomInfo: gpt.Red_CustomInfo.ToArray(), Red_Items: gpt.Red_Items.ProdVersion(), Consel_MerchantPro: gpt.Consel_MerchantPro, Consel_CustomerInfo: gpt.Consel_CustomerInfo.ProdVersion(), payPalBillingAgreementDescription: gpt.payPalBillingAgreementDescription, OrderDetails: gpt.OrderDetails.ProdVersion() ); urlFormat = string.Format(Endpoints.ProdPayEntry, Endpoints.PaymentPage); } } } catch (Exception ex) { //Log the error LocalizedString error = T("Request to GestPay service failed: {0}", ex.Message); Logger.Error(error.Text); //update the PaymentRecord for this transaction EndPayment(paymentId, false, null, error.Text); //return the URL of a suitable error page (call this.GetPaymentInfoUrl after inserting the error in the PaymentRecord) return(GetPaymentInfoUrl(paymentId)); } try { res = new EncryptDecryptTransactionResult(encryptXML); Validator.ValidateObject(res, new ValidationContext(res), true); } catch (Exception ex) { //Log the error Logger.Error(T("Validation problems on the response received: {0}", ex.Message).Text); //update the PaymentRecord for this transaction EndPayment(paymentId, false, null, T("Validation problems on the response received: {0}", ex.Message).Text); //return the URL of a suitable error page (call this.GetPaymentInfoUrl after inserting the error in the PaymentRecord) return(GetPaymentInfoUrl(paymentId)); } if (res.TransactionResult.ToUpperInvariant() == "OK") { return(string.Format(urlFormat, settings.GestPayShopLogin, res.CryptDecryptString)); } else { //Log the error LocalizedString error = T("Remote service replied with an error. Error {0}: {1}", res.ErrorCode, res.ErrorDescription); Logger.Error(error.Text); //update the PaymentRecord for this transaction EndPayment(paymentId, false, null, error.Text); //return the URL of a suitable error page (call this.GetPaymentInfoUrl after inserting the error in the PaymentRecord) return(GetPaymentInfoUrl(paymentId)); } }