Hello {{Customer.FullName | Escape}},
+The recurring payment for order #{{Order.OrderNumber}} at {{Store.Name}} is cancelled. You will not be charged for further cycles.
+Every {{RecurringPayment.CycleLength}} {{RecurringPayment.CyclePeriod}}{% if RecurringPayment.TotalCycles > 0 %}, {{RecurringPayment.CyclesPaid}} of {{RecurringPayment.TotalCycles}} paid{% endif %}
+ " + Button("{{Order.OrderURLForCustomer}}", "View the order") + @" +To buy again, place a new order.
"), + IsActive = true, + EmailAccountId = ea + }, + new() { + Name = "RecurringPayment.Cancelled.StoreOwnerNotification", + Subject = "{{Store.Name}}: recurring payment for order #{{Order.OrderNumber}} cancelled", + Body = Layout( + "A recurring payment was cancelled.", + "Recurring payment cancelled", + @"The recurring payment for order #{{Order.OrderNumber}} ({{Customer.Email | Escape}}) was cancelled. Cancelled by: {{RecurringPayment.CancelledBy}}.
+Every {{RecurringPayment.CycleLength}} {{RecurringPayment.CyclePeriod}}{% if RecurringPayment.TotalCycles > 0 %}, {{RecurringPayment.CyclesPaid}} of {{RecurringPayment.TotalCycles}} paid{% endif %}
"), + IsActive = true, + EmailAccountId = ea + }, + new() { + Name = "RecurringPayment.PaymentFailed.CustomerNotification", + Subject = "{{Store.Name}}: the payment for order #{{Order.OrderNumber}} could not be taken", + Body = Layout( + "A payment for your recurring order could not be taken.", + "Payment failed", + @"Hello {{Customer.FullName | Escape}},
+The payment for the next cycle of your recurring payment for order #{{Order.OrderNumber}} could not be taken{% if RecurringPayment.LastError != '' %}: {{RecurringPayment.LastError}}{% endif %}.
+The payment provider may try again. Please check that your payment details are up to date.
+A cycle of the recurring payment for order #{{Order.OrderNumber}} ({{Customer.Email | Escape}}) failed{% if RecurringPayment.LastError != '' %}: {{RecurringPayment.LastError}}{% endif %}.
+The payment provider may retry it.
+Every {{RecurringPayment.CycleLength}} {{RecurringPayment.CyclePeriod}}{% if RecurringPayment.TotalCycles > 0 %}, {{RecurringPayment.CyclesPaid}} of {{RecurringPayment.TotalCycles}} paid{% endif %}
"), + IsActive = true, + EmailAccountId = ea + } + }; + } +} diff --git a/src/Modules/Grand.Module.Installer/Services/MessageTemplates/MessageTemplateSeed.cs b/src/Modules/Grand.Module.Installer/Services/MessageTemplates/MessageTemplateSeed.cs index 692f494f5..459866574 100644 --- a/src/Modules/Grand.Module.Installer/Services/MessageTemplates/MessageTemplateSeed.cs +++ b/src/Modules/Grand.Module.Installer/Services/MessageTemplates/MessageTemplateSeed.cs @@ -15,6 +15,7 @@ public static ListHello {{Customer.FullName | Escape}},
+The recurring payment for order #{{Order.OrderNumber}} at {{Store.Name}} is cancelled. You will not be charged for further cycles.
+Every {{RecurringPayment.CycleLength}} {{RecurringPayment.CyclePeriod}}{% if RecurringPayment.TotalCycles > 0 %}, {{RecurringPayment.CyclesPaid}} of {{RecurringPayment.TotalCycles}} paid{% endif %}
+ " + Button("{{Order.OrderURLForCustomer}}", "View the order") + @" +To buy again, place a new order.
"), + IsActive = true, + EmailAccountId = emailAccountId + }, + new() { + Name = "RecurringPayment.Cancelled.StoreOwnerNotification", + Subject = "{{Store.Name}}: recurring payment for order #{{Order.OrderNumber}} cancelled", + Body = Layout( + "A recurring payment was cancelled.", + "Recurring payment cancelled", + @"The recurring payment for order #{{Order.OrderNumber}} ({{Customer.Email | Escape}}) was cancelled. Cancelled by: {{RecurringPayment.CancelledBy}}.
+Every {{RecurringPayment.CycleLength}} {{RecurringPayment.CyclePeriod}}{% if RecurringPayment.TotalCycles > 0 %}, {{RecurringPayment.CyclesPaid}} of {{RecurringPayment.TotalCycles}} paid{% endif %}
"), + IsActive = true, + EmailAccountId = emailAccountId + }, + new() { + Name = "RecurringPayment.PaymentFailed.CustomerNotification", + Subject = "{{Store.Name}}: the payment for order #{{Order.OrderNumber}} could not be taken", + Body = Layout( + "A payment for your recurring order could not be taken.", + "Payment failed", + @"Hello {{Customer.FullName | Escape}},
+The payment for the next cycle of your recurring payment for order #{{Order.OrderNumber}} could not be taken{% if RecurringPayment.LastError != '' %}: {{RecurringPayment.LastError}}{% endif %}.
+The payment provider may try again. Please check that your payment details are up to date.
+A cycle of the recurring payment for order #{{Order.OrderNumber}} ({{Customer.Email | Escape}}) failed{% if RecurringPayment.LastError != '' %}: {{RecurringPayment.LastError}}{% endif %}.
+The payment provider may retry it.
+Every {{RecurringPayment.CycleLength}} {{RecurringPayment.CyclePeriod}}{% if RecurringPayment.TotalCycles > 0 %}, {{RecurringPayment.CyclesPaid}} of {{RecurringPayment.TotalCycles}} paid{% endif %}
"), + IsActive = true, + EmailAccountId = emailAccountId + } + }; + } +} diff --git a/src/Tests/Grand.Business.Checkout.Tests/Commands/Handlers/Orders/CancelRecurringPaymentCommandHandlerTests.cs b/src/Tests/Grand.Business.Checkout.Tests/Commands/Handlers/Orders/CancelRecurringPaymentCommandHandlerTests.cs new file mode 100644 index 000000000..bf43e89cb --- /dev/null +++ b/src/Tests/Grand.Business.Checkout.Tests/Commands/Handlers/Orders/CancelRecurringPaymentCommandHandlerTests.cs @@ -0,0 +1,106 @@ +using Grand.Business.Checkout.Commands.Handlers.Orders; +using Grand.Business.Checkout.Services.Orders; +using Grand.Business.Core.Commands.Checkout.Orders; +using Grand.Business.Core.Interfaces.Catalog.Products; +using Grand.Business.Core.Interfaces.Checkout.Orders; +using Grand.Business.Core.Interfaces.Checkout.Payments; +using Grand.Business.Core.Utilities.Checkout; +using Grand.Data.Tests.MongoDb; +using Grand.Domain.Orders; +using Grand.Mediator; +using Microsoft.Extensions.Logging; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Grand.Business.Checkout.Tests.Commands.Handlers.Orders; + +[TestClass] +public class CancelRecurringPaymentCommandHandlerTests +{ + private Mock