Add reviewed NMI hosted invoices and read-only payment reconciliation
This commit is contained in:
@@ -22,6 +22,7 @@ public interface IStore
|
||||
Task Import(Conversation message);
|
||||
Task<List<Conversation>> Deliveries();
|
||||
Task<bool> TryInsertPmsChange(PmsChange change);
|
||||
Task<bool> TryInsertPayment(PaymentRequest payment);
|
||||
}
|
||||
public sealed class MongoStore : IStore
|
||||
{
|
||||
@@ -42,6 +43,8 @@ public sealed class MongoStore : IStore
|
||||
}
|
||||
public async Task Initialize()
|
||||
{
|
||||
await Collection<PaymentRequest>().Indexes.CreateOneAsync(new CreateIndexModel<PaymentRequest>(Builders<PaymentRequest>.IndexKeys.Ascending(x=>x.HotelId).Ascending(x=>x.Reference),new(){Unique=true}));
|
||||
await Collection<PaymentRequest>().Indexes.CreateOneAsync(new CreateIndexModel<PaymentRequest>(Builders<PaymentRequest>.IndexKeys.Ascending(x=>x.HotelId).Descending(x=>x.UpdatedAt)));
|
||||
await Collection<PmsChange>().Indexes.CreateOneAsync(new CreateIndexModel<PmsChange>(Builders<PmsChange>.IndexKeys.Ascending(x=>x.HotelId).Ascending(x=>x.ReservationId),new CreateIndexOptions<PmsChange>{Unique=true,PartialFilterExpression=Builders<PmsChange>.Filter.In(x=>x.State,new[]{"Review","Applying","NeedsReview"})}));
|
||||
await Collection<PmsChange>().Indexes.CreateOneAsync(new CreateIndexModel<PmsChange>(Builders<PmsChange>.IndexKeys.Ascending(x=>x.HotelId).Descending(x=>x.UpdatedAt)));
|
||||
await Collection<PmsSnapshot>().Indexes.CreateOneAsync(new CreateIndexModel<PmsSnapshot>(Builders<PmsSnapshot>.IndexKeys.Ascending(x=>x.FetchedAt),new(){ExpireAfter=TimeSpan.FromDays(1)}));
|
||||
@@ -57,7 +60,7 @@ public sealed class MongoStore : IStore
|
||||
var query = Collection<T>().Find(Scope<T>(hotel));
|
||||
if (typeof(T) == typeof(Conversation)) query = query.Sort(Builders<T>.Sort.Descending("ReceivedAt"));
|
||||
if (typeof(T) == typeof(Activity)) query = query.Sort(Builders<T>.Sort.Descending("At"));
|
||||
if (typeof(T) == typeof(PmsChange)) query = query.Sort(Builders<T>.Sort.Descending("UpdatedAt"));
|
||||
if (typeof(T) == typeof(PmsChange) || typeof(T) == typeof(PaymentRequest)) query = query.Sort(Builders<T>.Sort.Descending("UpdatedAt"));
|
||||
return query.Limit(500).ToListAsync();
|
||||
}
|
||||
public async Task<T?> Get<T>(string hotel, string id) where T : TenantDocument => await Collection<T>().Find(Scope<T>(hotel) & Builders<T>.Filter.Eq(x => x.Id, id)).FirstOrDefaultAsync();
|
||||
@@ -98,6 +101,11 @@ public sealed class MongoStore : IStore
|
||||
try { await Insert(message); }
|
||||
catch (MongoWriteException ex) when (ex.WriteError.Category == ServerErrorCategory.DuplicateKey) { /* already durable */ }
|
||||
}
|
||||
public async Task<bool> TryInsertPayment(PaymentRequest payment)
|
||||
{
|
||||
try { await Insert(payment);return true; }
|
||||
catch(MongoWriteException ex) when(ex.WriteError.Category==ServerErrorCategory.DuplicateKey){return false;}
|
||||
}
|
||||
public async Task<bool> TryInsertPmsChange(PmsChange change)
|
||||
{
|
||||
try { await Insert(change);return true; }
|
||||
@@ -108,6 +116,14 @@ public sealed class MongoStore : IStore
|
||||
// Explicit Development-only preview store. Production never falls back to this.
|
||||
public sealed class PreviewStore : IStore
|
||||
{
|
||||
public Task<bool> TryInsertPayment(PaymentRequest payment)
|
||||
{
|
||||
lock(gate)
|
||||
{
|
||||
if(rows.Where(x=>x.Key.StartsWith("PaymentRequest:")).Select(x=>Clone<PaymentRequest>(x.Value)).Any(x=>x.HotelId==payment.HotelId&&x.Reference==payment.Reference))return Task.FromResult(false);
|
||||
return Task.FromResult(rows.TryAdd(Key<PaymentRequest>(payment.Id),Json(payment)));
|
||||
}
|
||||
}
|
||||
public Task<bool> TryInsertPmsChange(PmsChange change)
|
||||
{
|
||||
lock(gate)
|
||||
|
||||
Reference in New Issue
Block a user