Esempio n. 1
0
        public void CanMakePayment()
        {
            Payment payment = new Payment
            {
                amount      = 99.99M,
                description = "Test payment",
                redirectUrl = "http://www.foxip.net/test/12345",
                metadata    = "12345678"
            };

            PaymentStatus status = mollieClient.StartPayment(payment);

            Assert.AreEqual(status.amount, payment.amount);
            Assert.AreEqual(status.description, payment.description);
            Assert.AreEqual(status.links.redirectUrl, payment.redirectUrl);
            Assert.IsTrue(status.links.paymentUrl.StartsWith("https://"));
            Assert.AreEqual(status.mode, "test");
            Assert.AreEqual(status.paidDatetime, null);
            Assert.IsNull(status.cancelledDatetime, null);
            Assert.IsNotNull(status.createdDatetime);
            Assert.IsNull(status.details);
            Assert.IsNull(status.expiredDatetime);
            Assert.IsTrue(status.id != "");
            Assert.AreEqual(status.metadata, payment.metadata);
            Assert.AreEqual(status.status, Status.open);
            Assert.IsNull(status.method);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            MollieClient mollieClient = new MollieClient();

            mollieClient.setApiKey(ConfigurationManager.AppSettings["mollie_api_key"]);

            Console.WriteLine("Loading iDeal issuers ...");
            Issuers issuers = mollieClient.GetIssuers();

            foreach (Issuer issuer in issuers.data)
            {
                Console.WriteLine(issuer.name);
            }

            Console.WriteLine("Starting payment without method ...");

            Payment payment = new Payment
            {
                amount      = 99.99M,
                description = "Test payment",
                redirectUrl = "http://www.foxip.net/completed/?orderId=1245",
            };

            PaymentStatus status = mollieClient.StartPayment(payment);

            Console.WriteLine("The status is: " + status.status);
            Console.WriteLine("Please follow this link to start the payment:");
            Console.WriteLine(status.links.paymentUrl);

            Console.WriteLine("Press [enter] to continue ...");
            Console.ReadLine();

            Console.WriteLine("Getting status ...");
            status = mollieClient.GetStatus(status.id);
            Console.WriteLine("The status is now: " + status.status);

            //Refunds only for iDEAL, Bancontact/Mister Cash, SOFORT Banking, creditcard and banktransfer
            Console.WriteLine("Refunding ...");
            try
            {
                RefundStatus refundStatus = mollieClient.Refund(status.id);
                Console.WriteLine("The status is now: " + refundStatus.payment.status);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }

            Console.WriteLine("Starting payment with a specific method ...");
            status = mollieClient.StartPayment(new Payment
            {
                amount      = 1.99M,
                method      = Method.mistercash,
                description = "Test payment",
                redirectUrl = "http://www.foxip.net/completed/?orderId=12345"
            });
            Console.WriteLine("The status is: " + status.status);
            Console.WriteLine("Please follow this link to start the payment:");
            Console.WriteLine(status.links.paymentUrl);
            Console.WriteLine("Press [enter] to continue ...");
            Console.ReadLine();
        }
Esempio n. 3
0
        public PartialViewResult Index(RegisterViewModel m)
        {
            var timeSetting       = WebConfigurationManager.AppSettings["RegistrationClose"];
            var registrationClose = DateTime.ParseExact(timeSetting, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);

            timeSetting = WebConfigurationManager.AppSettings["RegistrationStart"];
            var registrationStart = DateTime.ParseExact(timeSetting, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);

            timeSetting = WebConfigurationManager.AppSettings["RegistrationStartEarlyBird"];
            var registrationStartEarlyBird = DateTime.ParseExact(timeSetting, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);

            timeSetting = WebConfigurationManager.AppSettings["RegistrationStartOpenToAll"];
            var registrationStartOpenToAll = DateTime.ParseExact(timeSetting, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);

            // Check registration date, throw 403 otherwise.
            if (DateTime.Now >= registrationClose || DateTime.Now < registrationStartEarlyBird)
            {
                Response.StatusCode = 403;
                return(PartialView());
            }

            // Get amount of RU students, CognAC and Dorans
            var permitCount = Convert.ToInt16(m.TeamCaptainRUStudent || m.TeamCaptainCognAC || m.TeamCaptainDorans) +
                              Convert.ToInt16(m.Summoner2RUStudent || m.Summoner2CognAC || m.Summoner2Dorans) +
                              Convert.ToInt16(m.Summoner3RUStudent || m.Summoner3CognAC || m.Summoner3Dorans) +
                              Convert.ToInt16(m.Summoner4RUStudent || m.Summoner4CognAC || m.Summoner4Dorans) +
                              Convert.ToInt16(m.Summoner5RUStudent || m.Summoner5CognAC || m.Summoner5Dorans);
            var earlyBirdCount = Convert.ToInt16(m.TeamCaptainCognAC || m.TeamCaptainDorans) +
                                 Convert.ToInt16(m.Summoner2CognAC || m.Summoner2Dorans) +
                                 Convert.ToInt16(m.Summoner3CognAC || m.Summoner3Dorans) +
                                 Convert.ToInt16(m.Summoner4CognAC || m.Summoner4Dorans) +
                                 Convert.ToInt16(m.Summoner5CognAC || m.Summoner5Dorans);

            // Check for at least 4 permitted clients
            if (DateTime.Now < registrationStartOpenToAll && permitCount < 3)
            {
                ModelState.AddModelError("permitCount", "The team does not exist of at least 4 RU students, CognAC members, or Dorans members.");
            }

            // Check for early-bird access
            if (DateTime.Now >= registrationStartEarlyBird && DateTime.Now < registrationStart)
            {
                if (earlyBirdCount < 5)
                {
                    ModelState.AddModelError("earlyBirdAccess",
                                             "Registrations are currently only open for teams that have at least five CognAC and/or Dorans members.");
                }

                if (Mongo.Teams.Count(Query <Team> .Where(x => !x.Cancelled)) >= 12)
                {
                    ModelState.AddModelError("earlyBirdFull",
                                             "All 12 early-bird spots are now taken. You can retry registering after the tournament registration officially opens for all students.");
                }
            }


            if (ModelState.IsValid)
            {
                // Note: we don't actually retrieve stuff from the Riot servers here. We do this in a separate cron thread asynchronously

                var teamId = ObjectId.GenerateNewId();

                var captain = new Participant
                {
                    Email          = m.TeamCaptainEmail,
                    FullName       = m.TeamCaptainRealName,
                    IsCaptain      = true,
                    LastUpdateTime = new DateTime(1900, 1, 1),
                    RegisterTime   = DateTime.UtcNow,
                    StudyProgram   = m.TeamCaptainStudy,
                    TeamId         = teamId,
                    SummonerName   = m.TeamCaptainName,
                    RuStudent      = m.TeamCaptainRUStudent,
                    CognAC         = m.TeamCaptainCognAC,
                    Dorans         = m.TeamCaptainDorans,
                    StudentNumber  = m.TeamCaptainStudentNumber
                };

                var summoner2 = new Participant
                {
                    Email          = m.Summoner2Email,
                    FullName       = m.Summoner2RealName,
                    IsCaptain      = false,
                    LastUpdateTime = new DateTime(1900, 1, 1),
                    RegisterTime   = DateTime.UtcNow,
                    StudyProgram   = m.Summoner2Study,
                    TeamId         = teamId,
                    SummonerName   = m.Summoner2Name,
                    RuStudent      = m.Summoner2RUStudent,
                    CognAC         = m.Summoner2CognAC,
                    Dorans         = m.Summoner2Dorans,
                    StudentNumber  = m.Summoner2StudentNumber
                };

                var summoner3 = new Participant
                {
                    Email          = m.Summoner3Email,
                    FullName       = m.Summoner3RealName,
                    IsCaptain      = false,
                    LastUpdateTime = new DateTime(1900, 1, 1),
                    RegisterTime   = DateTime.UtcNow,
                    StudyProgram   = m.Summoner3Study,
                    TeamId         = teamId,
                    SummonerName   = m.Summoner3Name,
                    RuStudent      = m.Summoner3RUStudent,
                    CognAC         = m.Summoner3CognAC,
                    Dorans         = m.Summoner3Dorans,
                    StudentNumber  = m.Summoner3StudentNumber
                };

                var summoner4 = new Participant
                {
                    Email          = m.Summoner4Email,
                    FullName       = m.Summoner4RealName,
                    IsCaptain      = false,
                    LastUpdateTime = new DateTime(1900, 1, 1),
                    RegisterTime   = DateTime.UtcNow,
                    StudyProgram   = m.Summoner4Study,
                    TeamId         = teamId,
                    SummonerName   = m.Summoner4Name,
                    RuStudent      = m.Summoner4RUStudent,
                    CognAC         = m.Summoner4CognAC,
                    Dorans         = m.Summoner4Dorans,
                    StudentNumber  = m.Summoner4StudentNumber
                };

                var summoner5 = new Participant
                {
                    Email          = m.Summoner5Email,
                    FullName       = m.Summoner5RealName,
                    IsCaptain      = false,
                    LastUpdateTime = new DateTime(1900, 1, 1),
                    RegisterTime   = DateTime.UtcNow,
                    StudyProgram   = m.Summoner5Study,
                    TeamId         = teamId,
                    SummonerName   = m.Summoner5Name,
                    RuStudent      = m.Summoner5RUStudent,
                    CognAC         = m.Summoner5CognAC,
                    Dorans         = m.Summoner5Dorans,
                    StudentNumber  = m.Summoner5StudentNumber
                };

                Mongo.Participants.Insert(captain);
                Mongo.Participants.Insert(summoner2);
                Mongo.Participants.Insert(summoner3);
                Mongo.Participants.Insert(summoner4);
                Mongo.Participants.Insert(summoner5);

                var listParticipantIds = new List <ObjectId> {
                    captain.Id, summoner2.Id, summoner3.Id, summoner4.Id, summoner5.Id
                };

                var team = new Team
                {
                    CaptainId       = captain.Id,
                    Id              = teamId,
                    Name            = m.TeamName,
                    ParticipantsIds = listParticipantIds,
                    Cancelled       = false,
                };

                // Add team to database
                Mongo.Teams.Insert(team);

                // Create iDeal payment
                var key    = WebConfigurationManager.AppSettings["MollieLiveKey"];
                var client = new MollieClient {
                    ApiKey = key
                };

                var template = new PaymentTemplate {
                    Amount = team.Price, Description = "LoL Championship Nijmegen 2017", RedirectUrl = "https://lolcognac.nl/Payment/Status/" + team.Id, Method = m.PaymentMethod
                };
                var status = client.StartPayment(template);
                m.PaymentUrl = status.Links.PaymentUrl;
                m.Price      = status.Amount;

                status.TeamId = team.Id;

                Mongo.Payments.Insert(status);

                // Send email
                EmailHelper.SendOfficialLoLRegistrationReminder(captain.Email, captain.FullName);

                return(PartialView("OK", m));
            }

            // Model state is invalid, return form.
            return(PartialView("Form", m));
        }
        public override string RedirectForPayment(OrderData orderData)
        {
            var appliedtotal = orderData.PurchaseInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");
            var alreadypaid  = orderData.PurchaseInfo.GetXmlPropertyDouble("genxml/alreadypaid");
            var info         = ProviderUtils.GetProviderSettings("DnnCMolliepayment");
            var cartDesc     = info.GetXmlProperty("genxml/textbox/cartdescription");
            var testMode     = info.GetXmlPropertyBool("genxml/checkbox/testmode");
            var testApiKey   = info.GetXmlProperty("genxml/textbox/testapikey");
            var liveApiKey   = info.GetXmlProperty("genxml/textbox/liveapikey");
            var notifyUrl    = Utils.ToAbsoluteUrl("/DesktopModules/NBright/DnnCMollie/notify.ashx");

            var returnUrl = Globals.NavigateURL(StoreSettings.Current.PaymentTabId, "");
            var ItemId    = orderData.PurchaseInfo.ItemID.ToString("");

            var nbi = new NBrightInfo();

            nbi.XMLData = orderData.payselectionXml;
            var paymentMethod = nbi.GetXmlProperty("genxml/textbox/paymentmethod");
            var paymentBank   = nbi.GetXmlProperty("genxml/textbox/paymentbank");
            var apiKey        = testApiKey;

            if (!testMode)
            {
                apiKey = liveApiKey;
            }


            MollieClient mollieClient = new MollieClient();

            mollieClient.setApiKey(apiKey);

            Payment payment = new Payment()
            {
                amount      = decimal.Parse((appliedtotal - alreadypaid).ToString("0.00", CultureInfo.InvariantCulture)), //99.99M,
                description = cartDesc,
                redirectUrl = returnUrl + "/orderid/" + ItemId,
                method      = (Method)Enum.Parse(typeof(Method), paymentMethod, true),
                issuer      = paymentBank,
                metadata    = ItemId,
                webhookUrl  = notifyUrl,
            };

            PaymentStatus paymentStatus = mollieClient.StartPayment(payment);

            orderData.OrderStatus = "020";
            orderData.PurchaseInfo.SetXmlProperty("genxml/paymenterror", "");
            orderData.PurchaseInfo.SetXmlProperty("genxml/posturl", paymentStatus.links.paymentUrl);
            orderData.PurchaseInfo.Lang = Utils.GetCurrentCulture();
            orderData.SavePurchaseData();
            try
            {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Write(ProviderUtils.GetBankRemotePost(orderData));
            }
            catch (Exception ex)
            {
                // rollback transaction
                orderData.PurchaseInfo.SetXmlProperty("genxml/paymenterror", "<div>ERROR: Invalid payment data </div><div>" + ex + "</div>");
                orderData.PaymentFail();
                var param = new string[3];
                param[0] = "orderid=" + orderData.PurchaseInfo.ItemID.ToString("");
                param[1] = "status=0";
                return(Globals.NavigateURL(StoreSettings.Current.PaymentTabId, "", param));
            }

            try
            {
                HttpContext.Current.Response.End();
            }
            catch (Exception ex)
            {
                // this try/catch to avoid sending error 'ThreadAbortException'
            }

            return("");
        }