100 lines
3.9 KiB
C#
100 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
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;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace _0_Framework.Application.PaymentGateway;
|
|
|
|
public class AqayePardakhtPaymentGateway:IPaymentGateway
|
|
{
|
|
private static string _pin = "86EAF2C4D052F7D8759F";
|
|
private const string AccountNumber = "AP.1042276242";
|
|
private const string EncryptedKey = "130D2@D2923";
|
|
|
|
private readonly HttpClient _httpClient;
|
|
|
|
public AqayePardakhtPaymentGateway(IHttpClientFactory httpClientFactory,IOptions<AppSettingConfiguration> appSetting)
|
|
{
|
|
_httpClient = httpClientFactory.CreateClient();
|
|
|
|
if (appSetting.Value.Domain == ".dadmehrg.ir")
|
|
{
|
|
_pin = "7349F84E81AB584862D9";
|
|
}
|
|
|
|
}
|
|
|
|
public async Task<PaymentGatewayResponse> Create(CreatePaymentGatewayRequest command,CancellationToken cancellationToken =default)
|
|
{
|
|
var response = await _httpClient.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/create", new
|
|
{
|
|
pin = _pin,
|
|
amount = command.Amount,
|
|
callback = command.CallBackUrl,
|
|
card_number = command.CardNumber,
|
|
invoice_id = command.InvoiceId,
|
|
mobile = command.Mobile,
|
|
email = command.Email??"",
|
|
description = command.Description,
|
|
}, cancellationToken: cancellationToken);
|
|
var resStr = await response.Content.ReadAsStringAsync(cancellationToken);
|
|
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, 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>(cancellationToken: cancellationToken);
|
|
return result;
|
|
}
|
|
|
|
public async Task<PaymentGatewayResponse> CreateSandBox(CreatePaymentGatewayRequest command, CancellationToken cancellationToken = default)
|
|
{
|
|
var response = await _httpClient.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/create", new
|
|
{
|
|
pin = "sandbox",
|
|
amount = command.Amount,
|
|
callback = command.CallBackUrl,
|
|
card_number = command.Amount,
|
|
invoice_id = command.InvoiceId,
|
|
mobile = command.Mobile,
|
|
email = command.Email,
|
|
description = command.Email,
|
|
}, cancellationToken: cancellationToken);
|
|
|
|
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;
|
|
}
|
|
} |