2022-04-24 05:19:34 +02:00
|
|
|
using System;
|
2020-11-17 13:46:23 +01:00
|
|
|
using BTCPayServer.Abstractions.Contracts;
|
2022-04-24 05:19:34 +02:00
|
|
|
using BTCPayServer.Client.Models;
|
2020-06-24 10:34:09 +09:00
|
|
|
using BTCPayServer.Configuration;
|
|
|
|
using BTCPayServer.Controllers;
|
2023-02-21 03:06:27 +01:00
|
|
|
using ExchangeSharp;
|
2020-06-24 10:34:09 +09:00
|
|
|
using Microsoft.AspNetCore.Routing;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Services.Notifications.Blobs
|
|
|
|
{
|
2020-10-20 13:09:09 +02:00
|
|
|
public class PayoutNotification : BaseNotification
|
2020-06-24 10:34:09 +09:00
|
|
|
{
|
2020-10-20 13:09:09 +02:00
|
|
|
private const string TYPE = "payout";
|
|
|
|
|
2020-06-24 10:34:09 +09:00
|
|
|
internal class Handler : NotificationHandler<PayoutNotification>
|
|
|
|
{
|
|
|
|
private readonly LinkGenerator _linkGenerator;
|
|
|
|
private readonly BTCPayServerOptions _options;
|
|
|
|
|
|
|
|
public Handler(LinkGenerator linkGenerator, BTCPayServerOptions options)
|
|
|
|
{
|
|
|
|
_linkGenerator = linkGenerator;
|
|
|
|
_options = options;
|
|
|
|
}
|
2020-10-20 13:09:09 +02:00
|
|
|
|
|
|
|
public override string NotificationType => TYPE;
|
|
|
|
public override (string identifier, string name)[] Meta
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2021-12-31 16:59:02 +09:00
|
|
|
return new (string identifier, string name)[] { (TYPE, "Payouts") };
|
2020-10-20 13:09:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 10:34:09 +09:00
|
|
|
protected override void FillViewModel(PayoutNotification notification, NotificationViewModel vm)
|
|
|
|
{
|
2023-02-21 03:06:27 +01:00
|
|
|
vm.Identifier = notification.Identifier;
|
|
|
|
vm.Type = notification.NotificationType;
|
2024-07-02 09:55:54 +01:00
|
|
|
vm.StoreId = notification.StoreId;
|
2022-04-24 05:19:34 +02:00
|
|
|
vm.Body = (notification.Status ?? PayoutState.AwaitingApproval) switch
|
|
|
|
{
|
2023-02-21 03:06:27 +01:00
|
|
|
PayoutState.AwaitingApproval => "A new payout is awaiting for approval",
|
|
|
|
PayoutState.AwaitingPayment => "A new payout is approved and awaiting payment",
|
2022-04-24 05:19:34 +02:00
|
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
|
|
};
|
2022-01-07 12:32:00 +09:00
|
|
|
vm.ActionLink = _linkGenerator.GetPathByAction(nameof(UIStorePullPaymentsController.Payouts),
|
|
|
|
"UIStorePullPayments",
|
2024-05-01 10:22:07 +09:00
|
|
|
new { storeId = notification.StoreId, payoutMethodId = notification.PaymentMethod }, _options.RootPath);
|
2020-06-24 10:34:09 +09:00
|
|
|
}
|
|
|
|
}
|
2020-10-20 13:09:09 +02:00
|
|
|
|
2020-06-24 10:34:09 +09:00
|
|
|
public string PayoutId { get; set; }
|
|
|
|
public string StoreId { get; set; }
|
|
|
|
public string PaymentMethod { get; set; }
|
|
|
|
public string Currency { get; set; }
|
2023-02-21 03:06:27 +01:00
|
|
|
public override string Identifier => Status is null ? TYPE : $"{TYPE}_{Status.ToStringLowerInvariant()}";
|
|
|
|
|
2020-10-20 13:09:09 +02:00
|
|
|
public override string NotificationType => TYPE;
|
2022-04-24 05:19:34 +02:00
|
|
|
public PayoutState? Status { get; set; }
|
2020-06-24 10:34:09 +09:00
|
|
|
}
|
|
|
|
}
|