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 { } }
public async Task <TransactionResult> Confirm(PayUConfirmation confirmation) { var log = new PaymentConfirmationLog() { ProcessDate = DateTime.Now, TransactionId = new Guid(confirmation.reference_sale), RawData = Newtonsoft.Json.JsonConvert.SerializeObject(confirmation), ReferencePayU = confirmation.reference_pol, ResponseCodePol = confirmation.response_code_pol, ResponseMessagePol = confirmation.response_message_pol, StatePol = confirmation.state_pol }; context.PaymentConfirmationLogs.Add(log); await context.SaveChangesAsync(); var success = confirmation.state_pol.Equals("4"); var transactionResult = new TransactionResult() { Success = success }; await SaveTransactionConfirmation(log.TransactionId, log); return(transactionResult); }
private async Task SaveTransactionConfirmation(Guid transactionId, PaymentConfirmationLog log) { var transaction = await context.Transactions.SingleOrDefaultAsync(tran => tran.Id == transactionId); transaction.ConfirmationDate = DateTime.Now; transaction.Approved = log.StatePol.Equals("4"); transaction.Closed = true; transaction.Status = log.ResponseMessagePol; context.Entry(transaction).State = EntityState.Modified; await context.SaveChangesAsync(); }