Beispiel #1
0
        public ActionResult PayMoney(PayMoneyCommand payMoneyCommand, User currentUser)
        {
            Require.NotNull(payMoneyCommand, "payMoneyCommand");

            if (!ModelState.IsValid)
            {
                IList <UserGroupMembership> otherMembershipsInUsersGroups = FindOtherMembershipsInUsersGroups(currentUser, null);
                return(View("PayMoney", new PayMoneyViewModel(otherMembershipsInUsersGroups, payMoneyCommand)));
            }

            UserGroupMembership sender = UserGroupService.FindMembershipsByUserAndGroup(currentUser, payMoneyCommand.Recipient.UserGroup);

            switch (payMoneyCommand.PaymentDto.PaymentType)
            {
            case PaymentType.PayPal: {
                return(PayWithPayPal(payMoneyCommand, sender, currentUser));
            }

            case PaymentType.Cash: {
                return(PayCash(payMoneyCommand, sender, currentUser));
            }

            default: {
                throw new ArgumentOutOfRangeException();
            }
            }
        }
Beispiel #2
0
        public void TestPayMoneyCommandFor100MakesPlayerPay100ToBank()
        {
            var playerId        = 0;
            var banker          = new TraditionalBanker(new[] { playerId });
            var payMoneyCommand = new PayMoneyCommand(banker, 100);

            payMoneyCommand.PerformOn(playerId);

            Assert.That(banker.GetBalanceFor(playerId), Is.EqualTo(1400));
        }
Beispiel #3
0
        private ActionResult PayCash(PayMoneyCommand payMoneyCommand, UserGroupMembership sender, User currentUser)
        {
            string paymentUrl = Url.Action("PendingPayments", "Payment", null, Request.Url.Scheme);

            PaymentService.Create(payMoneyCommand.PaymentDto,
                                  payMoneyCommand.Recipient.Account,
                                  sender.Account,
                                  payMoneyCommand.Recipient.User,
                                  sender.User,
                                  currentUser,
                                  paymentUrl);

            return(RedirectToAction("Index", "Payment"));
        }
Beispiel #4
0
        private ActionResult PayWithPayPal(PayMoneyCommand payMoneyCommand, UserGroupMembership sender, User currentUser)
        {
            string  paymentUrl = Url.Action("PendingPayments", "Payment", null, Request.Url.Scheme);
            Payment payment    = PaymentService.Create(payMoneyCommand.PaymentDto,
                                                       payMoneyCommand.Recipient.Account,
                                                       sender.Account,
                                                       payMoneyCommand.Recipient.User,
                                                       sender.User,
                                                       currentUser,
                                                       paymentUrl);

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(PayPalUrl);

            webRequest.Method      = "post";
            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.ServerCertificateValidationCallback = delegate {
                return(true);
            };
            ServicePointManager.ServerCertificateValidationCallback = delegate {
                return(true);
            };
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
            PayPalPaymentCommand payPalPaymentCommand = new PayPalPaymentCommand(
                payMoneyCommand.PaymentDto.Amount,
                payMoneyCommand.PaymentDto.Text,
                payMoneyCommand.Recipient.User,
                Url.Action("PayPalSuccess", "Payment", new { payment = payment.BusinessId }, Request.Url.Scheme),
                Url.Action("PayPalCancel", "Payment", new { payment = payment.BusinessId }, Request.Url.Scheme)
                );
            string        postData = payPalPaymentCommand.ToString();
            ASCIIEncoding ascii    = new ASCIIEncoding();

            byte[] postBytes = ascii.GetBytes(postData);

            using (Stream dataStream = webRequest.GetRequestStream()) {
                dataStream.Write(postBytes, 0, postBytes.Length);
            }

            WebResponse response = webRequest.GetResponse();

            /*Weiterleiten*/
            return(Redirect(response.ResponseUri.ToString()));
        }