Skip to content

Commit 9797e10

Browse files
committed
feat: Add prepayment always required test case (#188)
1 parent 00f54a7 commit 9797e10

17 files changed

+95
-46
lines changed

Examples/BookingSystem.AspNetCore/Feeds/FacilitiesFeeds.cs

+12-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ namespace BookingSystem
1414
public class AcmeFacilityUseRpdeGenerator : RpdeFeedModifiedTimestampAndIdLong<FacilityOpportunity, FacilityUse>
1515
{
1616
//public override string FeedPath { get; protected set; } = "example path override";
17-
private readonly bool _useSingleSellerMode;
17+
private readonly AppSettings _appSettings;
1818

1919
// Example constructor that can set state
20-
public AcmeFacilityUseRpdeGenerator(bool useSingleSellerMode)
20+
public AcmeFacilityUseRpdeGenerator(AppSettings appSettings)
2121
{
22-
_useSingleSellerMode = useSingleSellerMode;
22+
this._appSettings = appSettings;
2323
}
2424

2525
protected override async Task<List<RpdeItem<FacilityUse>>> GetRpdeItems(long? afterTimestamp, long? afterId)
@@ -55,7 +55,7 @@ protected override async Task<List<RpdeItem<FacilityUse>>> GetRpdeItems(long? af
5555
FacilityUseId = result.Item1.Id
5656
}),
5757
Name = result.Item1.Name,
58-
Provider = _useSingleSellerMode ? new Organization
58+
Provider = _appSettings.FeatureFlags.SingleSeller ? new Organization
5959
{
6060
Id = RenderSingleSellerId(),
6161
Name = "Test Seller",
@@ -123,6 +123,13 @@ protected override async Task<List<RpdeItem<FacilityUse>>> GetRpdeItems(long? af
123123
public class AcmeFacilityUseSlotRpdeGenerator : RpdeFeedModifiedTimestampAndIdLong<FacilityOpportunity, Slot>
124124
{
125125
//public override string FeedPath { get; protected set; } = "example path override";
126+
private readonly AppSettings _appSettings;
127+
128+
// Example constructor that can set state
129+
public AcmeFacilityUseSlotRpdeGenerator(AppSettings appSettings)
130+
{
131+
this._appSettings = appSettings;
132+
}
126133

127134
protected override async Task<List<RpdeItem<Slot>>> GetRpdeItems(long? afterTimestamp, long? afterId)
128135
{
@@ -178,7 +185,7 @@ protected override async Task<List<RpdeItem<Slot>>> GetRpdeItems(long? afterTime
178185
OpenBookingFlowRequirement = OpenBookingFlowRequirement(x),
179186
ValidFromBeforeStartDate = x.ValidFromBeforeStartDate,
180187
LatestCancellationBeforeStartDate = x.LatestCancellationBeforeStartDate,
181-
OpenBookingPrepayment = x.Prepayment.Convert(),
188+
OpenBookingPrepayment = _appSettings.FeatureFlags.PrepaymentAlwaysRequired ? null : x.Prepayment.Convert(),
182189
AllowCustomerCancellationFullRefund = x.AllowCustomerCancellationFullRefund,
183190
}
184191
},

Examples/BookingSystem.AspNetCore/Feeds/OrdersFeed.cs

+16-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ public class AcmeOrdersFeedRpdeGenerator : OrdersRPDEFeedModifiedTimestampAndID
1414
{
1515
//public override string FeedPath { get; protected set; } = "example path override";
1616

17+
private readonly AppSettings _appSettings;
18+
19+
public AcmeOrdersFeedRpdeGenerator(AppSettings appSettings)
20+
{
21+
_appSettings = appSettings;
22+
}
23+
1724
protected override async Task<List<RpdeItem>> GetRPDEItems(string clientId, long? afterTimestamp, string afterId)
1825
{
1926
// Note if using SQL Server it is best to use rowversion as the modified value for the Orders table,
@@ -52,7 +59,7 @@ protected override async Task<List<RpdeItem>> GetRPDEItems(string clientId, long
5259
Modified = result.OrderTable.OrderModified,
5360
State = result.OrderTable.Deleted || result.OrderTable.VisibleInOrdersFeed == FeedVisibility.Archived ? RpdeState.Deleted : RpdeState.Updated,
5461
Data = result.OrderTable.Deleted || result.OrderTable.VisibleInOrdersFeed == FeedVisibility.Archived ? null :
55-
AcmeOrderStore.RenderOrderFromDatabaseResult(RenderOrderId(result.OrderTable.OrderMode == OrderMode.Proposal ? OrderType.OrderProposal : OrderType.Order, new Guid(result.OrderTable.OrderId)), result.OrderTable,
62+
AcmeOrderStore.RenderOrderFromDatabaseResult(RenderOrderId(result.OrderTable.OrderMode == OrderMode.Proposal ? OrderType.OrderProposal : OrderType.Order, new Guid(result.OrderTable.OrderId)), result.OrderTable, _appSettings.FeatureFlags.PrepaymentAlwaysRequired,
5663
result.OrderItemsTable.Select(orderItem => new OrderItem
5764
{
5865
Id = RenderOrderItemId(OrderType.Order, new Guid(result.OrderTable.OrderId), orderItem.Id),
@@ -110,6 +117,13 @@ public class AcmeOrderProposalsFeedRpdeGenerator : OrdersRPDEFeedModifiedTimesta
110117
{
111118
//public override string FeedPath { get; protected set; } = "example path override";
112119

120+
private readonly AppSettings _appSettings;
121+
122+
public AcmeOrderProposalsFeedRpdeGenerator(AppSettings appSettings)
123+
{
124+
_appSettings = appSettings;
125+
}
126+
113127
protected override async Task<List<RpdeItem>> GetRPDEItems(string clientId, long? afterTimestamp, string afterId)
114128
{
115129
using (var db = FakeBookingSystem.Database.Mem.Database.Open())
@@ -144,7 +158,7 @@ protected override async Task<List<RpdeItem>> GetRPDEItems(string clientId, long
144158
Modified = result.OrderTable.OrderProposalModified,
145159
State = result.OrderTable.Deleted || result.OrderTable.VisibleInOrderProposalsFeed == FeedVisibility.Archived ? RpdeState.Deleted : RpdeState.Updated,
146160
Data = result.OrderTable.Deleted || result.OrderTable.VisibleInOrderProposalsFeed == FeedVisibility.Archived ? null :
147-
AcmeOrderStore.RenderOrderFromDatabaseResult(RenderOrderId(result.OrderTable.OrderMode == OrderMode.Proposal ? OrderType.OrderProposal : OrderType.Order, new Guid(result.OrderTable.OrderId)), result.OrderTable,
161+
AcmeOrderStore.RenderOrderFromDatabaseResult(RenderOrderId(result.OrderTable.OrderMode == OrderMode.Proposal ? OrderType.OrderProposal : OrderType.Order, new Guid(result.OrderTable.OrderId)), result.OrderTable, _appSettings.FeatureFlags.PrepaymentAlwaysRequired,
148162
result.OrderItemsTable.Select(orderItem => new OrderItem
149163
{
150164
Id = RenderOrderItemId(OrderType.Order, new Guid(result.OrderTable.OrderId), orderItem.Id),

Examples/BookingSystem.AspNetCore/Feeds/SessionsFeeds.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ protected override async Task<List<RpdeItem<ScheduledSession>>> GetRpdeItems(lon
6464

6565
public class AcmeSessionSeriesRpdeGenerator : RpdeFeedModifiedTimestampAndIdLong<SessionOpportunity, SessionSeries>
6666
{
67-
private readonly bool _useSingleSellerMode;
67+
private readonly AppSettings _appSettings;
6868

6969
// Example constructor that can set state from EngineConfig
70-
public AcmeSessionSeriesRpdeGenerator(bool useSingleSellerMode)
70+
public AcmeSessionSeriesRpdeGenerator(AppSettings appSettings)
7171
{
72-
this._useSingleSellerMode = useSingleSellerMode;
72+
this._appSettings = appSettings;
7373
}
7474

7575
protected override async Task<List<RpdeItem<SessionSeries>>> GetRpdeItems(long? afterTimestamp, long? afterId)
@@ -106,7 +106,7 @@ protected override async Task<List<RpdeItem<SessionSeries>>> GetRpdeItems(long?
106106
}),
107107
Name = result.Item1.Title,
108108
EventAttendanceMode = MapAttendanceMode(result.Item1.AttendanceMode),
109-
Organizer = _useSingleSellerMode ? new Organization
109+
Organizer = _appSettings.FeatureFlags.SingleSeller ? new Organization
110110
{
111111
Id = RenderSingleSellerId(),
112112
Name = "Test Seller",
@@ -156,7 +156,7 @@ protected override async Task<List<RpdeItem<SessionSeries>>> GetRpdeItems(long?
156156
OpenBookingFlowRequirement = OpenBookingFlowRequirement(result.Item1),
157157
ValidFromBeforeStartDate = result.Item1.ValidFromBeforeStartDate,
158158
LatestCancellationBeforeStartDate = result.Item1.LatestCancellationBeforeStartDate,
159-
OpenBookingPrepayment = result.Item1.Prepayment.Convert(),
159+
OpenBookingPrepayment = _appSettings.FeatureFlags.PrepaymentAlwaysRequired ? null : result.Item1.Prepayment.Convert(),
160160
AllowCustomerCancellationFullRefund = result.Item1.AllowCustomerCancellationFullRefund
161161
}
162162
},

Examples/BookingSystem.AspNetCore/Settings/AppSettings.cs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class FeatureSettings
1717
public bool SingleSeller { get; set; } = false;
1818
public bool PaymentReconciliationDetailValidation { get; set; } = true;
1919
public bool OnlyFreeOpportunities { get; set; } = false;
20+
public bool PrepaymentAlwaysRequired { get; set; } = false;
2021
}
2122

2223
public class PaymentSettings

Examples/BookingSystem.AspNetCore/Settings/EngineConfig.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ public static StoreBookingEngine CreateStoreBookingEngine(AppSettings appSetting
141141
OpportunityType.ScheduledSession, new AcmeScheduledSessionRpdeGenerator()
142142
},
143143
{
144-
OpportunityType.SessionSeries, new AcmeSessionSeriesRpdeGenerator(appSettings.FeatureFlags.SingleSeller)
144+
OpportunityType.SessionSeries, new AcmeSessionSeriesRpdeGenerator(appSettings)
145145
},
146146
{
147-
OpportunityType.FacilityUse, new AcmeFacilityUseRpdeGenerator(appSettings.FeatureFlags.SingleSeller)
147+
OpportunityType.FacilityUse, new AcmeFacilityUseRpdeGenerator(appSettings)
148148
},
149149
{
150-
OpportunityType.FacilityUseSlot, new AcmeFacilityUseSlotRpdeGenerator()
150+
OpportunityType.FacilityUseSlot, new AcmeFacilityUseSlotRpdeGenerator(appSettings)
151151
}
152152
},
153153

@@ -157,8 +157,8 @@ public static StoreBookingEngine CreateStoreBookingEngine(AppSettings appSetting
157157
"{+BaseUrl}/{OrderType}/{uuid}",
158158
"{+BaseUrl}/{OrderType}/{uuid}#/orderedItems/{OrderItemIdLong}"),
159159

160-
OrdersFeedGenerator = new AcmeOrdersFeedRpdeGenerator(),
161-
OrderProposalsFeedGenerator = new AcmeOrderProposalsFeedRpdeGenerator()
160+
OrdersFeedGenerator = new AcmeOrdersFeedRpdeGenerator(appSettings),
161+
OrderProposalsFeedGenerator = new AcmeOrderProposalsFeedRpdeGenerator(appSettings)
162162
},
163163
new DatasetSiteGeneratorSettings
164164
{
@@ -259,7 +259,7 @@ public static StoreBookingEngine CreateStoreBookingEngine(AppSettings appSetting
259259
BusinessToBusinessTaxCalculation = appSettings.Payment.TaxCalculationB2B,
260260
BusinessToConsumerTaxCalculation = appSettings.Payment.TaxCalculationB2C,
261261
EnforceSyncWithinOrderTransactions = false,
262-
PrepaymentAlwaysRequired = false
262+
PrepaymentAlwaysRequired = appSettings.FeatureFlags.PrepaymentAlwaysRequired
263263
});
264264
}
265265
}

Examples/BookingSystem.AspNetCore/Stores/FacilityStore.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ protected override async Task GetOrderItems(List<OrderItemContext<FacilityOpport
315315
Price = slot.Price,
316316
PriceCurrency = "GBP",
317317
LatestCancellationBeforeStartDate = slot.LatestCancellationBeforeStartDate,
318-
OpenBookingPrepayment = slot.Prepayment.Convert(),
318+
OpenBookingPrepayment = _appSettings.FeatureFlags.PrepaymentAlwaysRequired ? null : slot.Prepayment.Convert(),
319319
ValidFromBeforeStartDate = slot.ValidFromBeforeStartDate,
320320
AllowCustomerCancellationFullRefund = slot.AllowCustomerCancellationFullRefund,
321321
},

Examples/BookingSystem.AspNetCore/Stores/OrderStore.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public static Order CreateOrderFromOrderMode(OrderMode orderMode, Uri orderId, G
424424
}
425425
}
426426

427-
public static Order RenderOrderFromDatabaseResult(Uri orderId, OrderTable dbOrder, List<OrderItem> orderItems)
427+
public static Order RenderOrderFromDatabaseResult(Uri orderId, OrderTable dbOrder, bool prepaymentAlwaysRequired, List<OrderItem> orderItems)
428428
{
429429
var order = CreateOrderFromOrderMode(dbOrder.OrderMode, orderId, dbOrder.ProposalVersionId, dbOrder.ProposalStatus);
430430
order.Id = orderId;
@@ -433,7 +433,7 @@ public static Order RenderOrderFromDatabaseResult(Uri orderId, OrderTable dbOrde
433433
{
434434
Price = dbOrder.TotalOrderPrice,
435435
PriceCurrency = "GBP",
436-
OpenBookingPrepayment = OrderCalculations.GetRequiredStatusType(orderItems)
436+
OpenBookingPrepayment = prepaymentAlwaysRequired ? null : OrderCalculations.GetRequiredStatusType(orderItems)
437437
};
438438
order.OrderedItem = orderItems;
439439

@@ -470,7 +470,7 @@ public override async Task<Order> GetOrderStatus(OrderIdComponents orderId, Simp
470470
OrderItemIntakeFormResponse = orderItem.AdditionalDetailsString != null ? OpenActiveSerializer.DeserializeList<PropertyValue>(orderItem.AdditionalDetailsString) : null,
471471
};
472472
}).ToList();
473-
var order = RenderOrderFromDatabaseResult(orderIdUri, dbOrder, orderItems);
473+
var order = RenderOrderFromDatabaseResult(orderIdUri, dbOrder, _appSettings.FeatureFlags.PrepaymentAlwaysRequired, orderItems);
474474

475475
// Map AcceptedOffer from object to IdReference
476476
var mappedOrderItems = order.OrderedItem.Select((orderItem) => new OrderItem

Examples/BookingSystem.AspNetCore/Stores/SessionStore.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ protected override async Task GetOrderItems(List<OrderItemContext<SessionOpportu
336336
Price = @class.Price,
337337
PriceCurrency = "GBP",
338338
LatestCancellationBeforeStartDate = @class.LatestCancellationBeforeStartDate,
339-
OpenBookingPrepayment = @class.Prepayment.Convert(),
339+
OpenBookingPrepayment = _appSettings.FeatureFlags.PrepaymentAlwaysRequired ? null : @class.Prepayment.Convert(),
340340
ValidFromBeforeStartDate = @class.ValidFromBeforeStartDate,
341341
AllowCustomerCancellationFullRefund = @class.AllowCustomerCancellationFullRefund,
342342
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"FeatureFlags": {
3+
"PrepaymentAlwaysRequired": true
4+
}
5+
}

Examples/BookingSystem.AspNetFramework/Feeds/FacilitiesFeeds.cs

+12-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ namespace BookingSystem
1414
public class AcmeFacilityUseRpdeGenerator : RpdeFeedModifiedTimestampAndIdLong<FacilityOpportunity, FacilityUse>
1515
{
1616
//public override string FeedPath { get; protected set; } = "example path override";
17-
private readonly bool _useSingleSellerMode;
17+
private readonly AppSettings _appSettings;
1818

1919
// Example constructor that can set state
20-
public AcmeFacilityUseRpdeGenerator(bool useSingleSellerMode)
20+
public AcmeFacilityUseRpdeGenerator(AppSettings appSettings)
2121
{
22-
_useSingleSellerMode = useSingleSellerMode;
22+
this._appSettings = appSettings;
2323
}
2424

2525
protected override async Task<List<RpdeItem<FacilityUse>>> GetRpdeItems(long? afterTimestamp, long? afterId)
@@ -55,7 +55,7 @@ protected override async Task<List<RpdeItem<FacilityUse>>> GetRpdeItems(long? af
5555
FacilityUseId = result.Item1.Id
5656
}),
5757
Name = result.Item1.Name,
58-
Provider = _useSingleSellerMode ? new Organization
58+
Provider = _appSettings.FeatureFlags.SingleSeller ? new Organization
5959
{
6060
Id = RenderSingleSellerId(),
6161
Name = "Test Seller",
@@ -123,6 +123,13 @@ protected override async Task<List<RpdeItem<FacilityUse>>> GetRpdeItems(long? af
123123
public class AcmeFacilityUseSlotRpdeGenerator : RpdeFeedModifiedTimestampAndIdLong<FacilityOpportunity, Slot>
124124
{
125125
//public override string FeedPath { get; protected set; } = "example path override";
126+
private readonly AppSettings _appSettings;
127+
128+
// Example constructor that can set state
129+
public AcmeFacilityUseSlotRpdeGenerator(AppSettings appSettings)
130+
{
131+
this._appSettings = appSettings;
132+
}
126133

127134
protected override async Task<List<RpdeItem<Slot>>> GetRpdeItems(long? afterTimestamp, long? afterId)
128135
{
@@ -178,7 +185,7 @@ protected override async Task<List<RpdeItem<Slot>>> GetRpdeItems(long? afterTime
178185
OpenBookingFlowRequirement = OpenBookingFlowRequirement(x),
179186
ValidFromBeforeStartDate = x.ValidFromBeforeStartDate,
180187
LatestCancellationBeforeStartDate = x.LatestCancellationBeforeStartDate,
181-
OpenBookingPrepayment = x.Prepayment.Convert(),
188+
OpenBookingPrepayment = _appSettings.FeatureFlags.PrepaymentAlwaysRequired ? null : x.Prepayment.Convert(),
182189
AllowCustomerCancellationFullRefund = x.AllowCustomerCancellationFullRefund,
183190
}
184191
},

0 commit comments

Comments
 (0)