コード例 #1
0
        public void ProcessPaymentEpagosMercantil(ProcessPaymentRequest processPaymentRequest, out ProcessPaymentResult result)
        {
            try
            {
                ProcessPaymentResult _result = new ProcessPaymentResult();
                EpagosMercantil      items   = new EpagosMercantil {
                    //URLConnection = _settingService.GetSettingByKey(paymentmethod+ ".currency".ToLower(), "", _storeContext.CurrentStore.Id, true),
                    //KeyId = _settingService.GetSettingByKey(paymentmethod + ".currency".ToLower(), "", _storeContext.CurrentStore.Id, true),
                    //PublicKey = _settingService.GetSettingByKey(paymentmethod + ".currency".ToLower(), "", _storeContext.CurrentStore.Id, true),
                };
                //using (StreamReader r = new StreamReader("EpagosMercantilsettings.json"))
                //{
                //    string json = r.ReadToEnd();
                //     items = JsonConvert.DeserializeObject<EpagosMercantil>(json);
                //}



                WebRequest __webrequest = WebRequest.Create(items.URLConnection) as HttpWebRequest;

                string PostData =
                    String.Format("KeyId={0}&PublicKeyId={1}&Amount={2}&Description={3}&CardHolder={4}&CardHolderId={5}&CardNumber={6}&CVC={7}&ExpirationDate={8}/{9}&StatusId={10}",
                                  items.KeyId,
                                  items.PublicKey,
                                  processPaymentRequest.OrderTotal,
                                  "Pago+Compra+EcommerceSigo",
                                  processPaymentRequest.CreditCardName.Replace(" ", "+"),
                                  processPaymentRequest.CreditCardNumberId,
                                  processPaymentRequest.CreditCardNumber,
                                  processPaymentRequest.CreditCardCvv2,
                                  processPaymentRequest.CreditCardExpireMonth.ToString("00"),
                                  processPaymentRequest.CreditCardExpireYear,
                                  "c");



                byte[] __postDataStream = Encoding.UTF8.GetBytes(PostData.Replace(" ", string.Empty));

                __webrequest.Method        = "POST";
                __webrequest.ContentType   = "application/x-www-form-urlencoded";
                __webrequest.ContentLength = __postDataStream.Length;
                Stream __requestStream = __webrequest.GetRequestStream();
                __requestStream.Write(__postDataStream, 0, __postDataStream.Length);
                __requestStream.Close();

                // response
                WebResponse  __webresponse      = __webrequest.GetResponse();
                Stream       dataStream         = __webresponse.GetResponseStream();
                StreamReader reader             = new StreamReader(dataStream);
                string       responseFromServer = reader.ReadToEnd();

                EpagosMercantilRSModel __instaRs = JsonConvert.DeserializeObject <EpagosMercantilRSModel>(responseFromServer) as EpagosMercantilRSModel;
                if (__instaRs.Success == true)
                {
                    _result.AuthorizationTransactionId     = " Código del pago:" + __instaRs.Id;
                    _result.AuthorizationTransactionCode   = "Número de referencia del pago:" + __instaRs.Reference;
                    _result.AuthorizationTransactionResult = "Mensaje: " + __instaRs.Message;
                    _result.CaptureTransactionResult       = __instaRs.Voucher;
                    _result.NewPaymentStatus = PaymentStatus.Paid;
                    _epagosMercantilPaymentSettings.TransactMode = TransactMode.AuthorizeAndCapture;
                }
                else
                {
                    string __errorMessage;
                    switch (Convert.ToInt32(__instaRs.Code))
                    {
                    case 400:
                        __errorMessage = "Error al validar los datos enviados: " + __instaRs.Message;
                        break;

                    case 401:
                        __errorMessage = "Error de autenticación, ha ocurrido un error con las llaves utilizadas. " + __instaRs.Message;
                        break;

                    case 403:
                        __errorMessage = "Pago Rechazado por el banco. " + __instaRs.Message;
                        break;

                    case 500:
                        __errorMessage = "Ha Ocurrido un error interno dentro del servidor: " + __instaRs.Message;
                        break;

                    case 503:
                        __errorMessage = "Ha Ocurrido un error al procesar los parámetros de entrada. Revise los datos enviados y vuelva a intentarlo. " + __instaRs.Message;
                        break;

                    default:
                        __errorMessage = "Lo sentimos, no hemos podido procesar su tarjeta de crédito. El mensaje del banco fue: " + __instaRs.Message;
                        break;
                    }
                    _result.AddError(__errorMessage);
                }
                result = _result;
            }
            catch (Exception ex)
            {
                throw new NopException("Error al procesar el pago: " + ex.Message, ex);
            }
        }
コード例 #2
0
        public void ProcessPaymentEpagosMercantil(ProcessPaymentRequest processPaymentRequest, out ProcessPaymentResult result)
        {
            try
            {
                ProcessPaymentResult _result = new ProcessPaymentResult();
                EpagosMercantil      items   = new EpagosMercantil {
                    URLConnection = _settingService.GetSettingByKey("UrlMercantil", "", _storeContext.CurrentStore.Id, true),
                };

                //string idComercio = "104755";
                //string tipotransaccion = "0200";
                string monto     = Convert.ToString(processPaymentRequest.OrderTotal).Replace(".", ",");
                string fechavcto = String.Format(processPaymentRequest.CreditCardExpireMonth.ToString() + processPaymentRequest.CreditCardExpireYear.ToString().Substring(2));

                //                "Pago+Compra+EcommerceSigo",
                //                processPaymentRequest.CreditCardName.Replace(" ", "+"),
                //                processPaymentRequest.CreditCardNumberId,
                //                processPaymentRequest.CreditCardNumber,
                //                processPaymentRequest.CreditCardCvv2,
                //                processPaymentRequest.CreditCardExpireMonth.ToString("00"),
                //                processPaymentRequest.CreditCardExpireYear,
                //                "c");

                //string apikey = Apikey(idComercio, tipotransaccion, Convert.ToString(processPaymentRequest.OrderTotal).Replace(".", ","),
                //                                                     "numerofact" + processPaymentRequest.OrderGuid,
                //                                                     processPaymentRequest.CreditCardNumberId,
                //                                                      processPaymentRequest.CreditCardName.Replace(" ", "+"),
                //                                                      processPaymentRequest.CreditCardNumber,
                //                                                       String.Format(processPaymentRequest.CreditCardExpireMonth.ToString() + processPaymentRequest.CreditCardExpireYear.ToString().Substring(2)),
                //                                                       processPaymentRequest.CreditCardCvv2, "1");

                //var client = new RestClient(items.URLConnection);
                //var request = new RestRequest();
                //string timeStamp = Stopwatch.GetTimestamp().ToString();

                //request.Method = Method.POST;
                //request.AddHeader("x-ibm-client-id", "ba54c4ba-0aba-48ee-a978-1b78392a40a5");
                //request.AddHeader("Apikey", apikey);
                //request.AddHeader("Timestamp", timeStamp);
                //request.AddHeader("Content-Length", apikey.Length.ToString());
                //request.AddHeader("Host", "apimbu.mercantilbanco.com:9443");
                //request.AddHeader("Accept", "application/json");
                //string strJSONContent = "{ \r\n  \"HEADER_PAGO_REQUEST\": { \r\n \"IDENTIFICADOR_UNICO_GLOBAL\": \"900\"," +
                //                                                            " \r\n \"IDENTIFICACION_CANAL\": \"06\", \r\n  " +
                //                                                            "  \"SIGLA_APLICACION\": \"APIC\", \r\n    " +
                //                                                            "\"IDENTIFICACION_USUARIO\": \"66\", \r\n   " +
                //                                                            " \"DIRECCION_IP_CONSUMIDOR\": \"192.237.245.234\", \r\n  " +
                //                                                            "  \"DIRECCION_IP_CLIENTE\": \"200.3.1.8\", \r\n   " +
                //                                                            " \"FECHA_ENVIO_MENSAJE\": \""+DateTime.Now.ToString("YYYYMMDD") +"\", \r\n  " +
                //                                                            "  \"HORA_ENVIO_MENSAJE\": \""+DateTime.Now.ToString("hhmmss") +"\", \r\n" +
                //                                                            "    \"ATRIBUTO_PAGINEO\": \"N\", \r\n  " +
                //                                                            "  \"CLAVE_BUSQUEDA\": \"\""+string.Empty+", \r\n  " +
                //                                                            "  \"CANTIDAD_REGISTROS\": 0 \r\n  }," +
                //                         "\r\n  \"BODY_PAGO_REQUEST\": { \r\n    " +
                //                                                            "\"IDENTIFICADOR_COMERCIO\": " + idComercio + ", \r\n  " +
                //                                                            "\"TIPO_TRANSACCION\": \""+tipotransaccion+"\", \r\n   " +
                //                                                            " \"MONTO_TRANSACCION\": " + monto + ", \r\n    " +
                //                                                            "\"NUMERO_FACTURA\": 88888888888, \r\n " +
                //                                                            "\"IDENTIFICACION_TARJETAHABIENTE\": \""+ processPaymentRequest.CreditCardNumberId + "\", \r\n  " +
                //                                                            "\"NOMBRE_TARJETAHABIENTE\": \""+ processPaymentRequest.CreditCardName + "\", \r\n   " +
                //                                                            "\"NUMERO_TARJETA\": \"" + processPaymentRequest.CreditCardNumber + "\", \r\n  " +
                //                                                             "\"FECHA_VENCIMIENTO_TARJETA\": "+fechavcto+", \r\n\t\"CODIGO_SEGURIDAD_TARJETA\": "+ processPaymentRequest.CreditCardCvv2 + ", " +
                //                                                             "\r\n    \"NUMERO_LOTE\": \"1\" \r\n  } \r\n} \r\n";

                //HttpBrowserCapabilities bc = Request.Browser;
                string claveBanco = "B2CM3rcanti1#";
                string json       = "{" +
                                    " merchant_identify: {"
                                    + "integratorId: 31,"
                                    + "merchantId: 150332,"
                                    + "terminalId:abcde " +
                                    "},"
                                    + "client_identify: {"
                                    + "ipaddress: 10.0.0.1,"
                                    + "browser_agent: Chrome 18.1.3,"
                                    + "mobile: { " +
                                    "manufacturer: Samsung}"
                                    + "},"
                                    + "transaction: {"
                                    + "trx_type: 'compra',"
                                    + "payment_method:'tdc',"
                                    + "card_number:" + processPaymentRequest.CreditCardNumber + ","
                                    + "customer_id:" + processPaymentRequest.CreditCardNumberId + ","
                                    + "invoice_number: " + processPaymentRequest.CreditCardNumberId + ","
                                    + "expiration_date:" + processPaymentRequest.CreditCardExpireYear + "/" + processPaymentRequest.CreditCardExpireMonth.ToString("00") + ","
                                    + "cvv: " + CvvEncrypter(processPaymentRequest.CreditCardCvv2, claveBanco) + ","
                                    + "currency:ves,"
                                    + "amount: " + Convert.ToString(processPaymentRequest.OrderTotal) +
                                    "} " +
                                    "}";



                //request.Parameters.Clear();
                //request.AddParameter("application/json", strJSONContent, ParameterType.RequestBody);

                //var response = client.Execute(request);



                //byte[] __postDataStream = Encoding.UTF8.GetBytes(PostData.Replace(" ", string.Empty));

                //__webrequest.Method = "POST";
                //__webrequest.ContentType = "application/json";
                //__webrequest.ContentLength = __postDataStream.Length;
                //__webrequest.Headers.Add("x-ibm-client-id");
                //Stream __requestStream = __webrequest.GetRequestStream();
                //__requestStream.Write(__postDataStream, 0, __postDataStream.Length);
                //__requestStream.Close();

                //// response
                //WebResponse __webresponse = __webrequest.GetResponse();
                //Stream dataStream = __webresponse.GetResponseStream();
                //StreamReader reader = new StreamReader(dataStream);
                //string responseFromServer = reader.ReadToEnd();

                //EpagosMercantilRSModel __instaRs = JsonConvert.DeserializeObject<EpagosMercantilRSModel>(responseFromServer) as EpagosMercantilRSModel;
                //if (__instaRs.Success == true)
                //{
                //    _result.AuthorizationTransactionId = " Código del pago:" + __instaRs.Id;
                //    _result.AuthorizationTransactionCode = "Número de referencia del pago:" + __instaRs.Reference;
                //    _result.AuthorizationTransactionResult = "Mensaje: " + __instaRs.Message;
                //    _result.CaptureTransactionResult = __instaRs.Voucher;
                //    _result.NewPaymentStatus = PaymentStatus.Paid;
                //    _epagosMercantilPaymentSettings.TransactMode = TransactMode.AuthorizeAndCapture;
                //}
                //else
                //{
                //    string __errorMessage;
                //    switch (Convert.ToInt32(__instaRs.Code))
                //    {
                //        case 400:
                //            __errorMessage = "Error al validar los datos enviados: " + __instaRs.Message;
                //            break;
                //        case 401:
                //            __errorMessage = "Error de autenticación, ha ocurrido un error con las llaves utilizadas. " + __instaRs.Message;
                //            break;
                //        case 403:
                //            __errorMessage = "Pago Rechazado por el banco. " + __instaRs.Message;
                //            break;
                //        case 500:
                //            __errorMessage = "Ha Ocurrido un error interno dentro del servidor: " + __instaRs.Message;
                //            break;
                //        case 503:
                //            __errorMessage = "Ha Ocurrido un error al procesar los parámetros de entrada. Revise los datos enviados y vuelva a intentarlo. " + __instaRs.Message;
                //            break;
                //        default:
                //            __errorMessage = "Lo sentimos, no hemos podido procesar su tarjeta de crédito. El mensaje del banco fue: " + __instaRs.Message;
                //            break;
                //    }
                //    _result.AddError(__errorMessage);
                //}
                result = _result;
            }
            catch (Exception ex)
            {
                throw new NopException("Error al procesar el pago: " + ex.Message, ex);
            }
        }