Skip to content

Commit

Permalink
Solved issue #783
Browse files Browse the repository at this point in the history
  • Loading branch information
guerrerotook committed Dec 9, 2024
1 parent 30018cc commit cc028d3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using BancoAlimentar.AlimentaEstaIdeia.Model;
using BancoAlimentar.AlimentaEstaIdeia.Repository;
using Easypay.Rest.Client.Api;
using Easypay.Rest.Client.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BancoAlimentar.AlimentaEstaIdeia.Tools.EasyPay
{
internal class UpdatedNullCompletedDataTimePaymentsTool : EasyPayTool
{
public UpdatedNullCompletedDataTimePaymentsTool(
ApplicationDbContext context,
IUnitOfWork unitOfWork,
IConfiguration configuration)
: base(context, unitOfWork, configuration)
{

}

public override void ExecuteTool()
{
List<BasePayment> paymentsWithNullCompleted = this.Context.Donations
.Include(p => p.ConfirmedPayment)
.Where(p => p.PaymentStatus == PaymentStatus.Payed && p.ConfirmedPayment.Completed == null)
.Select(p => p.ConfirmedPayment)
.ToList();

SinglePaymentApi client = this.GetSinglePaymentApi();

foreach (EasyPayBaseClass item in paymentsWithNullCompleted.OfType<EasyPayBaseClass>())
{
if (!string.IsNullOrEmpty(item.EasyPayPaymentId))
{
Easypay.Rest.Client.Model.Single payment = client.SingleIdGet(Guid.Parse(item.EasyPayPaymentId));
SingleCaptureFull capture = payment.Capture
.Where(p => p.Status == Easypay.Rest.Client.Model.CaptureStatus.Success)
.FirstOrDefault();
if (capture != null)
{
item.Completed = payment.Capture.First().CaptureDate.ToDateTime(TimeOnly.MinValue);
this.Context.Entry(item).State = EntityState.Modified;
}
else
{
Console.WriteLine("We didn't found a completed payment");
}
}
}

this.Context.SaveChanges();
}
}
}
6 changes: 6 additions & 0 deletions BancoAlimentar.AlimentaEstaIdeia.Tools/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BancoAlimentar.AlimentaEstaIdeia.Model;
using BancoAlimentar.AlimentaEstaIdeia.Repository;
using BancoAlimentar.AlimentaEstaIdeia.Tools.Database;
using BancoAlimentar.AlimentaEstaIdeia.Tools.EasyPay;
using BancoAlimentar.AlimentaEstaIdeia.Tools.KeyVault;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
Expand Down Expand Up @@ -47,6 +48,11 @@ static void Main(string[] args)
// config.UnitOfWork,
// Configuration);
//deleteAllSubscriptionsTool.ExecuteTool();
//UpdatedNullCompletedDataTimePaymentsTool updatedNullCompletedDataTimePaymentsTool = new UpdatedNullCompletedDataTimePaymentsTool(
// config.ApplicationDbContext,
// config.UnitOfWork,
// Configuration);
//updatedNullCompletedDataTimePaymentsTool.ExecuteTool();

//ConsodilatePaymentsWithNullDonationId consodilatePaymentsWithNullDonationId =
// new ConsodilatePaymentsWithNullDonationId(config.ApplicationDbContext, config.UnitOfWork);
Expand Down

This file was deleted.

0 comments on commit cc028d3

Please sign in to comment.