Ejemplo n.º 1
0
        public IActionResult AddCardCustomer([FromBody] CardToken cardData)
        {
            if (cardData == null)
            {
                _log.Error(nameof(cardData).ToString() + "Cannot be null.");
                throw new ArgumentNullException(nameof(cardData), "Cannot be null.");
            }

            Card cardCreated = null;

            try
            {
                _log.Information("Adding Card to customer.");

                var openpayAPI = OpenPayHandler.GetOpenPayInstance();

                Card request = new Card();
                request.TokenId         = cardData.token_id;
                request.DeviceSessionId = cardData.device_session_id;

                cardCreated = openpayAPI.CardService.Create(cardData.id, request);
            }
            catch (Exception ex)
            {
                _log.Error("Exception while adding card." + ex.ToString());
                return(NotFound());
            }

            return(Ok(cardCreated));
        }
Ejemplo n.º 2
0
        public IActionResult AddCustomer([FromBody] Customer customer)

        {
            if (customer == null)
            {
                _log.Error(nameof(customer).ToString() + "Cannot be null.");
                throw new ArgumentNullException(nameof(customer), "Cannot be null.");
            }

            Customer customerCreated = null;

            try
            {
                _log.Information("Adding Customer.");
                var openpayAPI = OpenPayHandler.GetOpenPayInstance();
                customerCreated = openpayAPI.CustomerService.Create(customer);
            }
            catch (Exception ex)
            {
                _log.Error("Exception while adding customer." + ex.ToString());
                return(NotFound());
            }

            return(Ok(customerCreated));
        }
        public IActionResult GetListCars([FromBody] string customer_id)
        {
            List <Card> cards = null;

            try
            {
                _log.Information("Getting List Cards.");

                var openpayAPI = OpenPayHandler.GetOpenPayInstance();
                cards = openpayAPI.CardService.List(customer_id, null);
            }
            catch (Exception ex)
            {
                _log.Error("Exception while getting Cards." + ex.ToString());
                return(NotFound());
            }

            return(Ok(cards));
        }
Ejemplo n.º 4
0
        public IActionResult GetCustomer([FromBody] string customer_id)
        {
            Customer customer = null;

            try
            {
                _log.Information("Getting Customer.");

                var openpayAPI = OpenPayHandler.GetOpenPayInstance();

                customer = openpayAPI.CustomerService.Get(customer_id);
            }
            catch (Exception ex)
            {
                _log.Error("Exception while getting customer." + ex.ToString());
                return(NotFound());
            }

            return(Ok(customer));
        }
Ejemplo n.º 5
0
        public IActionResult AddCharge([FromBody] ChargeToken ChargeData)
        {
            if (ChargeData == null)
            {
                _log.Error(nameof(ChargeData).ToString() + "Cannot be null.");
                throw new ArgumentNullException(nameof(ChargeData), "Cannot be null.");
            }

            Charge        charge  = null;
            ChargeRequest request = new ChargeRequest();

            try
            {
                _log.Information("Adding charge to customer.");

                var openpayAPI = OpenPayHandler.GetOpenPayInstance();
                request.Method          = ChargeData.Method;
                request.SourceId        = ChargeData.SourceId;
                request.Amount          = new Decimal(ChargeData.Amount);
                request.Description     = ChargeData.Description;
                request.DeviceSessionId = ChargeData.DeviceSessionId;
                //request.Customer = customerCargo;

                charge = openpayAPI.ChargeService.Create(ChargeData.CustomerId, request);
            }



            catch (Exception ex)
            {
                _log.Error("Exception while adding charge." + ex.ToString());
                return(NotFound());
            }

            return(Ok(charge));
        }
Ejemplo n.º 6
0
        public IActionResult RemoveCardCustomer([FromBody] DeleteCard DeleteCard)
        {
            if (DeleteCard == null)
            {
                _log.Error(nameof(DeleteCard).ToString() + "Cannot be null.");
                throw new ArgumentNullException(nameof(DeleteCard), "Cannot be null.");
            }


            try
            {
                _log.Information("Deleting Card to customer.");

                var openpayAPI = OpenPayHandler.GetOpenPayInstance();
                openpayAPI.CardService.Delete(DeleteCard.customer_id, DeleteCard.card_id);
            }
            catch (Exception ex)
            {
                _log.Error("Exception while deleting card." + ex.ToString());
                return(NotFound());
            }

            return(Ok());
        }