Exemple #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();
        }
Exemple #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
        }
Exemple #3
0
        public void MPIPN_MustThrowException_BothActionsNull()
        {
            try
            {
                Ipn.HandleNotification(Ipn.Payment, "id");
            }
            catch (ArgumentNullException)
            {
                Assert.Pass();
                return;
            }

            Assert.Fail();
        }
Exemple #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();
        }
Exemple #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();
        }
Exemple #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();
        }
Exemple #7
0
        /// <summary>
        /// Create New Customer
        /// </summary>
        public Boolean InsertIPN(NameValueCollection ipn, string call)
        {
            var licenseid = "";

            try
            {
                licenseid = ipn["custom"].Split('|')[0];
            }
            catch
            { }

            var insertingIpn = new Ipn
            {
                LicenseId          = licenseid,
                Product            = ipn["custom"].Split('|').Length > 2 ? ipn["custom"].Split('|')[1] : null,
                ReceiverEmail      = ipn["receiver_email"],
                ReceiverId         = ipn["receiver_id"],
                ResidenceCountry   = ipn["residence_country"],
                TestIpn            = ipn["test_ipn"],
                TransactionSubject = ipn["transaction_subject"],
                TxnId                 = ipn["txn_id"],
                TxnType               = ipn["txn_type"],
                PayerEmail            = ipn["payer_email"],
                PayerId               = ipn["payer_id"],
                PayerStatus           = ipn["payer_status"],
                FirstName             = ipn["first_name"],
                LastName              = ipn["last_name"],
                AddressCity           = ipn["address_city"],
                AddressCountry        = ipn["address_country"],
                AddressCountryCode    = ipn["address_country_code"],
                AddressName           = ipn["address_name"],
                AddressState          = ipn["address_state"],
                AddressStatus         = ipn["address_status"],
                AddressStreet         = ipn["address_street"],
                AddressZip            = ipn["address_zip"],
                Custom                = ipn["custom"],
                HandlingAmount        = ipn["handling_amount"],
                ItemName              = ipn["item_name"],
                ItemNumber            = ipn["item_number"],
                McCurrency            = ipn["mc_currency"],
                McFee                 = ipn["mc_fee"],
                McGross               = ipn["mc_gross"],
                PaymentDate           = ipn["payment_date"],
                PaymentFee            = ipn["payment_fee"],
                PaymentGross          = ipn["payment_gross"],
                PaymentStatus         = ipn["payment_status"],
                PaymentType           = ipn["payment_type"],
                ProtectionEligibility = ipn["protection_eligibility"],
                Quantity              = ipn["quantity"],
                Shipping              = ipn["shipping"],
                Tax     = ipn["tax"],
                Call    = call,
                Created = DateTime.UtcNow,
                Updated = DateTime.UtcNow,
                Version = "1.0"
            };

            using (var context = new CustomerInfoRepository())
            {
                context.Ipns.Add(insertingIpn);

                try
                {
                    context.SaveChanges();
                    return(true);
                }
                catch (Exception exception)
                {
                    SPCServices.ExceptionHandling.SPCExceptionLog.LogSPCException(exception, licenseid);
                    return(false);
                }
            }
        }
Exemple #8
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);
 }