74 lines
2.6 KiB
C#
74 lines
2.6 KiB
C#
using Hutopy.Application.Common.Interfaces;
|
|
|
|
namespace Hutopy.Application.Stripe.Commands;
|
|
public class ConfirmStripeTransactionCommand : IRequest<string>
|
|
{
|
|
public string Id { get; set; }
|
|
public string Object { get; set; }
|
|
public int Created { get; set; }
|
|
public Data Data { get; set; }
|
|
public Request Request { get; set; }
|
|
}
|
|
|
|
public class Data
|
|
{
|
|
public Object Object { get; set; }
|
|
}
|
|
|
|
public class Object
|
|
{
|
|
public string Id { get; set; } = String.Empty;
|
|
public int Amount { get; set; }
|
|
public BillingDetails Billing_details { get; set; } = new();
|
|
public string Calculated_statement_descriptor { get; set; } = String.Empty;
|
|
public string Currency { get; set; } = String.Empty;
|
|
public bool Paid { get; set; }
|
|
public string Payment_intent { get; set; } = String.Empty;
|
|
public string Payment_method { get; set; } = String.Empty;
|
|
public string Receipt_url { get; set; } = String.Empty;
|
|
public string Status { get; set; } = String.Empty;
|
|
public string Failure_message { get; set; } = String.Empty;
|
|
}
|
|
|
|
public class BillingDetails
|
|
{
|
|
public string Email { get; set; } = String.Empty;
|
|
public string Name { get; set; } = String.Empty;
|
|
public string Phone { get; set; } = String.Empty;
|
|
}
|
|
|
|
public class Request
|
|
{
|
|
public string Id { get; set; } = String.Empty;
|
|
}
|
|
|
|
public class ConfirmStripeTransactionCommandHandler(
|
|
IApplicationDbContext dbContext,
|
|
IStripeService stripeService
|
|
)
|
|
: IRequestHandler<ConfirmStripeTransactionCommand, string>
|
|
{
|
|
public async Task<string> Handle(ConfirmStripeTransactionCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var lastTransaction = await dbContext.UserTransactions.OrderBy(x => x.Created).LastAsync(cancellationToken);
|
|
var stripeConfirmation = stripeService.ValidateTransaction(request);
|
|
|
|
if (stripeConfirmation.Succeeded)
|
|
{
|
|
lastTransaction.IsConfirmed = true;
|
|
}
|
|
lastTransaction.Paid = request.Data.Object.Paid;
|
|
lastTransaction.StripeChargeId = request.Data.Object.Id;
|
|
lastTransaction.StripeEventId = request.Id;
|
|
lastTransaction.StripeReceiptUrl = request.Data.Object.Receipt_url;
|
|
lastTransaction.StripePaymentIntent = request.Data.Object.Payment_intent;
|
|
lastTransaction.StripePaymentMethod = request.Data.Object.Payment_method;
|
|
lastTransaction.StripeBillingDetailEmail = request.Data.Object.Billing_details.Email;
|
|
lastTransaction.StripeBillingDetailName = request.Data.Object.Billing_details.Name;
|
|
|
|
await dbContext.SaveChangesAsync(cancellationToken);
|
|
|
|
return "";
|
|
}
|
|
}
|