InvoiceExpiredPaidPartial and InvoicePaidAfterExpiration webhooks

This commit is contained in:
rockstardev
2025-05-12 23:52:10 -05:00
parent 9afa45088e
commit 2b86d4c9dc
3 changed files with 35 additions and 4 deletions

View File

@@ -5,11 +5,13 @@ public static class WebhookEventType
{ {
public const string InvoiceCreated = nameof(InvoiceCreated); public const string InvoiceCreated = nameof(InvoiceCreated);
public const string InvoiceReceivedPayment = nameof(InvoiceReceivedPayment); public const string InvoiceReceivedPayment = nameof(InvoiceReceivedPayment);
public const string InvoicePaymentSettled = nameof(InvoicePaymentSettled);
public const string InvoiceProcessing = nameof(InvoiceProcessing); public const string InvoiceProcessing = nameof(InvoiceProcessing);
public const string InvoiceExpired = nameof(InvoiceExpired); public const string InvoiceExpired = nameof(InvoiceExpired);
public const string InvoiceSettled = nameof(InvoiceSettled); public const string InvoiceSettled = nameof(InvoiceSettled);
public const string InvoiceInvalid = nameof(InvoiceInvalid); public const string InvoiceInvalid = nameof(InvoiceInvalid);
public const string InvoicePaymentSettled = nameof(InvoicePaymentSettled); public const string InvoiceExpiredPaidPartial = nameof(InvoiceExpiredPaidPartial);
public const string InvoicePaidAfterExpiration = nameof(InvoicePaidAfterExpiration);
public const string PayoutCreated = nameof(PayoutCreated); public const string PayoutCreated = nameof(PayoutCreated);
public const string PayoutApproved = nameof(PayoutApproved); public const string PayoutApproved = nameof(PayoutApproved);
public const string PayoutUpdated = nameof(PayoutUpdated); public const string PayoutUpdated = nameof(PayoutUpdated);
@@ -18,5 +20,4 @@ public static class WebhookEventType
public const string PaymentRequestArchived = nameof(PaymentRequestArchived); public const string PaymentRequestArchived = nameof(PaymentRequestArchived);
public const string PaymentRequestStatusChanged = nameof(PaymentRequestStatusChanged); public const string PaymentRequestStatusChanged = nameof(PaymentRequestStatusChanged);
public const string PaymentRequestCompleted = nameof(PaymentRequestCompleted); public const string PaymentRequestCompleted = nameof(PaymentRequestCompleted);
} }

View File

@@ -29,6 +29,8 @@ public class InvoiceWebhookProvider : WebhookProvider<InvoiceEvent>
{WebhookEventType.InvoiceExpired, "Invoice - Expired"}, {WebhookEventType.InvoiceExpired, "Invoice - Expired"},
{WebhookEventType.InvoiceSettled, "Invoice - Is Settled"}, {WebhookEventType.InvoiceSettled, "Invoice - Is Settled"},
{WebhookEventType.InvoiceInvalid, "Invoice - Became Invalid"}, {WebhookEventType.InvoiceInvalid, "Invoice - Became Invalid"},
{WebhookEventType.InvoiceExpiredPaidPartial, "Invoice - Expired Paid Partial"},
{WebhookEventType.InvoicePaidAfterExpiration, "Invoice - Expired Paid Late"},
}; };
} }
@@ -113,6 +115,26 @@ public class InvoiceWebhookProvider : WebhookProvider<InvoiceEvent>
Payment = GreenfieldInvoiceController.ToPaymentModel(invoiceEvent.Invoice, invoiceEvent.Payment), Payment = GreenfieldInvoiceController.ToPaymentModel(invoiceEvent.Invoice, invoiceEvent.Payment),
StoreId = invoiceEvent.Invoice.StoreId StoreId = invoiceEvent.Invoice.StoreId
}; };
case InvoiceEventCode.ExpiredPaidPartial:
return new WebhookInvoiceReceivedPaymentEvent(WebhookEventType.InvoiceExpiredPaidPartial, storeId)
{
AfterExpiration =
invoiceEvent.Invoice.Status == InvoiceStatus.Expired ||
invoiceEvent.Invoice.Status == InvoiceStatus.Invalid,
PaymentMethodId = invoiceEvent.Payment.PaymentMethodId.ToString(),
Payment = GreenfieldInvoiceController.ToPaymentModel(invoiceEvent.Invoice, invoiceEvent.Payment),
StoreId = invoiceEvent.Invoice.StoreId
};
case InvoiceEventCode.PaidAfterExpiration:
return new WebhookInvoiceReceivedPaymentEvent(WebhookEventType.InvoicePaidAfterExpiration, storeId)
{
AfterExpiration =
invoiceEvent.Invoice.Status == InvoiceStatus.Expired ||
invoiceEvent.Invoice.Status == InvoiceStatus.Invalid,
PaymentMethodId = invoiceEvent.Payment.PaymentMethodId.ToString(),
Payment = GreenfieldInvoiceController.ToPaymentModel(invoiceEvent.Invoice, invoiceEvent.Payment),
StoreId = invoiceEvent.Invoice.StoreId
};
default: default:
return null; return null;
} }

View File

@@ -42,7 +42,7 @@
<div class="form-group"> <div class="form-group">
<label asp-for="Trigger" class="form-label" data-required></label> <label asp-for="Trigger" class="form-label" data-required></label>
<select asp-for="Trigger" asp-items="@WebhookSender.GetSupportedWebhookTypes() <select asp-for="Trigger" asp-items="@WebhookSender.GetSupportedWebhookTypes()
.OrderBy(a=>a.Value).Select(s => new SelectListItem(s.Value, s.Key))" .OrderBy(a=>a.Value).Select(s => new SelectListItem(s.Value, s.Key))"
class="form-select email-rule-trigger" required></select> class="form-select email-rule-trigger" required></select>
<span asp-validation-for="Trigger" class="text-danger"></span> <span asp-validation-for="Trigger" class="text-danger"></span>
<div class="form-text" text-translate="true">Choose what event sends the email.</div> <div class="form-text" text-translate="true">Choose what event sends the email.</div>
@@ -66,7 +66,7 @@
<input type="text" asp-for="Subject" class="form-control email-rule-subject" /> <input type="text" asp-for="Subject" class="form-control email-rule-subject" />
<span asp-validation-for="Subject" class="text-danger"></span> <span asp-validation-for="Subject" class="text-danger"></span>
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="Body" class="form-label" data-required></label> <label asp-for="Body" class="form-label" data-required></label>
<textarea asp-for="Body" class="form-control richtext email-rule-body" rows="4"></textarea> <textarea asp-for="Body" class="form-control richtext email-rule-body" rows="4"></textarea>
@@ -163,6 +163,14 @@
subject: 'Invoice {Invoice.Id} payment settled', subject: 'Invoice {Invoice.Id} payment settled',
body: 'Invoice {Invoice.Id} (Order Id: {Invoice.OrderId}) payment settled.' body: 'Invoice {Invoice.Id} (Order Id: {Invoice.OrderId}) payment settled.'
}, },
@WebhookEventType.InvoiceExpiredPaidPartial: {
subject: 'Invoice {Invoice.Id} Expired Paid Partial',
body: 'Invoice {Invoice.Id} (Order Id: {Invoice.OrderId}) has expired partially paid.'
},
@WebhookEventType.InvoicePaidAfterExpiration: {
subject: 'Invoice {Invoice.Id} Expired Paid Late',
body: 'Invoice {Invoice.Id} (Order Id: {Invoice.OrderId}) has been paid after expiration.'
},
@{ var paymentRequestsLink = CallbackGenerator.PaymentRequestListLink(storeId, this.Context.Request); } @{ var paymentRequestsLink = CallbackGenerator.PaymentRequestListLink(storeId, this.Context.Request); }
@WebhookEventType.PaymentRequestCompleted: { @WebhookEventType.PaymentRequestCompleted: {
subject: 'Payment Request {PaymentRequest.Title} {PaymentRequest.ReferenceId} Completed', subject: 'Payment Request {PaymentRequest.Title} {PaymentRequest.ReferenceId} Completed',