该令牌已被使用,conekta

时间:2017-08-08 21:36:49

标签: c# asp.net-mvc e-commerce payment

我在收费时遇到问题,这告诉我这个错误:

“令牌已被使用” “La tarjeta no pudo ser procesada”

当我使用测试令牌执行此操作时,这可以正常工作,但当我使用另一个令牌时,这不起作用,这是我的实现。

 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 个答案:

答案 0 :(得分:1)

问题是参数token_id仅用于一次调用,但如果您想重新使用卡进行自动付款,则必须设置payment_source_id而不是token_id,这是正确的代码:

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"));
                }

            }