-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30018cc
commit cc028d3
Showing
3 changed files
with
65 additions
and
8 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
BancoAlimentar.AlimentaEstaIdeia.Tools/EasyPay/UpdatedNullCompletedDataTimePaymentsTool.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
BancoAlimentar.AlimentaEstaIdeia.Tools/Properties/launchSettings.json
This file was deleted.
Oops, something went wrong.