public override IMovilwayApiResponse PerformUtibaOperation(IMovilwayApiRequest requestObject, UMarketSCClient utibaClientProxy, String sessionID)
        {
            CreateMoviPinRequestBody  request  = requestObject as CreateMoviPinRequestBody;
            CreateMoviPinResponseBody response = null;

            createcouponRequestType createCouponRequest = new createcouponRequestType()
            {
                sessionid            = sessionID,
                device_type          = request.DeviceType,
                amount               = request.Amount,
                amountSpecified      = true,
                wallet_type          = int.Parse(ConfigurationManager.AppSettings["CouponWalletType"]),
                wallet_typeSpecified = true,
                reserve              = true,
                reserveSpecified     = true,
                wait            = false,
                expiry          = int.Parse(ConfigurationManager.AppSettings["CouponExpiryDays"]),
                expirySpecified = true
            };

            if (!String.IsNullOrEmpty(request.ProductId))
            {
                createCouponRequest.extra_trans_data = new KeyValuePair[] { new KeyValuePair()
                                                                            {
                                                                                key = "product_id", value = request.ProductId
                                                                            } }
            }
            ;

            createcoupon utibaCreateCouponRequest = new createcoupon()
            {
                createcouponRequest = createCouponRequest
            };

            if (request.Recipient != null)
            {
                utibaCreateCouponRequest.createcouponRequest.recipient = request.Recipient;
            }
            createcouponResponse utibaCreateCouponResponse = utibaClientProxy.createcoupon(utibaCreateCouponRequest);

            if (utibaCreateCouponResponse != null)
            {
                response = new CreateMoviPinResponseBody()
                {
                    ResponseCode    = Utils.BuildResponseCode(utibaCreateCouponResponse.createcouponReturn.result, utibaCreateCouponResponse.createcouponReturn.result_namespace),
                    ResponseMessage = utibaCreateCouponResponse.createcouponReturn.result_message,
                    TransactionID   = utibaCreateCouponResponse.createcouponReturn.transid,
                    MoviPin         = utibaCreateCouponResponse.createcouponReturn.couponid,
                    Fee             = utibaCreateCouponResponse.createcouponReturn.fee,
                    ExpiryDate      = DateTime.Now.Date.AddDays(int.Parse(ConfigurationManager.AppSettings["CouponExpiryDays"]))
                };
            }
            return(response);
        }
    }
Exemple #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);
        }
Exemple #3
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);
        }