/// <inheritdoc /> public override async Task <IPaymentVerifyResult> VerifyAsync(InvoiceContext context, CancellationToken cancellationToken = default) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var callbackResult = await GetCallbackResult(context, cancellationToken); if (!callbackResult.IsSucceed) { return(PaymentVerifyResult.Failed(callbackResult.Message)); } var account = await GetAccountAsync(context.Payment).ConfigureAwaitFalse(); var data = SamanHelper.CreateVerifyData(callbackResult, account); var responseMessage = await _httpClient .PostXmlAsync(SamanHelper.GetVerificationUrl(context, _gatewayOptions), data, cancellationToken) .ConfigureAwaitFalse(); var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse(); return(SamanHelper.CreateVerifyResult(response, context, callbackResult, _messageOptions)); }
/// <inheritdoc /> public override async Task <IPaymentRequestResult> RequestAsync(Invoice invoice, CancellationToken cancellationToken = default) { if (invoice == null) { throw new ArgumentNullException(nameof(invoice)); } var account = await GetAccountAsync(invoice).ConfigureAwaitFalse(); return(SamanHelper.CreateRequestResult(invoice, _httpContextAccessor.HttpContext, account)); }
public async Task <IActionResult> Verify(Guid id) { try { var application = await GetApplicationAsync(); if (application == null || application.Status != 0) { return(Unauthorized()); } var transaction = await _transactionRepository.Get(id); if (transaction == null) { return(Unauthorized()); } switch (transaction.Bank.Code) { case (byte)BankCodeEnum.Mellat: var mellatHelper = new MellatHelper(_logger, _transactionRepository, _applicationBankRepository); var mellatResult = await mellatHelper.VerifyTransaction(transaction); return(Ok(mellatResult)); case (byte)BankCodeEnum.Efarda: var efardaHelper = new EfardaHelper(_logger, _transactionRepository, _applicationBankRepository); var efardaResult = await efardaHelper.VerifyTransaction(transaction); return(Ok(efardaResult)); case (byte)BankCodeEnum.Saman: default: var samanHelper = new SamanHelper(_logger, _transactionRepository, _applicationBankRepository); var result = await samanHelper.VerifyTransaction(transaction); return(Ok(result)); } } catch (Exception ex) { _logger.LogError(ex.Message); if (ex.InnerException != null) { _logger.LogError(ex.InnerException.Message); } throw; } }
public async Task <IActionResult> Verify(string publicKey, Guid id) { try { Application application = await _applicationRepository.GetFirstBy(x => x.PublicKey == publicKey); if (application == null || application.Status != 0) { return(Unauthorized()); } var transaction = await _transactionRepository.Get(id); if (transaction == null) { return(Unauthorized()); } switch (transaction.Bank.Code) { case ((byte)BankCodeEnum.Mellat): MellatHelper mellatHelper = new MellatHelper(_logger, _transactionRepository, _applicationRepository, _bankRepository, _applicationBankRepository); VerifyTransactionResponseModel mellatResult = await mellatHelper.VerifyTransaction(transaction); return(Ok(mellatResult)); case ((byte)BankCodeEnum.Saman): default: SamanHelper samanHelper = new SamanHelper(_logger, _transactionRepository, _applicationRepository, _bankRepository, _applicationBankRepository); VerifyTransactionResponseModel result = await samanHelper.VerifyTransaction(transaction); return(Ok(result)); } } catch (Exception ex) { _logger.LogError(ex.Message); if (ex.InnerException != null) { _logger.LogError(ex.InnerException.Message); } throw; } }
/// <inheritdoc /> public override async Task <IPaymentRefundResult> RefundAsync(InvoiceContext context, Money amount, CancellationToken cancellationToken = default) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var account = await GetAccountAsync(context.Payment).ConfigureAwaitFalse(); var data = SamanHelper.CreateRefundData(context, amount, account); var responseMessage = await _httpClient .PostXmlAsync(SamanHelper.GetVerificationUrl(context, _gatewayOptions), data, cancellationToken) .ConfigureAwaitFalse(); var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse(); return(SamanHelper.CreateRefundResult(response, _messageOptions)); }
/// <inheritdoc /> public override async Task <IPaymentFetchResult> FetchAsync(InvoiceContext context, CancellationToken cancellationToken = default) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var callbackResult = await SamanHelper.CreateCallbackResultAsync( _httpContextAccessor.HttpContext.Request, _messageOptions, cancellationToken) .ConfigureAwaitFalse(); if (callbackResult.IsSucceed) { return(PaymentFetchResult.ReadyForVerifying()); } return(PaymentFetchResult.Failed(callbackResult.Message)); }
private async Task <SamanCallbackResult> GetCallbackResult(InvoiceContext context, CancellationToken cancellationToken) { var callBackTransaction = context.Transactions.SingleOrDefault(x => x.Type == TransactionType.Callback); SamanCallbackResult callbackResult; if (callBackTransaction == null) { callbackResult = await SamanHelper.CreateCallbackResultAsync( _httpContextAccessor.HttpContext.Request, _messageOptions, cancellationToken) .ConfigureAwaitFalse(); } else { callbackResult = JsonConvert.DeserializeObject <SamanCallbackResult>(callBackTransaction.AdditionalData); } return(callbackResult); }