Exemple #1
0
        public void Can_VaBank_Context_Save_PaymentOrder_And_CardPayment()
        {
            long paymentNumber = 123;
            var priorCorrAcc = Context.Set<CorrespondentAccount>().Single(x => x.AccountNo == "3014153001749");
            var user = Context.Set<User>().Single(x => x.UserName == "terminator");
            var userPaymentProfile = Context.Set<UserPaymentProfile>().Single(x => x.UserId == user.Id);
            var userAccount = Context.Set<UserAccount>().First(x => x.Owner.Id == user.Id);
            var cardAccount = Context.Set<CardAccount>().Single(x => x.Owner.Id == user.Id && x.AccountNo == userAccount.AccountNo);
            var paymentOrderTemplate = Context.Set<PaymentOrderTemplate>().Single(x => x.TemplateCode == "PAYMENT-CELL-VELCOM-PHONENO");
            var currency = Context.Set<Currency>().Single(x => x.ISOName == "BYR");
            var paymentTemplate = Context.Set<PaymentTemplate>().Single(x => x.Code == paymentOrderTemplate.TemplateCode);
            var card = cardAccount.Cards.First();

            var paymentOrder = new PaymentOrder(
                paymentNumber,
                user.Profile.FirstName + " " + user.Profile.LastName,
                "153001966",
                cardAccount.AccountNo,
                userPaymentProfile.PayerTIN,
                paymentOrderTemplate.BeneficiaryName,
                paymentOrderTemplate.BeneficiaryBankCode,
                paymentOrderTemplate.BeneficiaryAccountNo,
                paymentOrderTemplate.BeneficiaryTIN,
                String.Format("Пополнение счета. Номер телефона: {0}", user.Profile.PhoneNumber),
                100000,
                currency.ISOName,
                paymentOrderTemplate.PaymentCode);

            var assembly = Assembly.GetExecutingAssembly();
            var form = JObject.Parse(new StreamReader(assembly.GetManifestResourceStream("VaBank.Data.Tests.EntityFramework.Templates.cell-velcom-phoneno.json")).ReadToEnd());
            var accountTo = Context.Set<CorrespondentAccount>().Single(x => x.Bank.Code == paymentOrderTemplate.BeneficiaryBankCode);
            var cardPayment = new CardPayment(card, paymentTemplate, paymentOrder, form, cardAccount, accountTo, currency);

            var paymentTransaction = new Transaction(cardAccount, currency, 100000, cardAccount.Balance, "123", "test_transaction_desc", "Nezavisimosti 58");
            var paymentTransactionLink = new PaymentTransactionLink(paymentTransaction, paymentOrder);

            Context.Set<PaymentOrder>().Add(paymentOrder);
            Context.Set<CardPayment>().Add(cardPayment);
            Context.SaveChanges();
        }
Exemple #2
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;
        }