public static void Init(string TemplateId, Action <bool, string> OnEditorResult)
        {
            CurrentTemplateId = TemplateId;

            var config  = PaymentsManager.CurrentConfig;
            var address = Resources.Load <PaymentsAppSettings>("PaymentsAppSettings").ServiceURL;

            /// Download target template.
            HTTPEditor.SendGet(address + "/GetApp/" + config.AppId + "/" + TemplateId, (isSuccess, responseBody) => {
                if (!isSuccess)
                {
                    OnEditorResult?.Invoke(false, "HTTP Error");
                    return;
                }
                else
                {
                    CurrentTemplate = JsonUtility.FromJson <PaymentTemplate>(responseBody);

                    if (CurrentTemplate == null)
                    {
                        OnEditorResult?.Invoke(true, "Template data is null.");
                        return;
                    }

                    OnEditorResult?.Invoke(true, "Template received.");

                    // Create window.
                    var window = (TemplateEditor)GetWindow(typeof(TemplateEditor));
                    window.Show();
                }
            });
        }
        /// <summary>
        /// Start a payment
        /// </summary>
        /// <param name="payment">Payment object</param>
        /// <returns></returns>
        public Payment StartPayment(PaymentTemplate payment)
        {
            var jsonData = LoadWebRequest("POST", "payments", JsonConvert.SerializeObject(payment));
            var status   = JsonConvert.DeserializeObject <Payment>(jsonData, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            return(status);
        }
Exemple #3
0
        public CardPayment Create(UserCard card, PaymentTemplate template, JObject form)
        {
            Argument.NotNull(template, "template");
            Argument.NotNull(form, "form");
            Argument.NotNull(card, "card");

            var paymentProfile = _paymentProfiles.Find(card.Owner.Id);

            if (paymentProfile == null)
            {
                var message = string.Format("Payment profile for user [{0}] was not found.", card.Owner.Id);
                throw new InvalidOperationException(message);
            }
            var paymentForm = _paymentFormFactory.Create(paymentProfile, card.Account, template);

            paymentForm.MergeWith(form);
            var paymentOrder = template.OrderTemplate.CreateOrder(paymentForm);
            var to           = paymentOrder.BeneficiaryBankCode == _settings.VaBankCode
                ? _accounts.Find(paymentOrder.BeneficiaryAccountNo)
                : _correspondentAccounts.QueryOne(DbQuery.For <CorrespondentAccount>().FilterBy(x => x.Bank.Code == paymentOrder.BeneficiaryBankCode));

            if (to == null)
            {
                var message = string.Format("Destination account could not be found. Bank code: {0}. Account No: {1}.",
                                            paymentOrder.BeneficiaryBankCode,
                                            paymentOrder.BeneficiaryAccountNo);
                throw new InvalidOperationException(message);
            }
            var currency = _currencies.Find(paymentOrder.CurrencyISOName);

            if (currency == null)
            {
                var message = string.Format("Currency with code {0} was not found.", paymentOrder.CurrencyISOName);
                throw new InvalidOperationException(message);
            }
            var payment = new CardPayment(card, template, paymentOrder, form, card.Account, to, currency);

            template.FillInfo(payment, paymentForm);
            var transactionName = _transactionReferenceBook.ForPayment(template);

            payment.Withdrawal = card.Account.Withdraw(
                card,
                transactionName.Code,
                transactionName.Description,
                _settings.Location,
                payment.MoneyAmount,
                _moneyConverter);
            return(payment);
        }
Exemple #4
0
        public PaymentForm Create(UserPaymentProfile profile, Account account, PaymentTemplate template)
        {
            Argument.NotNull(profile, "profile");
            Argument.NotNull(account, "account");
            Argument.NotNull(template, "template");

            var form = new JObject
            {
                { "payerTin", new JValue(profile.PayerTIN) },
                { "payerName", new JValue(profile.PayerName) },
                { "payerBankCode", new JValue(_bankSettings.VaBankCode) },
                { "payerAccountNo", new JValue(account.AccountNo) }
            };
            var fields = template.OrderTemplate.EnumerateNotTemplatedFields().ToList();

            foreach (var field in fields)
            {
                form.Add(field.Key, new JValue(field.Value));
            }
            return(new PaymentForm(form));
        }
Exemple #5
0
 public TransactionName ForPayment(PaymentTemplate template)
 {
     Argument.NotNull(template, "template");
     return(new TransactionName(template.Code, template.DisplayName));
 }
    private void TemplateLoaded(PaymentTemplate template, PaymentsAppSettings appSettings)
    {
        Debug.Log("[SHOP] Template loaded.");

        currentTemplate = template;

        // Initialize UI.
        foreach (var product in template.Products)
        {
            AddProduct(product);
        }

        foreach (var bundle in template.Bundles)
        {
            AddBundle(bundle);
        }

        // Load filters by items.
        Transform filterHolder = filterSelection.transform;
        var       filterPrefab = filterHolder.GetChild(0);

        foreach (var item in template.ItemDefinitions)
        {
            var filter = Instantiate(filterPrefab, filterHolder);
            filter.gameObject.SetActive(true);

            filter.GetComponentInChildren <Text>().text = item.Name;
            filter.gameObject.name = item.Id;
        }

        filterSelection.Initialize(); // first child is the template. use the first generated one.
        // filter event
        filterSelection.OnValueChanged.AddListener((List <int> values) => {
            int count        = values.Count;
            string[] itemIds = new string[count];
            for (int i = 0; i < count; i++)
            {
                // get item id.
                itemIds[i] = filterHolder.GetChild(values[i]).name;
            }

            FilterShopByItemId(itemIds);
        });

        filterSelection.SelectAll();

        #region Create sorting orders.
        ///
        var options = new List <Dropdown.OptionData>();

        //  DEFAULT SORTING ORDERS.
        string[] defaultSortings = new string[] {
            "by name (ascending)",
            "by name (descending)",
            "by price (high to low)",
            "by price (low to high)"
        };

        foreach (var sorting in defaultSortings)
        {
            options.Add(new Dropdown.OptionData()
            {
                text = sorting
            });
        }

        /// Item sortings from the app settings.
        int sortingOrdersCount = appSettings.SortingOrders.Length;
        for (int i = 0; i < sortingOrdersCount; i++)
        {
            options.Add(new Dropdown.OptionData()
            {
                text = appSettings.SortingOrders[i].Name
            });
        }

        sortingDropdown.AddOptions(options);

        sortingDropdown.onValueChanged.AddListener((index) => {
            if (index >= defaultSortings.Length)
            {
                string[] order = appSettings.SortingOrders[index - defaultSortings.Length].SortingOrderItemIds;
                SortByItem(order);
            }
            else
            {
                switch (index)
                {
                case 0:
                case 1:
                    SortByName(index == 0);
                    break;

                case 2:
                case 3:
                    SortByPrice(Payments.Products.Price.Currency.USDollars, index == 2);
                    break;
                }
            }
        });
        #endregion

        // Update sorting.
        sortingDropdown.onValueChanged?.Invoke(0);

        onShopLoaded?.Invoke();

        purchaseButton.onClick.AddListener(() => {
            OnPurchaseItem?.Invoke(activeItem);
        });
    }
Exemple #7
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));
        }