示例#1
0
        public async Task <PaymentProviderForm> SaveInitialTransaction(TransactionInputModel inputTransaction)
        {
            await ValidateTransaction(inputTransaction);

            Transaction transaction = MapTransactionFromInput(inputTransaction);

            context.Transactions.Add(transaction);
            await context.SaveChangesAsync();

            context.Entry(transaction).State = EntityState.Detached;

            var savedTransaction = await context.Transactions
                                   .Include(transac => transac.Customer)
                                   .Include(transac => transac.Details)
                                   .ThenInclude(detail => detail.TicketType)
                                   .AsNoTracking()
                                   .SingleOrDefaultAsync(m => m.Id == transaction.Id);

            savedTransaction.TotalValue = savedTransaction.GetTotalValue();

            var form = this.paymentProvider.GetPaymentForm(savedTransaction);

            savedTransaction.Signature            = form.Signature;
            savedTransaction.IsTestTransaction    = form.Test.Equals("1");
            context.Entry(savedTransaction).State = EntityState.Modified;
            await context.SaveChangesAsync();

            return(form);
        }
示例#2
0
        private async Task ConfirmPendingTransaction(Transaction transaction)
        {
            var orderInfo = await this.paymentProvider.GetOrderByReferenceId(transaction.Id.ToString("D"));

            if (orderInfo.result == null || orderInfo.result.payload == null || !orderInfo.result.payload.Any() || orderInfo.result.payload.First().transactions == null)
            {
                return;
            }

            try
            {
                var payUResult   = orderInfo.result.payload.First().transactions.First();
                var confirmation = new PaymentConfirmationLog();
                confirmation.TransactionId       = transaction.Id;
                confirmation.ProcessDate         = DateTime.Now;
                confirmation.ReferencePayU       = payUResult.id;
                confirmation.RawData             = JsonConvert.SerializeObject(orderInfo);
                confirmation.ResponseMessagePol  = payUResult.transactionResponse.state;
                context.Entry(transaction).State = EntityState.Modified;
                var confirmations = new List <PaymentConfirmationLog>();
                confirmations.Add(confirmation);
                transaction.Confirmations = confirmations;
                transaction.Closed        = true;
                transaction.Status        = confirmation.ResponseMessagePol;
                transaction.Approved      = string.Equals("APPROVED", payUResult.transactionResponse.state);
            }
            catch
            {
            }
        }