a39a36e66d
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m6s
- New PaymentTransaction entity (Domain/Entities/Payment/) with all gateway fields: GatewayProvider, MerchantId, Authority, CardPan, CardHash, RefId, VerificationStatusCode, etc. - New PaymentTransactionConfiguration with indexes on Authority, GatewayProvider, UserId, TransactionId, RefId - Added DbSet<PaymentTransaction> to IApplicationDbContext and ApplicationDbContext - Extended PaymentVerificationResult DTO with CardPan, CardHash, VerificationCode - Updated ZarinPalPaymentService.VerifyPayment to return CardPan/CardHash/VerificationCode - Updated all 5 payment consumers to create/update PaymentTransaction: * PlaceOrderCommandHandler — creates PaymentTransaction after InitiatePayment * PaymentCallbackController — updates PaymentTransaction after VerifyPayment * ChargeDiscountWalletCommandHandler — creates PaymentTransaction + fixed callback URL * VerifyDiscountWalletChargeCommandHandler — updates PaymentTransaction after verify * TransactionsService.CustomerPaymentRequest/Verification — create/update PaymentTransaction * PackageService.CustomerPurchasePackage/Verify — create/update PaymentTransaction - Transaction table untouched — PaymentTransaction is a separate table - Pattern inspired by PYMS: create row before gateway → update after verify - EF migration: AddPaymentTransactionTable
228 lines
6.6 KiB
C#
228 lines
6.6 KiB
C#
namespace CMSMicroservice.Application.Common.Interfaces;
|
|
|
|
/// <summary>
|
|
/// Interface برای یکپارچهسازی با درگاههای پرداخت
|
|
/// </summary>
|
|
public interface IPaymentGatewayService
|
|
{
|
|
/// <summary>
|
|
/// شروع تراکنش پرداخت (ارسال به درگاه)
|
|
/// </summary>
|
|
/// <param name="request">اطلاعات تراکنش</param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns>URL درگاه برای هدایت کاربر + RefId تراکنش</returns>
|
|
Task<PaymentInitiateResult> InitiatePaymentAsync(
|
|
PaymentRequest request,
|
|
CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// تأیید پرداخت (بعد از بازگشت از درگاه)
|
|
/// </summary>
|
|
/// <param name="refId">شماره مرجع تراکنش</param>
|
|
/// <param name="verificationToken">توکن تأیید از درگاه</param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns>وضعیت نهایی تراکنش</returns>
|
|
Task<PaymentVerificationResult> VerifyPaymentAsync(
|
|
string refId,
|
|
string verificationToken,
|
|
CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// تأیید پرداخت با مبلغ — برای درگاههایی مثل زرینپال که مبلغ را در Verify نیاز دارند
|
|
/// </summary>
|
|
/// <param name="refId">شماره مرجع تراکنش (Authority در زرینپال)</param>
|
|
/// <param name="verificationToken">توکن تأیید از درگاه (Status در زرینپال)</param>
|
|
/// <param name="amountInToman">مبلغ تراکنش به تومان</param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns>وضعیت نهایی تراکنش</returns>
|
|
Task<PaymentVerificationResult> VerifyPaymentAsync(
|
|
string refId,
|
|
string verificationToken,
|
|
decimal amountInToman,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
// پیشفرض: درگاههایی که Amount نمیخواهند، از overload بدون amount استفاده کنند
|
|
return VerifyPaymentAsync(refId, verificationToken, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// واریز مبلغ به حساب کاربر (برداشت از کیف پول)
|
|
/// </summary>
|
|
/// <param name="request">اطلاعات واریز</param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns>وضعیت واریز</returns>
|
|
Task<PayoutResult> ProcessPayoutAsync(
|
|
PayoutRequest request,
|
|
CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
/// <summary>
|
|
/// درخواست شروع تراکنش پرداخت
|
|
/// </summary>
|
|
public class PaymentRequest
|
|
{
|
|
/// <summary>
|
|
/// مبلغ (تومان)
|
|
/// </summary>
|
|
public decimal Amount { get; set; }
|
|
|
|
/// <summary>
|
|
/// شناسه کاربر
|
|
/// </summary>
|
|
public long UserId { get; set; }
|
|
|
|
/// <summary>
|
|
/// شماره موبایل
|
|
/// </summary>
|
|
public string Mobile { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// شرح تراکنش
|
|
/// </summary>
|
|
public string Description { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// URL بازگشت بعد از پرداخت
|
|
/// </summary>
|
|
public string CallbackUrl { get; set; } = string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// نتیجه شروع تراکنش
|
|
/// </summary>
|
|
public class PaymentInitiateResult
|
|
{
|
|
/// <summary>
|
|
/// موفق بودن درخواست
|
|
/// </summary>
|
|
public bool IsSuccess { get; set; }
|
|
|
|
/// <summary>
|
|
/// شماره مرجع تراکنش (RefId)
|
|
/// </summary>
|
|
public string? RefId { get; set; }
|
|
|
|
/// <summary>
|
|
/// URL درگاه برای هدایت کاربر
|
|
/// </summary>
|
|
public string? GatewayUrl { get; set; }
|
|
|
|
/// <summary>
|
|
/// پیام خطا (در صورت ناموفق بودن)
|
|
/// </summary>
|
|
public string? ErrorMessage { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// نتیجه تأیید تراکنش
|
|
/// </summary>
|
|
public class PaymentVerificationResult
|
|
{
|
|
/// <summary>
|
|
/// موفق بودن تراکنش
|
|
/// </summary>
|
|
public bool IsSuccess { get; set; }
|
|
|
|
/// <summary>
|
|
/// شماره مرجع تراکنش
|
|
/// </summary>
|
|
public string RefId { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// کد پیگیری بانک
|
|
/// </summary>
|
|
public string? TrackingCode { get; set; }
|
|
|
|
/// <summary>
|
|
/// مبلغ تراکنش
|
|
/// </summary>
|
|
public decimal Amount { get; set; }
|
|
|
|
/// <summary>
|
|
/// پیام
|
|
/// </summary>
|
|
public string? Message { get; set; }
|
|
|
|
/// <summary>
|
|
/// شماره کارت ماسکشده (مثلاً 6037-****-****-1234)
|
|
/// </summary>
|
|
public string? CardPan { get; set; }
|
|
|
|
/// <summary>
|
|
/// هش کارت بانکی
|
|
/// </summary>
|
|
public string? CardHash { get; set; }
|
|
|
|
/// <summary>
|
|
/// کد وضعیت verify از درگاه (100=موفق، 101=تکراری)
|
|
/// </summary>
|
|
public int? VerificationCode { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// درخواست واریز
|
|
/// </summary>
|
|
public class PayoutRequest
|
|
{
|
|
/// <summary>
|
|
/// مبلغ (تومان)
|
|
/// </summary>
|
|
public decimal Amount { get; set; }
|
|
|
|
/// <summary>
|
|
/// شناسه کاربر
|
|
/// </summary>
|
|
public long UserId { get; set; }
|
|
|
|
/// <summary>
|
|
/// شماره شبا
|
|
/// </summary>
|
|
public string Iban { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// نام صاحب حساب
|
|
/// </summary>
|
|
public string AccountHolderName { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// شرح واریز
|
|
/// </summary>
|
|
public string Description { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// شماره مرجع داخلی
|
|
/// </summary>
|
|
public string InternalRefId { get; set; } = string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// نتیجه واریز
|
|
/// </summary>
|
|
public class PayoutResult
|
|
{
|
|
/// <summary>
|
|
/// موفق بودن واریز
|
|
/// </summary>
|
|
public bool IsSuccess { get; set; }
|
|
|
|
/// <summary>
|
|
/// شماره مرجع تراکنش بانکی
|
|
/// </summary>
|
|
public string? BankRefId { get; set; }
|
|
|
|
/// <summary>
|
|
/// کد پیگیری
|
|
/// </summary>
|
|
public string? TrackingCode { get; set; }
|
|
|
|
/// <summary>
|
|
/// پیام
|
|
/// </summary>
|
|
public string? Message { get; set; }
|
|
|
|
/// <summary>
|
|
/// زمان پردازش
|
|
/// </summary>
|
|
public DateTime ProcessedAt { get; set; }
|
|
}
|