1

i have a problem when a make a charge,this show me this error:

"The token has already been used" "La tarjeta no pudo ser procesada"

when i do this with a test token this works fine but when i do it with another token this don´t work, this is my implementation.

 bool band = true;
            Order order;

            Expression<Func<Usuario, bool>> exp = (x) => x.IdUsuario == IdUsuario;
            UsuarioLoader uLoader = new UsuarioLoader();
            var usuario = uLoader.GetElementByProperty(exp);
            try
            {

                order = new conekta.Order().create(@"{
                  ""currency"":""MXN"",
                  ""customer_info"": {
                    ""customer_id"": """+usuario.TokenConekta+@""" 
                  },
                  ""line_items"": [{
                    ""name"": ""Cobro Union"",
                    ""unit_price"": 1000,
                    ""quantity"": 1
                  }],
                  ""charges"": [{
                    ""payment_method"": {
                       ""type"": ""card"",
                        ""token_id"": """+tokenTarjeta+@"""
                    },""amount"":1000
                  }]
                }");

            }
            catch (ConektaException e)
            {
                band = false;
                foreach (JObject obj in e.details)
                {
                    System.Console.WriteLine("\n [ERROR]:\n");
                    System.Console.WriteLine("message:\t" + obj.GetValue("message"));
                    System.Console.WriteLine("debug:\t" + obj.GetValue("debug_message"));
                    System.Console.WriteLine("code:\t" + obj.GetValue("code"));
                }

            }

1 Answers1

2

the problem is that the parameter token_id is for a only one call, but if you want to re-use a card for an automatic payments you must set payment_source_id instead of token_id, this is the correct code:

Expression<Func<Usuario, bool>> exp = (x) => x.IdUsuario == IdUsuario;
            UsuarioLoader uLoader = new UsuarioLoader();
            var usuario = uLoader.GetElementByProperty(exp);
            try
            {

                order = new conekta.Order().create(@"{
                  ""currency"":""MXN"",
                  ""customer_info"": {
                    ""customer_id"": """+usuario.TokenConekta+ @""" 
                  },
                  ""line_items"": [{
                    ""name"": ""Cobro Union"",
                    ""unit_price"": 1000,
                    ""quantity"": 1
                  }],
                  ""charges"": [{
                    ""payment_method"": {
                       ""type"": ""card"",
                        ""payment_source_id"": """ + tokenTarjeta+@"""
                    },""amount"":1000
                  }]
                }");

            }
            catch (ConektaException e)
            {
                band = false;
                foreach (JObject obj in e.details)
                {
                    System.Console.WriteLine("\n [ERROR]:\n");
                    System.Console.WriteLine("message:\t" + obj.GetValue("message"));
                    System.Console.WriteLine("debug:\t" + obj.GetValue("debug_message"));
                    System.Console.WriteLine("code:\t" + obj.GetValue("code"));
                }

            }
cristian franco
  • 266
  • 2
  • 13
  • Where did you find this info? I looked for that field in the API Docs (https://developers.conekta.com/api?language=node), but it's not even mentioned – Steven Jan 16 '20 at 18:29
  • this response is only experience, the documentation is something wrong, i called directly to a conekta's person – cristian franco Jan 17 '20 at 04:28
  • Thanks. This helped me a lot, but I need to mention that right now in 2020, it`s a bit different, **payment_source_id** does not require the card token, now it requires the id of a payment source that you must register before. Besides it needs to be associated to a customer to work. – Steven Jan 17 '20 at 19:45
  • https://stackoverflow.com/questions/72064487/issue-while-creating-the-order-in-conekta-api would you like to suggest something here? – Pankaj Apr 29 '22 at 23:21