104 lines
3.0 KiB
C#
104 lines
3.0 KiB
C#
using BackOffice.BFF.ManualPayment.Protobuf;
|
|
using BackOffice.Main.Components;
|
|
using Grpc.Core;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace BackOffice.Main.Pages.Payment;
|
|
|
|
public partial class ManualMembershipPayment
|
|
{
|
|
[Inject] private ManualPaymentContract.ManualPaymentContractClient ManualPaymentClient { get; set; } = default!;
|
|
[Inject] private ISnackbar Snackbar { get; set; } = default!;
|
|
|
|
private long? _userId;
|
|
private long _amount = 0;
|
|
private string _referenceNumber = string.Empty;
|
|
private string? _description;
|
|
|
|
private bool _isProcessing = false;
|
|
private bool _showResult = false;
|
|
private string _resultMessage = string.Empty;
|
|
private long _transactionId = 0;
|
|
private long _orderId = 0;
|
|
private long _newWalletBalance = 0;
|
|
|
|
private async Task ProcessPayment()
|
|
{
|
|
// Validation
|
|
if (!_userId.HasValue || _userId.Value <= 0)
|
|
{
|
|
Snackbar.Add("لطفا کاربر را انتخاب کنید", Severity.Warning);
|
|
return;
|
|
}
|
|
|
|
if (_amount <= 0)
|
|
{
|
|
Snackbar.Add("لطفا مبلغ معتبری وارد کنید", Severity.Warning);
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(_referenceNumber))
|
|
{
|
|
Snackbar.Add("لطفا شماره مرجع را وارد کنید", Severity.Warning);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
_isProcessing = true;
|
|
_showResult = false;
|
|
|
|
var request = new ProcessManualMembershipPaymentRequest
|
|
{
|
|
UserId = _userId.Value,
|
|
Amount = _amount,
|
|
ReferenceNumber = _referenceNumber
|
|
};
|
|
|
|
if (!string.IsNullOrWhiteSpace(_description))
|
|
{
|
|
request.Description = _description;
|
|
}
|
|
|
|
var response = await ManualPaymentClient.ProcessManualMembershipPaymentAsync(request);
|
|
|
|
_resultMessage = response.Message;
|
|
_transactionId = response.TransactionId;
|
|
_orderId = response.OrderId;
|
|
_newWalletBalance = response.NewWalletBalance;
|
|
_showResult = true;
|
|
|
|
Snackbar.Add("پرداخت دستی با موفقیت ثبت شد", Severity.Success);
|
|
|
|
// Reset form
|
|
await Task.Delay(2000);
|
|
ResetForm();
|
|
}
|
|
catch (RpcException ex)
|
|
{
|
|
Snackbar.Add($"خطا در ثبت پرداخت: {ex.Status.Detail}", Severity.Error);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"خطای غیرمنتظره: {ex.Message}", Severity.Error);
|
|
}
|
|
finally
|
|
{
|
|
_isProcessing = false;
|
|
}
|
|
}
|
|
|
|
private void ResetForm()
|
|
{
|
|
_userId = null;
|
|
_amount = 0;
|
|
_referenceNumber = string.Empty;
|
|
_description = null;
|
|
_showResult = false;
|
|
_resultMessage = string.Empty;
|
|
_transactionId = 0;
|
|
_orderId = 0;
|
|
_newWalletBalance = 0;
|
|
}
|
|
}
|