Merge kub-stage into production
Build and Deploy to Production / build-and-deploy (push) Successful in 11m49s
Build and Deploy to Production / build-and-deploy (push) Successful in 11m49s
- Resolved appsettings.Production.json conflict (new MerchantId, SeedWorkers) - Removed duplicate u21 migration (kept 155925 from production) - All features: Magic Wallet, Discount Wallet, StockMovement fix, FullInformation expansion, Wallet user_name, gateway activation
This commit is contained in:
+12
@@ -88,6 +88,18 @@ public class ActivateClubMembershipCommandHandler : IRequestHandler<ActivateClub
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3.5. بررسی وضعیت کیفپول جادویی — اگر در حالت Magic است، فعالسازی مجاز نیست
|
||||||
|
if (wallet.WalletMode == WalletMode.Magic)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(
|
||||||
|
"User {UserId} cannot activate club while in Magic wallet mode",
|
||||||
|
request.UserId
|
||||||
|
);
|
||||||
|
throw new BadRequestException(
|
||||||
|
"ابتدا باید چرخه کیفپول جادویی تکمیل شود"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 4. پیدا کردن UserOrder با PackageId
|
// 4. پیدا کردن UserOrder با PackageId
|
||||||
var packageOrder = await _context.UserOrders
|
var packageOrder = await _context.UserOrders
|
||||||
.Include(o => o.Transaction)
|
.Include(o => o.Transaction)
|
||||||
|
|||||||
+11
@@ -72,6 +72,17 @@ public class CheckAndProcessDayaLoansCommandHandler : IRequestHandler<CheckAndPr
|
|||||||
|
|
||||||
result.UserId = user.Id;
|
result.UserId = user.Id;
|
||||||
|
|
||||||
|
// 2.5. بررسی محدودیت دایا — پس از اولین دور، فقط IPG مجاز است
|
||||||
|
var hasPreviousCycle = await _context.ClubMembershipCycles
|
||||||
|
.AnyAsync(c => c.UserId == user.Id, cancellationToken);
|
||||||
|
|
||||||
|
if (hasPreviousCycle)
|
||||||
|
{
|
||||||
|
result.Message = "کاربرانی که دور اول را تکمیل کردهاند فقط از طریق درگاه بانکی میتوانند پکیج خریداری کنند";
|
||||||
|
results.Add(result);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// 3. ذخیره/بهروزرسانی DayaLoanContract
|
// 3. ذخیره/بهروزرسانی DayaLoanContract
|
||||||
var contract = await _context.DayaLoanContracts
|
var contract = await _context.DayaLoanContracts
|
||||||
.FirstOrDefaultAsync(d => d.NationalCode == dayaResult.NationalCode, cancellationToken);
|
.FirstOrDefaultAsync(d => d.NationalCode == dayaResult.NationalCode, cancellationToken);
|
||||||
|
|||||||
+5
-1
@@ -1,7 +1,7 @@
|
|||||||
namespace CMSMicroservice.Application.InventoryItemCQ.Commands.ReduceInventory;
|
namespace CMSMicroservice.Application.InventoryItemCQ.Commands.ReduceInventory;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Command برای کم کردن موجودی (فروش)
|
/// Command برای کم کردن موجودی (فروش، خسارت، مفقودی و ...)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public record ReduceInventoryCommand : IRequest<ReduceInventoryResponseDto>
|
public record ReduceInventoryCommand : IRequest<ReduceInventoryResponseDto>
|
||||||
{
|
{
|
||||||
@@ -19,4 +19,8 @@ public record ReduceInventoryCommand : IRequest<ReduceInventoryResponseDto>
|
|||||||
public long? PerformedByUserId { get; init; }
|
public long? PerformedByUserId { get; init; }
|
||||||
/// <summary>آیا از موجودی رزرو شده کم شود؟</summary>
|
/// <summary>آیا از موجودی رزرو شده کم شود؟</summary>
|
||||||
public bool FromReserved { get; init; } = true;
|
public bool FromReserved { get; init; } = true;
|
||||||
|
/// <summary>نوع حرکت انبار (پیشفرض: فروش)</summary>
|
||||||
|
public Domain.Enums.StockMovementType MovementType { get; init; } = Domain.Enums.StockMovementType.Sale;
|
||||||
|
/// <summary>توضیحات</summary>
|
||||||
|
public string? Note { get; init; }
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -53,11 +53,11 @@ public class ReduceInventoryCommandHandler : IRequestHandler<ReduceInventoryComm
|
|||||||
var stockMovement = new StockMovement
|
var stockMovement = new StockMovement
|
||||||
{
|
{
|
||||||
InventoryItemId = item.Id,
|
InventoryItemId = item.Id,
|
||||||
MovementType = StockMovementType.Sale,
|
MovementType = request.MovementType,
|
||||||
Quantity = request.Quantity,
|
Quantity = -request.Quantity, // منفی — CHECK constraint: QuantityAfter = QuantityBefore + Quantity
|
||||||
QuantityBefore = previousQuantity,
|
QuantityBefore = previousQuantity,
|
||||||
QuantityAfter = item.Quantity,
|
QuantityAfter = item.Quantity,
|
||||||
Note = "Sale confirmed",
|
Note = request.Note ?? request.MovementType.ToString(),
|
||||||
ReferenceNumber = request.ReferenceNumber ?? $"SALE-{DateTime.UtcNow:yyyyMMddHHmmss}",
|
ReferenceNumber = request.ReferenceNumber ?? $"SALE-{DateTime.UtcNow:yyyyMMddHHmmss}",
|
||||||
OrderId = request.OrderId,
|
OrderId = request.OrderId,
|
||||||
DiscountOrderId = request.DiscountOrderId,
|
DiscountOrderId = request.DiscountOrderId,
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
using CMSMicroservice.Application.Common.Interfaces;
|
||||||
|
using CMSMicroservice.Domain.Entities.Club;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace CMSMicroservice.Infrastructure.BackgroundServices;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// سرویس یکباره برای Seed کردن ClubMembershipCycle برای عضویتهای فعال موجود.
|
||||||
|
/// عضویتهایی که قبل از اضافه شدن سیستم Cycle ایجاد شدهاند رکورد ندارند.
|
||||||
|
/// این Worker در استارتاپ اجرا شده، برای آنها CycleNumber=1 میسازد و سپس متوقف میشود.
|
||||||
|
///
|
||||||
|
/// فعال/غیرفعال از appsettings:
|
||||||
|
/// "SeedWorkers": { "MagicWalletCycleSeed": { "Enabled": true } }
|
||||||
|
///
|
||||||
|
/// بعد از اجرای موفق، Enabled را false کنید.
|
||||||
|
/// </summary>
|
||||||
|
public class MagicWalletCycleSeedService : BackgroundService
|
||||||
|
{
|
||||||
|
private readonly IServiceScopeFactory _scopeFactory;
|
||||||
|
private readonly ILogger<MagicWalletCycleSeedService> _logger;
|
||||||
|
|
||||||
|
public MagicWalletCycleSeedService(
|
||||||
|
IServiceScopeFactory scopeFactory,
|
||||||
|
ILogger<MagicWalletCycleSeedService> logger)
|
||||||
|
{
|
||||||
|
_scopeFactory = scopeFactory;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
// صبر کوتاه برای اطمینان از آماده شدن دیتابیس
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(15), stoppingToken);
|
||||||
|
|
||||||
|
_logger.LogInformation("MagicWalletCycleSeedService started — scanning active memberships without cycles...");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var scope = _scopeFactory.CreateScope();
|
||||||
|
var context = scope.ServiceProvider.GetRequiredService<IApplicationDbContext>();
|
||||||
|
|
||||||
|
var seededCount = await SeedMissingCycles(context, stoppingToken);
|
||||||
|
|
||||||
|
_logger.LogInformation(
|
||||||
|
"MagicWalletCycleSeedService completed — seeded {Count} ClubMembershipCycle records",
|
||||||
|
seededCount);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "MagicWalletCycleSeedService encountered an error");
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation(
|
||||||
|
"MagicWalletCycleSeedService finished — shutting down (one-time execution). " +
|
||||||
|
"Set SeedWorkers:MagicWalletCycleSeed:Enabled to false in appsettings.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<int> SeedMissingCycles(IApplicationDbContext context, CancellationToken ct)
|
||||||
|
{
|
||||||
|
// پیدا کردن عضویتهای فعالی که هنوز Cycle ندارند
|
||||||
|
var membershipIdsWithCycle = await context.ClubMembershipCycles
|
||||||
|
.Where(c => !c.IsDeleted)
|
||||||
|
.Select(c => c.ClubMembershipId)
|
||||||
|
.Distinct()
|
||||||
|
.ToListAsync(ct);
|
||||||
|
|
||||||
|
var membershipsWithoutCycle = await context.ClubMemberships
|
||||||
|
.Where(cm => !cm.IsDeleted && cm.IsActive && !membershipIdsWithCycle.Contains(cm.Id))
|
||||||
|
.Select(cm => new
|
||||||
|
{
|
||||||
|
cm.Id,
|
||||||
|
cm.UserId,
|
||||||
|
cm.ActivatedAt
|
||||||
|
})
|
||||||
|
.ToListAsync(ct);
|
||||||
|
|
||||||
|
if (membershipsWithoutCycle.Count == 0)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("No active memberships without cycles found — nothing to seed");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Found {Count} active memberships without ClubMembershipCycle — seeding...",
|
||||||
|
membershipsWithoutCycle.Count);
|
||||||
|
|
||||||
|
var seeded = 0;
|
||||||
|
foreach (var cm in membershipsWithoutCycle)
|
||||||
|
{
|
||||||
|
if (ct.IsCancellationRequested) break;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var cycle = new ClubMembershipCycle
|
||||||
|
{
|
||||||
|
UserId = cm.UserId,
|
||||||
|
ClubMembershipId = cm.Id,
|
||||||
|
CycleNumber = 1,
|
||||||
|
PackagePurchasedAt = cm.ActivatedAt ?? DateTime.UtcNow,
|
||||||
|
IsCurrentCycle = true,
|
||||||
|
PurchaseMethod = 0,
|
||||||
|
PackageAmount = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
context.ClubMembershipCycles.Add(cycle);
|
||||||
|
seeded++;
|
||||||
|
|
||||||
|
_logger.LogDebug(
|
||||||
|
"Seeded ClubMembershipCycle for UserId={UserId}, MembershipId={MembershipId}, ActivatedAt={ActivatedAt}",
|
||||||
|
cm.UserId, cm.Id, cm.ActivatedAt);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex,
|
||||||
|
"Failed to seed cycle for MembershipId={MembershipId}, UserId={UserId}",
|
||||||
|
cm.Id, cm.UserId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await context.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
return seeded;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -126,6 +126,10 @@ public static class ConfigureServices
|
|||||||
// One-time: Initialize inventory records for existing products
|
// One-time: Initialize inventory records for existing products
|
||||||
services.AddHostedService<InventoryInitializerService>();
|
services.AddHostedService<InventoryInitializerService>();
|
||||||
|
|
||||||
|
// One-time: Seed ClubMembershipCycle for existing active memberships
|
||||||
|
if (configuration.GetValue<bool>("SeedWorkers:MagicWalletCycleSeed:Enabled"))
|
||||||
|
services.AddHostedService<MagicWalletCycleSeedService>();
|
||||||
|
|
||||||
if (configuration.GetValue<bool>("UseInMemoryDatabase"))
|
if (configuration.GetValue<bool>("UseInMemoryDatabase"))
|
||||||
{
|
{
|
||||||
services.AddDbContext<ApplicationDbContext>(options =>
|
services.AddDbContext<ApplicationDbContext>(options =>
|
||||||
|
|||||||
+1
-2
@@ -26,8 +26,7 @@ public class DiscountProductConfiguration : IEntityTypeConfiguration<DiscountPro
|
|||||||
.HasMaxLength(500);
|
.HasMaxLength(500);
|
||||||
|
|
||||||
builder.Property(entity => entity.FullInformation)
|
builder.Property(entity => entity.FullInformation)
|
||||||
.IsRequired()
|
.IsRequired();
|
||||||
.HasMaxLength(2000);
|
|
||||||
|
|
||||||
builder.Property(entity => entity.Price)
|
builder.Property(entity => entity.Price)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|||||||
+4780
File diff suppressed because it is too large
Load Diff
+38
@@ -0,0 +1,38 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class ExpandDiscountProductFullInformation : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "FullInformation",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "DiscountProducts",
|
||||||
|
type: "nvarchar(max)",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(2000)",
|
||||||
|
oldMaxLength: 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "FullInformation",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "DiscountProducts",
|
||||||
|
type: "nvarchar(2000)",
|
||||||
|
maxLength: 2000,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(max)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-2
@@ -1404,8 +1404,7 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
|||||||
|
|
||||||
b.Property<string>("FullInformation")
|
b.Property<string>("FullInformation")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasMaxLength(2000)
|
.HasColumnType("nvarchar(max)");
|
||||||
.HasColumnType("nvarchar(2000)");
|
|
||||||
|
|
||||||
b.Property<string>("ImagePath")
|
b.Property<string>("ImagePath")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Version>0.0.181</Version>
|
<Version>0.0.183</Version>
|
||||||
<DebugType>None</DebugType>
|
<DebugType>None</DebugType>
|
||||||
<DebugSymbols>False</DebugSymbols>
|
<DebugSymbols>False</DebugSymbols>
|
||||||
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
||||||
|
|||||||
@@ -88,6 +88,15 @@ service UserWalletContract
|
|||||||
get: "/Customer/GetMagicWalletStatus"
|
get: "/Customer/GetMagicWalletStatus"
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ============= Discount Wallet Methods =============
|
||||||
|
|
||||||
|
rpc InitiateDiscountCharge(InitiateDiscountChargeRequest) returns (InitiateDiscountChargeResponse){
|
||||||
|
option (google.api.http) = {
|
||||||
|
post: "/Customer/InitiateDiscountCharge"
|
||||||
|
body: "*"
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
message CreateNewUserWalletRequest
|
message CreateNewUserWalletRequest
|
||||||
{
|
{
|
||||||
@@ -145,6 +154,7 @@ message GetAllUserWalletByFilterResponseModel
|
|||||||
int64 user_id = 2;
|
int64 user_id = 2;
|
||||||
int64 balance = 3;
|
int64 balance = 3;
|
||||||
int64 network_balance = 4;
|
int64 network_balance = 4;
|
||||||
|
string user_name = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============= Customer-specific Messages =============
|
// ============= Customer-specific Messages =============
|
||||||
@@ -240,4 +250,19 @@ message GetMagicWalletStatusResponse
|
|||||||
int64 magic_remaining_deposit = 5;
|
int64 magic_remaining_deposit = 5;
|
||||||
int64 balance = 6;
|
int64 balance = 6;
|
||||||
google.protobuf.Timestamp magic_activated_at = 7;
|
google.protobuf.Timestamp magic_activated_at = 7;
|
||||||
|
int32 purchase_cycle_count = 8; // تعداد دورهای خرید پکیج (0 = هنوز هیچ دوری تکمیل نشده)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============= Discount Wallet Messages =============
|
||||||
|
|
||||||
|
message InitiateDiscountChargeRequest
|
||||||
|
{
|
||||||
|
int64 amount = 1; // مبلغ واریزی (ریال)
|
||||||
|
}
|
||||||
|
|
||||||
|
message InitiateDiscountChargeResponse
|
||||||
|
{
|
||||||
|
bool is_success = 1;
|
||||||
|
string gateway_url = 2;
|
||||||
|
string error_message = 3;
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using CMSMicroservice.Application.Common.Interfaces;
|
using CMSMicroservice.Application.Common.Interfaces;
|
||||||
using CMSMicroservice.Application.DiscountShopCQ.Commands.CompleteOrderPayment;
|
using CMSMicroservice.Application.DiscountShopCQ.Commands.CompleteOrderPayment;
|
||||||
|
using CMSMicroservice.Application.WalletCQ.Commands.VerifyDiscountWalletCharge;
|
||||||
using CMSMicroservice.Application.WalletCQ.Commands.VerifyMagicWalletCharge;
|
using CMSMicroservice.Application.WalletCQ.Commands.VerifyMagicWalletCharge;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@@ -186,4 +187,63 @@ public class PaymentCallbackController : ControllerBase
|
|||||||
return Redirect($"{frontOfficeBaseUrl}/magic-wallet?payment=failed");
|
return Redirect($"{frontOfficeBaseUrl}/magic-wallet?payment=failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Callback برای شارژ کیفپول تخفیفی — زرینپال بعد از پرداخت کاربر را اینجا برمیگرداند
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("/api/wallet/verify-discount-charge")]
|
||||||
|
public async Task<IActionResult> DiscountChargeCallback(
|
||||||
|
[FromQuery(Name = "Authority")] string? authority,
|
||||||
|
[FromQuery(Name = "Status")] string? status,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var frontOfficeBaseUrl = _configuration["FrontOfficeBaseUrl"] ?? "https://localhost:5268";
|
||||||
|
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Discount charge callback received: Authority={Authority}, Status={Status}",
|
||||||
|
authority, status);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(authority))
|
||||||
|
{
|
||||||
|
_logger.LogError("Discount charge callback: Authority is missing");
|
||||||
|
return Redirect($"{frontOfficeBaseUrl}/profile/charge-discount-wallet?payment=error&reason=no-authority");
|
||||||
|
}
|
||||||
|
|
||||||
|
// پیدا کردن PaymentTransaction برای استخراج UserId و Amount
|
||||||
|
var paymentTx = await _context.PaymentTransactions
|
||||||
|
.FirstOrDefaultAsync(pt => pt.Authority == authority, cancellationToken);
|
||||||
|
|
||||||
|
if (paymentTx == null || !paymentTx.UserId.HasValue)
|
||||||
|
{
|
||||||
|
_logger.LogError("Discount charge callback: PaymentTransaction not found for Authority={Authority}", authority);
|
||||||
|
return Redirect($"{frontOfficeBaseUrl}/profile/charge-discount-wallet?payment=error&reason=tx-not-found");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.Equals(status, "OK", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Discount charge cancelled by user. Authority={Authority}", authority);
|
||||||
|
return Redirect($"{frontOfficeBaseUrl}/profile/charge-discount-wallet?payment=cancelled");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await _sender.Send(new VerifyDiscountWalletChargeCommand
|
||||||
|
{
|
||||||
|
UserId = paymentTx.UserId.Value,
|
||||||
|
Amount = paymentTx.Amount,
|
||||||
|
Authority = authority
|
||||||
|
}, cancellationToken);
|
||||||
|
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Discount charge completed successfully. Authority={Authority}, UserId={UserId}",
|
||||||
|
authority, paymentTx.UserId.Value);
|
||||||
|
|
||||||
|
return Redirect($"{frontOfficeBaseUrl}/profile/charge-discount-wallet?payment=success");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Discount charge callback error. Authority={Authority}", authority);
|
||||||
|
return Redirect($"{frontOfficeBaseUrl}/profile/charge-discount-wallet?payment=failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,7 +181,9 @@ public class InventoryService : InventoryContract.InventoryContractBase
|
|||||||
Id = inventoryItem.Id,
|
Id = inventoryItem.Id,
|
||||||
Quantity = Math.Abs(difference),
|
Quantity = Math.Abs(difference),
|
||||||
FromReserved = false,
|
FromReserved = false,
|
||||||
ReferenceNumber = request.ReferenceNumber
|
ReferenceNumber = request.ReferenceNumber,
|
||||||
|
MovementType = Domain.Enums.StockMovementType.AdjustmentMinus,
|
||||||
|
Note = "Stock adjustment (decrease)"
|
||||||
},
|
},
|
||||||
context.CancellationToken);
|
context.CancellationToken);
|
||||||
|
|
||||||
@@ -332,7 +334,9 @@ public class InventoryService : InventoryContract.InventoryContractBase
|
|||||||
Id = inventoryItem.Id,
|
Id = inventoryItem.Id,
|
||||||
Quantity = request.Quantity,
|
Quantity = request.Quantity,
|
||||||
FromReserved = false,
|
FromReserved = false,
|
||||||
ReferenceNumber = request.ReferenceNumber ?? $"LOSS-{DateTime.UtcNow:yyyyMMddHHmmss}"
|
ReferenceNumber = request.ReferenceNumber ?? $"LOSS-{DateTime.UtcNow:yyyyMMddHHmmss}",
|
||||||
|
MovementType = (Domain.Enums.StockMovementType)request.LossType,
|
||||||
|
Note = string.IsNullOrWhiteSpace(request.Reason) ? null : request.Reason
|
||||||
},
|
},
|
||||||
context.CancellationToken);
|
context.CancellationToken);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using CMSMicroservice.Application.UserWalletCQ.Commands.CreateNewUserWallet;
|
|||||||
using CMSMicroservice.Application.UserWalletCQ.Commands.UpdateUserWallet;
|
using CMSMicroservice.Application.UserWalletCQ.Commands.UpdateUserWallet;
|
||||||
using CMSMicroservice.Application.UserWalletCQ.Commands.DeleteUserWallet;
|
using CMSMicroservice.Application.UserWalletCQ.Commands.DeleteUserWallet;
|
||||||
using CMSMicroservice.Application.WalletCQ.Commands.ChargeMagicWallet;
|
using CMSMicroservice.Application.WalletCQ.Commands.ChargeMagicWallet;
|
||||||
|
using CMSMicroservice.Application.WalletCQ.Commands.ChargeDiscountWallet;
|
||||||
using CMSMicroservice.Application.UserWalletCQ.Queries.GetUserWallet;
|
using CMSMicroservice.Application.UserWalletCQ.Queries.GetUserWallet;
|
||||||
using CMSMicroservice.Application.UserWalletCQ.Queries.GetAllUserWalletByFilter;
|
using CMSMicroservice.Application.UserWalletCQ.Queries.GetAllUserWalletByFilter;
|
||||||
using CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWalletChangeLog;
|
using CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWalletChangeLog;
|
||||||
@@ -54,7 +55,28 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
|
|||||||
}
|
}
|
||||||
public override async Task<GetAllUserWalletByFilterResponse> GetAllUserWalletByFilter(GetAllUserWalletByFilterRequest request, ServerCallContext context)
|
public override async Task<GetAllUserWalletByFilterResponse> GetAllUserWalletByFilter(GetAllUserWalletByFilterRequest request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
return await _dispatchRequestToCQRS.Handle<GetAllUserWalletByFilterRequest, GetAllUserWalletByFilterQuery, GetAllUserWalletByFilterResponse>(request, context);
|
var response = await _dispatchRequestToCQRS.Handle<GetAllUserWalletByFilterRequest, GetAllUserWalletByFilterQuery, GetAllUserWalletByFilterResponse>(request, context);
|
||||||
|
|
||||||
|
// Enrich response with user names
|
||||||
|
if (response?.Models != null && response.Models.Any())
|
||||||
|
{
|
||||||
|
var userIds = response.Models.Select(m => m.UserId).Distinct().ToList();
|
||||||
|
var users = await _context.Users
|
||||||
|
.AsNoTracking()
|
||||||
|
.Where(u => userIds.Contains(u.Id))
|
||||||
|
.Select(u => new { u.Id, u.FirstName, u.LastName })
|
||||||
|
.ToDictionaryAsync(u => u.Id, context.CancellationToken);
|
||||||
|
|
||||||
|
foreach (var model in response.Models)
|
||||||
|
{
|
||||||
|
if (users.TryGetValue(model.UserId, out var user))
|
||||||
|
{
|
||||||
|
model.UserName = $"{user.FirstName} {user.LastName}".Trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============= Customer-specific Methods =============
|
// ============= Customer-specific Methods =============
|
||||||
@@ -170,6 +192,27 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============= Discount Wallet Methods =============
|
||||||
|
|
||||||
|
public override async Task<InitiateDiscountChargeResponse> InitiateDiscountCharge(
|
||||||
|
InitiateDiscountChargeRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
var userId = GetCurrentUserId();
|
||||||
|
|
||||||
|
var result = await _sender.Send(new ChargeDiscountWalletCommand
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
Amount = request.Amount
|
||||||
|
}, context.CancellationToken);
|
||||||
|
|
||||||
|
return new InitiateDiscountChargeResponse
|
||||||
|
{
|
||||||
|
IsSuccess = result.IsSuccess,
|
||||||
|
GatewayUrl = result.GatewayUrl ?? "",
|
||||||
|
ErrorMessage = result.ErrorMessage ?? ""
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public override async Task<GetMagicWalletStatusResponse> GetMagicWalletStatus(
|
public override async Task<GetMagicWalletStatusResponse> GetMagicWalletStatus(
|
||||||
Google.Protobuf.WellKnownTypes.Empty request, ServerCallContext context)
|
Google.Protobuf.WellKnownTypes.Empty request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
@@ -181,6 +224,9 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
|
|||||||
if (wallet == null)
|
if (wallet == null)
|
||||||
throw new RpcException(new Status(StatusCode.NotFound, "کیف پول یافت نشد"));
|
throw new RpcException(new Status(StatusCode.NotFound, "کیف پول یافت نشد"));
|
||||||
|
|
||||||
|
var cycleCount = await _context.ClubMembershipCycles
|
||||||
|
.CountAsync(c => c.UserId == userId, context.CancellationToken);
|
||||||
|
|
||||||
var response = new GetMagicWalletStatusResponse
|
var response = new GetMagicWalletStatusResponse
|
||||||
{
|
{
|
||||||
WalletMode = (int)wallet.WalletMode,
|
WalletMode = (int)wallet.WalletMode,
|
||||||
@@ -188,7 +234,8 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
|
|||||||
MagicTotalCredited = wallet.MagicTotalCredited,
|
MagicTotalCredited = wallet.MagicTotalCredited,
|
||||||
MagicMaxDeposit = SystemConstants.MagicWalletMaxDeposit,
|
MagicMaxDeposit = SystemConstants.MagicWalletMaxDeposit,
|
||||||
MagicRemainingDeposit = Math.Max(0, SystemConstants.MagicWalletMaxDeposit - wallet.MagicTotalDeposited),
|
MagicRemainingDeposit = Math.Max(0, SystemConstants.MagicWalletMaxDeposit - wallet.MagicTotalDeposited),
|
||||||
Balance = wallet.Balance
|
Balance = wallet.Balance,
|
||||||
|
PurchaseCycleCount = cycleCount
|
||||||
};
|
};
|
||||||
|
|
||||||
if (wallet.MagicActivatedAt.HasValue)
|
if (wallet.MagicActivatedAt.HasValue)
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
{
|
{
|
||||||
"PaymentProvider": "zarinpal",
|
"PaymentProvider": "zarinpal",
|
||||||
"ZarinPal": {
|
"ZarinPal": {
|
||||||
"MerchantId": "6b098fc8-f490-47a1-aac3-1de1a1b84404",
|
"MerchantId": "4225d555-5fa9-4df0-9b61-1ce152cbbba8",
|
||||||
"UseSandbox": false
|
"UseSandbox": false
|
||||||
},
|
},
|
||||||
"CmsBaseUrl": "https://cms.kbs1.ir",
|
"CmsBaseUrl": "https://cms.kbs1.ir",
|
||||||
"FrontOfficeBaseUrl": "https://kbs1.ir",
|
"FrontOfficeBaseUrl": "https://kbs1.ir",
|
||||||
"UseRealPaymentGateway": false,
|
|
||||||
"JwtSecurityKey": "TvlZVx5TJaHs8e9HgUdGzhGP2CIidoI444nAj+8+g7c=",
|
"JwtSecurityKey": "TvlZVx5TJaHs8e9HgUdGzhGP2CIidoI444nAj+8+g7c=",
|
||||||
"JwtIssuer": "https://localhost",
|
"JwtIssuer": "https://localhost",
|
||||||
"JwtAudience": "https://localhost",
|
"JwtAudience": "https://localhost",
|
||||||
@@ -68,6 +67,11 @@
|
|||||||
"CronExpression": "5 0 * * 0"
|
"CronExpression": "5 0 * * 0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"SeedWorkers": {
|
||||||
|
"MagicWalletCycleSeed": {
|
||||||
|
"Enabled": true
|
||||||
|
}
|
||||||
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"Kestrel": {
|
"Kestrel": {
|
||||||
"EndpointDefaults": {
|
"EndpointDefaults": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"PaymentProvider": "zarinpal",
|
"PaymentProvider": "zarinpal",
|
||||||
"ZarinPal": {
|
"ZarinPal": {
|
||||||
"MerchantId": "6b098fc8-f490-47a1-aac3-1de1a1b84404",
|
"MerchantId": "4225d555-5fa9-4df0-9b61-1ce152cbbba8",
|
||||||
"UseSandbox": true
|
"UseSandbox": true
|
||||||
},
|
},
|
||||||
"FMS": {
|
"FMS": {
|
||||||
@@ -68,6 +68,11 @@
|
|||||||
"CronExpression": "5 0 * * 0"
|
"CronExpression": "5 0 * * 0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"SeedWorkers": {
|
||||||
|
"MagicWalletCycleSeed": {
|
||||||
|
"Enabled": true
|
||||||
|
}
|
||||||
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"Kestrel": {
|
"Kestrel": {
|
||||||
"EndpointDefaults": {
|
"EndpointDefaults": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"PaymentProvider": "zarinpal",
|
"PaymentProvider": "zarinpal",
|
||||||
"ZarinPal": {
|
"ZarinPal": {
|
||||||
"MerchantId": "6b098fc8-f490-47a1-aac3-1de1a1b84404",
|
"MerchantId": "4225d555-5fa9-4df0-9b61-1ce152cbbba8",
|
||||||
"UseSandbox": true
|
"UseSandbox": true
|
||||||
},
|
},
|
||||||
"CmsBaseUrl": "https://cms.kbs1.ir",
|
"CmsBaseUrl": "https://cms.kbs1.ir",
|
||||||
@@ -75,6 +75,11 @@
|
|||||||
"CronExpression": "5 0 * * 0"
|
"CronExpression": "5 0 * * 0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"SeedWorkers": {
|
||||||
|
"MagicWalletCycleSeed": {
|
||||||
|
"Enabled": true
|
||||||
|
}
|
||||||
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"Authentication": {
|
"Authentication": {
|
||||||
"Authority": "https://ids.domain.com/",
|
"Authority": "https://ids.domain.com/",
|
||||||
|
|||||||
Reference in New Issue
Block a user