Example #1
0
        public void MPIPN_PaymentNotification_MustBeOk()
        {
            SDK.CleanConfiguration();
            SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");

            var payment =
                new Payment
            {
                TransactionAmount = 100m,
                Description       = "IPN Test",
                Token             = GenerateSingleUseCardToken(),
                PaymentMethodId   = "visa",
                ExternalReference = "1234",
                Installments      = 1,
                Payer             = new Payer
                {
                    Email = "*****@*****.**"
                }
            };

            payment.Save();

            Ipn.HandleNotification(Ipn.Payment, payment.Id.ToString(), onMerchantOrderReceived: null, onPaymentReceived: p =>
            {
                Assert.AreEqual(p.Id, payment.Id);
                Assert.AreEqual(p.Description, payment.Description);
                Assert.AreEqual(p.TransactionAmount, payment.TransactionAmount);
                Assert.AreEqual(p.ExternalReference, payment.ExternalReference);
                Assert.Pass();
            });

            Assert.Fail();
        }
Example #2
0
        public void MPIPN_MustNotGetMerchantOrderById_OnNullMerchantOrderHandler()
        {
            SDK.CleanConfiguration();
            var merchantOrderId = "xxxx";

            Ipn.HandleNotification(Ipn.MerchantOrder, merchantOrderId, onPaymentReceived: x => { }, onMerchantOrderReceived: null);
            // No API Call is performed, therefore test passes
        }
Example #3
0
        public void MPIPN_MustThrowException_BothActionsNull()
        {
            try
            {
                Ipn.HandleNotification(Ipn.Payment, "id");
            }
            catch (ArgumentNullException)
            {
                Assert.Pass();
                return;
            }

            Assert.Fail();
        }
Example #4
0
        public void MPIPN_MustThrowException_TopicParameterEmpty()
        {
            try
            {
                Ipn.HandleNotification(null, "id");
            }
            catch (MPException ex)
            {
                Assert.AreEqual("Topic and Id can not be null in the IPN request.", ex.Message);
                return;
            }

            Assert.Fail();
        }
Example #5
0
        public void MPIPN_MustThrowException_InvalidPaymentId()
        {
            var paymentId = "xxxx";

            try
            {
                Ipn.HandleNotification(Ipn.Payment, paymentId, x => {});
            }
            catch (MPException ex)
            {
                Assert.AreEqual(ex.Message, $"Invalid Payment Id: {paymentId}");
                return;
            }

            Assert.Fail();
        }
Example #6
0
        public void MPIPN_MerchantOrderNotification_MustBeOk()
        {
            SDK.CleanConfiguration();
            SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN");

            var merchantOrder =
                new MerchantOrder
            {
                Payer = new MercadoPago.DataStructures.MerchantOrder.Payer
                {
                    Email = "*****@*****.**"
                },
                Items = new List <Item>
                {
                    new Item
                    {
                        Description = "Test Ipn",
                        Quantity    = 1,
                        UnitPrice   = 10m
                    }
                }
            };

            merchantOrder.Save();

            Ipn.HandleNotification(Ipn.MerchantOrder, merchantOrder.Id, onPaymentReceived: null, onMerchantOrderReceived: m =>
            {
                Assert.AreEqual(m.Id, merchantOrder.Id);
                Assert.AreEqual(m.Items.Count, merchantOrder.Items.Count);
                Assert.AreEqual(m.Items[0].UnitPrice, merchantOrder.Items[0].UnitPrice);
                Assert.AreEqual(m.Items[0].Description, merchantOrder.Items[0].Description);
                Assert.Pass();
            });

            Assert.Fail();
        }
Example #7
0
 // Put this in an ASP.NET controller supporting HTTP POST
 public static void IpnNotification(string topic, string id)
 {
     Ipn.HandleNotification(topic, id, onPaymentReceived: OnPaymentReceived, onMerchantOrderReceived: OnMerchantOrderReceived);
 }