39 lines
1.8 KiB
C#
39 lines
1.8 KiB
C#
namespace HiVakil.Infrastructure.Services;
|
|
|
|
public class ZarinpalService : IPaymentService
|
|
{
|
|
private readonly IRestApiWrapper _restApiWrapper;
|
|
private readonly IMediator _mediator;
|
|
private readonly SiteSettings _siteSettings;
|
|
public ZarinpalService(IRestApiWrapper restApiWrapper,
|
|
IOptionsSnapshot<SiteSettings> snapshot,
|
|
IMediator mediator)
|
|
{
|
|
_restApiWrapper = restApiWrapper;
|
|
_mediator = mediator;
|
|
_siteSettings = snapshot.Value;
|
|
}
|
|
public async Task<string> GetPaymentLinkAsync(double amount,string factorNumber, Guid orderId, Guid userId, string phoneNumber , string fullName , CancellationToken cancellationToken = default)
|
|
{
|
|
var request = new ZarinaplPaymentLinkRequest
|
|
{
|
|
description = $"پرداخت {amount.ToString("N0")} ریال توسط {fullName} با شماره تماس {phoneNumber} برای سفارش با شماره {factorNumber}",
|
|
amount = (int)amount,
|
|
callback_url = Path.Combine(_siteSettings.BaseUrl, "api", "accounting", "pay", "verify"),
|
|
//merchant_id = "4292b845-b510-4d1d-8ee2-097499b198e5",
|
|
metadata = new ZarinaplPaymentLinkRequestMetadata { mobile = phoneNumber }
|
|
};
|
|
var response = await _restApiWrapper.ZarinpalRestApi.GetPaymentLinkAsync(request);
|
|
if (response.data.code != 100)
|
|
throw new AppException($"Exception in get link from zarinpal | {response.data.message}");
|
|
|
|
|
|
string link = $"https://www.zarinpal.com/pg/StartPay/{response.data.authority}";
|
|
return link;
|
|
}
|
|
|
|
public async Task<Tuple<string,string>> VerifyPaymentAsync(string authority, CancellationToken cancellationToken = default)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
} |