コード例 #1
0
        public ActionResult Commit(string occ, string externalUniqueNumber, string status)
        {
            if (null != status && !status.Equals("PRE_AUTHORIZED", StringComparison.InvariantCultureIgnoreCase))
            {
                ViewBag.Occ = occ;
                ViewBag.ExternalUniqueNumber = externalUniqueNumber;
                ViewBag.Status = status;

                return(View("CommitError"));
            }

            try
            {
                TransactionCommitResponse response = Transaction.Commit(occ, externalUniqueNumber);

                ViewBag.ExternalUniqueNumber = externalUniqueNumber;
                ViewBag.Transaction          = response;
                return(View());
            }
            catch (Transbank.Onepay.Exceptions.TransbankException e)
            {
                Debug.WriteLine(e.StackTrace);
                return(RedirectToAction("Message", "Error", new { error = e.Message }));
            }
        }
        static void Main(string[] args)
        {
            // Setting comerce data
            Onepay.SharedSecret    = "?XW#WOLG##FBAGEAYSNQ5APD#JF@$AYZ";
            Onepay.ApiKey          = "dKVhq1WGt_XapIYirTXNyUKoWTDFfxaEV63-O5jcsdw";
            Onepay.IntegrationType = Transbank.Onepay.Enums.OnepayIntegrationType.Test;

            // Setting items to the shopping cart
            ShoppingCart cart = new ShoppingCart();

            cart.Add(new Item(
                         description: "Zapatos",
                         quantity: 1,
                         amount: 10000,
                         additionalData: null,
                         expire: 10));

            cart.Add(new Item("Pantalon", 1, 5000, null, -1));

            // Send transaction to Transbank
            TransactionCreateResponse response = Transaction.Create(cart);

            Console.WriteLine(response.ToString());

            var bytes = Convert.FromBase64String(response.QrCodeAsBase64);

            using (var imageFile = new FileStream(@"Qr.jpg", FileMode.Create))
            {
                imageFile.Write(bytes, 0, bytes.Length);
                imageFile.Flush();
            }

            Console.WriteLine("Pay with the app and then press any key to continue....");
            Console.ReadKey();

            TransactionCommitResponse commitResponse = Transaction.Commit(
                response.Occ, response.ExternalUniqueNumber);

            Console.WriteLine(commitResponse.ToString());

            Console.WriteLine("Press any key to Refund Transaction...");
            Console.ReadKey();

            RefundCreateResponse refundResponse = Refund.Create(commitResponse.Amount,
                                                                commitResponse.Occ, response.ExternalUniqueNumber,
                                                                commitResponse.AuthorizationCode);

            Console.WriteLine(refundResponse.ToString());

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
コード例 #3
0
        public void TestOnepayCommitTransaction()
        {
            Options options = new Options(
                "mUc0GxYGor6X8u-_oB3e-HWJulRG01WoC96-_tUA3Bg",
                "P4DCPS55QB2QLT56SQH6#W#LV76IAPYX"
                );

            var externalNumber = "f506a955-800c-4185-8818-4ef9fca97aae";
            var occ            = "1807983490979289";

            TransactionCommitResponse response = Transaction.Commit(
                occ, externalNumber, options);

            Assert.IsNotNull(response);
            Assert.AreEqual("1807983490979289", response.Occ);
            Assert.AreEqual("623245", response.AuthorizationCode);
            Assert.AreEqual(1532104549, response.IssuedAt);
            Assert.AreEqual("FfY4Ab89rC8rEf0qnpGcd0L/0mcm8SpzcWhJJMbUBK0=", response.Signature);
            Assert.AreEqual(27500, response.Amount);
            Assert.AreEqual("Venta Normal: Sin cuotas", response.TransactionDesc);
            Assert.AreEqual(27500, response.InstallmentsAmount);
            Assert.AreEqual(1, response.InstallmentsNumber);
            Assert.AreEqual("20180720122456123", response.BuyOrder);
        }