feat: add wallet api for aqaye pardakht

This commit is contained in:
MahanCh
2025-07-10 11:55:18 +03:30
parent 030a622252
commit ba994a5802
7 changed files with 74 additions and 19 deletions

View File

@@ -4,7 +4,9 @@ using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Security.Policy;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace _0_Framework.Application.PaymentGateway;
@@ -12,6 +14,9 @@ namespace _0_Framework.Application.PaymentGateway;
public class AqayePardakhtPaymentGateway:IPaymentGateway
{
private const string Pin = "86EAF2C4D052F7D8759F";
private const string AccountNumber = "AP.1042276242";
private const string EncryptedKey = "130D2@D2923";
private readonly HttpClient _httpClient;
public AqayePardakhtPaymentGateway(IHttpClientFactory httpClientFactory)
@@ -19,7 +24,7 @@ public class AqayePardakhtPaymentGateway:IPaymentGateway
_httpClient = httpClientFactory.CreateClient();
}
public async Task<PaymentGatewayResponse> Create(CreatePaymentGatewayRequest command)
public async Task<PaymentGatewayResponse> Create(CreatePaymentGatewayRequest command,CancellationToken cancellationToken =default)
{
var response = await _httpClient.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/create", new
{
@@ -31,29 +36,29 @@ public class AqayePardakhtPaymentGateway:IPaymentGateway
mobile = command.Mobile,
email = command.Email,
description = command.Description,
});
}, cancellationToken: cancellationToken);
var result = await response.Content.ReadFromJsonAsync<PaymentGatewayResponse>();
var result = await response.Content.ReadFromJsonAsync<PaymentGatewayResponse>(cancellationToken: cancellationToken);
return result;
}
public string GetStartPayUrl(string transactionId) =>
$"https://panel.aqayepardakht.ir/startpay/{transactionId}";
public async Task<PaymentGatewayResponse> Verify(VerifyPaymentGateWayRequest command)
public async Task<PaymentGatewayResponse> Verify(VerifyPaymentGateWayRequest command, CancellationToken cancellationToken = default)
{
var response = await _httpClient.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/verify", new
{
pin = Pin,
amount = command.Amount,
transid = command.TransactionId,
});
}, cancellationToken: cancellationToken);
var result = await response.Content.ReadFromJsonAsync<PaymentGatewayResponse>();
var result = await response.Content.ReadFromJsonAsync<PaymentGatewayResponse>(cancellationToken: cancellationToken);
return result;
}
public async Task<PaymentGatewayResponse> CreateSandBox(CreatePaymentGatewayRequest command)
public async Task<PaymentGatewayResponse> CreateSandBox(CreatePaymentGatewayRequest command, CancellationToken cancellationToken = default)
{
var response = await _httpClient.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/create", new
{
@@ -65,12 +70,24 @@ public class AqayePardakhtPaymentGateway:IPaymentGateway
mobile = command.Mobile,
email = command.Email,
description = command.Email,
});
}, cancellationToken: cancellationToken);
var result = await response.Content.ReadFromJsonAsync<PaymentGatewayResponse>();
var result = await response.Content.ReadFromJsonAsync<PaymentGatewayResponse>(cancellationToken: cancellationToken);
return result;
}
public string GetStartPaySandBoxUrl(string transactionId) =>
$"https://panel.aqayepardakht.ir/startpay/sandbox/{transactionId}";
public async Task<WalletAmountResponse> GetWalletAmount(CancellationToken cancellationToken)
{
var response =await _httpClient.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/getmoney", new
{
account=AccountNumber,
code = EncryptedKey
}, cancellationToken: cancellationToken);
var jsonString = await response.Content.ReadAsStringAsync(cancellationToken);
var result = await response.Content.ReadFromJsonAsync<WalletAmountResponse>(cancellationToken);
return result;
}
}

View File

@@ -1,22 +1,23 @@
using System;
using Microsoft.AspNetCore.Server.HttpSys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.HttpSys;
namespace _0_Framework.Application.PaymentGateway;
public interface IPaymentGateway
{
Task<PaymentGatewayResponse> Create(CreatePaymentGatewayRequest command);
Task<PaymentGatewayResponse> Create(CreatePaymentGatewayRequest command, CancellationToken cancellationToken =default);
string GetStartPayUrl(string transactionId);
Task<PaymentGatewayResponse> Verify(VerifyPaymentGateWayRequest command);
Task<PaymentGatewayResponse> CreateSandBox(CreatePaymentGatewayRequest command);
Task<PaymentGatewayResponse> Verify(VerifyPaymentGateWayRequest command, CancellationToken cancellationToken=default);
Task<PaymentGatewayResponse> CreateSandBox(CreatePaymentGatewayRequest command, CancellationToken cancellationToken=default);
string GetStartPaySandBoxUrl(string transactionId);
Task<WalletAmountResponse> GetWalletAmount(CancellationToken cancellationToken);
}
public class PaymentGatewayResponse
@@ -31,6 +32,16 @@ public class PaymentGatewayResponse
public string TransactionId { get; set; }
}
public class WalletAmountResponse
{
[JsonPropertyName("status")]
public string Status { get; set; }
[JsonPropertyName("money")]
public double Amount { get; set; }
[JsonPropertyName("code")]
public int Code { get; set; }
}
public class CreatePaymentGatewayRequest
{
public double Amount { get; set; }