示例#1
0
        public IMovilwayApiResponse PerformOperation(IMovilwayApiRequest requestObject)
        {
            var request = requestObject as ConsolidateMoviPinRequestBody;

            Logger.BeginLow(() => TagValue.New().Tag("Request").Value(request));


            var response = new ConsolidateMoviPinResponseBody
            {
                ResponseCode    = 0,
                ResponseMessage = "Sus Movipins han sido consolidados.",
                TransactionID   = 0,
                MoviPins        = new MoviPins()
            };


            if (request != null)
            {
                decimal consolidatedAmount = 0;
                string  recipient          = null;
                var     pines = new List <MoviPinDetails>();

                // Busco el detalle de cada pin recibido
                foreach (var movipin in request.MoviPins)
                {
                    pines.Add(Utils.GetMoviPinDetails(movipin.Number));
                }


                // Reviso que no existan pines repetidos
                if (pines.Select(m => m.Number).Distinct().Count() != pines.Count())
                {
                    response.ResponseCode    = 99;
                    response.ResponseMessage = "Existen pines repetidos en la solicitud";
                    Logger.CheckPointLow(() => TagValue.New().Tag("Response").Value(response));
                    return(response);
                }

                // Reviso que exista más de un pin válido, ya que no tiene sentido validar un solo pin
                if (pines.Count(p => p.IsValid == true) <= 1)
                {
                    response.ResponseCode    = 99;
                    response.ResponseMessage = "Existen menos de dos pines validos";
                    Logger.CheckPointLow(() => TagValue.New().Tag("Response").Value(response));
                    return(response);
                }

                // Reviso que todos los pines sean del mismo user
                if (pines.Select(p => p.Agent).Distinct().Count() != 1)
                {
                    response.ResponseCode    = 99;
                    response.ResponseMessage = "No todos los pines son del mismo usuario";
                    Logger.CheckPointLow(() => TagValue.New().Tag("Response").Value(response));
                    return(response);
                }

                // Seteo el agente a utilizar más adelante al crear el nuevo pin consolidado
                recipient = pines.First().Agent;

                // Reviso que el pin a crear sea de un monto válido
                if (pines.Sum(p => p.RemainingAmount) == 0)
                {
                    response.ResponseCode    = 99;
                    response.ResponseMessage = "No puede crearse un nuevo PIN por cero D2";
                    Logger.CheckPointLow(() => TagValue.New().Tag("Response").Value(response));
                    return(response);
                }


                // En esta parte se redimen uno a uno los pines
                foreach (var movipin in request.MoviPins)
                {
                    if (pines.Single(p => p.Number == movipin.Number).IsValid != null && pines.Single(p => p.Number == movipin.Number).IsValid.Value)
                    {
                        var movipaymentRequest = new MoviPaymentRequestBody
                        {
                            AuthenticationData = new AuthenticationData()
                            {
                                Username = _redeemUser,
                                Password = _redeemPassword
                            },
                            DeviceType = request.DeviceType,
                            Amount     = pines.Single(p => p.Number == movipin.Number).RemainingAmount.Value,
                            ExternalTransactionReference = "",
                            MoviPin = movipin.Number
                        };
                        var redeeemResponse = new ServiceExecutionDelegator
                                              <MoviPaymentResponseBody, MoviPaymentRequestBody>().
                                              ResolveRequest(movipaymentRequest, ApiTargetPlatform.Utiba, ApiServiceName.MoviPayment);

                        if (redeeemResponse.ResponseCode.Value == 0)
                        {
                            consolidatedAmount += pines.Single(p => p.Number == movipin.Number).RemainingAmount.Value;
                        }
                        else
                        {
                            movipin.IsValid         = false;
                            movipin.Agent           = null;
                            movipin.RemainingAmount = null;
                        }
                    }
                    response.MoviPins.Add(pines.Single(p => p.Number == movipin.Number));
                }

                // Acá procedemos a crear el nuevo pin por el monto que redimimos
                if (consolidatedAmount > 0)
                {
                    var createMoviPinRequest = new CreateMoviPinRequestBody()
                    {
                        AuthenticationData = new AuthenticationData()
                        {
                            Username = _consolidateUser,
                            Password = _consolidatePassword
                        },
                        Amount     = consolidatedAmount,
                        DeviceType = request.DeviceType,
                        ExternalTransactionReference = "",
                        Recipient = recipient
                    };
                    var createMoviPinResponse = new ServiceExecutionDelegator
                                                <CreateMoviPinResponseBody, CreateMoviPinRequestBody>().
                                                ResolveRequest(createMoviPinRequest, ApiTargetPlatform.Utiba, ApiServiceName.CreateMoviPin);

                    if (createMoviPinResponse.ResponseCode.Value == 0)
                    {
                        response.ConsolidatedMoviPin = createMoviPinResponse.MoviPin;
                        response.ConsolidatedAmount  = consolidatedAmount;
                        response.ExpiryDate          = createMoviPinResponse.ExpiryDate;
                    }
                    else
                    {
                        response.ResponseCode    = 99;
                        response.ResponseMessage = "Operacion fallida";
                    }
                }
                else
                {
                    response.ResponseCode    = 99;
                    response.ResponseMessage = "El pin se quería generar con monto cero";
                }
            }

            Logger.CheckPointLow(() => TagValue.New().Tag("Response").Value(response));
            return(response);
        }
示例#2
0
        public IMovilwayApiResponse PerformOperation(IMovilwayApiRequest requestObject)
        {
            var request = requestObject as RegenerateMoviPinRequestBody;

            Logger.BeginLow(() => TagValue.New().Tag("Request").Value(request));


            var response = new RegenerateMoviPinResponseBody
            {
                ResponseCode    = 0,
                ResponseMessage = "Su Movipin ha sido regenerado.",
                TransactionID   = 0
            };


            if (request != null)
            {
                decimal regeneratedAmount = 0;
                string  recipient         = null;
                var     pin = new MoviPinDetails();

                // Busco el detalle de cada pin recibido
                pin = Utils.GetMoviPinDetails(request.TransactionNumber);

                // Reviso que exista más de un pin válido, ya que no tiene sentido validar un solo pin
                if (!(pin.IsValid ?? false))
                {
                    response.ResponseCode    = 99;
                    response.ResponseMessage = "Pin invalido";
                    Logger.CheckPointLow(() => TagValue.New().Tag("Response").Value(response));
                    return(response);
                }

                // Seteo el agente a utilizar más adelante al crear el nuevo pin regenerado
                recipient = pin.Agent;

                // En esta parte se redimen uno a uno los pines
                var movipaymentRequest = new MoviPaymentRequestBody
                {
                    AuthenticationData = new AuthenticationData()
                    {
                        Username = _redeemUser,
                        Password = _redeemPassword
                    },
                    DeviceType = request.DeviceType,
                    Amount     = pin.RemainingAmount.Value,
                    ExternalTransactionReference = "",
                    MoviPin = pin.Number
                };
                var redeeemResponse = new ServiceExecutionDelegator
                                      <MoviPaymentResponseBody, MoviPaymentRequestBody>().
                                      ResolveRequest(movipaymentRequest, ApiTargetPlatform.Utiba, ApiServiceName.MoviPayment);

                if (redeeemResponse.ResponseCode.Value == 0)
                {
                    regeneratedAmount = pin.RemainingAmount.Value;
                }
                else
                {
                    pin.IsValid         = false;
                    pin.Agent           = null;
                    pin.RemainingAmount = null;
                }

                // Acá procedemos a crear el nuevo pin por el monto que redimimos
                if (regeneratedAmount > 0)
                {
                    var createMoviPinRequest = new CreateMoviPinRequestBody()
                    {
                        AuthenticationData = new AuthenticationData()
                        {
                            Username = _consolidateUser,
                            Password = _consolidatePassword
                        },
                        Amount     = regeneratedAmount,
                        DeviceType = request.DeviceType,
                        ExternalTransactionReference = "",
                        Recipient = recipient
                    };
                    var createMoviPinResponse = new ServiceExecutionDelegator
                                                <CreateMoviPinResponseBody, CreateMoviPinRequestBody>().
                                                ResolveRequest(createMoviPinRequest, ApiTargetPlatform.Utiba, ApiServiceName.CreateMoviPin);

                    if (createMoviPinResponse.ResponseCode.Value == 0)
                    {
                        response.RegeneratedMoviPin = createMoviPinResponse.MoviPin;
                        response.RegeneratedAmount  = regeneratedAmount;
                        response.ExpiryDate         = createMoviPinResponse.ExpiryDate;
                    }
                    else
                    {
                        response.ResponseCode    = 99;
                        response.ResponseMessage = "Operacion fallida";
                    }
                }
                else
                {
                    response.ResponseCode    = 99;
                    response.ResponseMessage = "El pin se quería regenerar con monto cero";
                }
            }

            Logger.CheckPointLow(() => TagValue.New().Tag("Response").Value(response));
            return(response);
        }
示例#3
0
        public override IMovilwayApiResponse PerformUtibaOperation(IMovilwayApiRequest requestObject, UMarketSCClient utibaClientProxy, String sessionID)
        {
            MoviPaymentRequestBody  request  = requestObject as MoviPaymentRequestBody;
            MoviPaymentResponseBody response = null;

            coupontransferRequestType couponTransferRequest = new coupontransferRequestType()
            {
                sessionid     = sessionID,
                device_type   = request.DeviceType,
                amount        = request.Amount,
                couponid      = request.MoviPin,
                type          = int.Parse(ConfigurationManager.AppSettings["CouponWalletType"]),
                typeSpecified = true
            };

            KeyValuePair[] keyValues;
            if (!String.IsNullOrEmpty(request.ProductId))
            {
                keyValues = new KeyValuePair[]
                {
                    new KeyValuePair()
                    {
                        key = "host_trans_ref", value = request.ExternalTransactionReference
                    },
                    new KeyValuePair()
                    {
                        key = "dollar_amount", value = request.DollarAmount.ToString()
                    },
                    new KeyValuePair()
                    {
                        key = "exchange_rate", value = request.ExchangeRate.ToString()
                    },
                    new KeyValuePair()
                    {
                        key = "product_id", value = request.ProductId
                    }
                }
            }
            ;
            else
            {
                keyValues = new KeyValuePair[]
                {
                    new KeyValuePair()
                    {
                        key = "host_trans_ref", value = request.ExternalTransactionReference
                    },
                    new KeyValuePair()
                    {
                        key = "dollar_amount", value = request.DollarAmount.ToString()
                    },
                    new KeyValuePair()
                    {
                        key = "exchange_rate", value = request.ExchangeRate.ToString()
                    }
                }
            };

            couponTransferRequest.extra_trans_data = keyValues;

            coupontransferResponse utibaCouponTransferResponse = utibaClientProxy.coupontransfer(new coupontransfer()
            {
                coupontransferRequestType = couponTransferRequest
            });

            if (utibaCouponTransferResponse != null)
            {
                response = new MoviPaymentResponseBody()
                {
                    ResponseCode    = Utils.BuildResponseCode(utibaCouponTransferResponse.coupontransferReturn.result, utibaCouponTransferResponse.coupontransferReturn.result_namespace),
                    ResponseMessage = utibaCouponTransferResponse.coupontransferReturn.result_message,
                    Fee             = utibaCouponTransferResponse.coupontransferReturn.fee,
                    TransactionID   = utibaCouponTransferResponse.coupontransferReturn.transid
                };
            }
            return(response);
        }
    }