/// <inheritdoc /> public override async Task <IPaymentVerifyResult> VerifyAsync(InvoiceContext context, CancellationToken cancellationToken = default) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var callbackResult = await PasargadHelper.CreateCallbackResult( _httpContextAccessor.HttpContext.Request, _messageOptions.Value, cancellationToken) .ConfigureAwaitFalse(); if (!callbackResult.IsSucceed) { return(callbackResult.Result); } var responseMessage = await _httpClient.PostFormAsync( _gatewayOptions.ApiCheckPaymentUrl, callbackResult.CallbackCheckData, cancellationToken) .ConfigureAwaitFalse(); var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse(); var account = await GetAccountAsync(context.Payment).ConfigureAwaitFalse(); var checkCallbackResult = PasargadHelper.CreateCheckCallbackResult( response, account, callbackResult, _messageOptions.Value); if (!checkCallbackResult.IsSucceed) { return(checkCallbackResult.Result); } var data = PasargadHelper.CreateVerifyData(context, account, _crypto, callbackResult); responseMessage = await _httpClient.PostFormAsync( _gatewayOptions.ApiVerificationUrl, data, cancellationToken) .ConfigureAwaitFalse(); response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse(); return(PasargadHelper.CreateVerifyResult(response, callbackResult, _messageOptions.Value)); }
/// <inheritdoc /> public override async Task <IPaymentFetchResult> FetchAsync(InvoiceContext context, CancellationToken cancellationToken = default) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var callbackResult = await PasargadHelper.CreateCallbackResult( _httpContextAccessor.HttpContext.Request, _messageOptions.Value, cancellationToken) .ConfigureAwaitFalse(); if (callbackResult.IsSucceed) { return(PaymentFetchResult.ReadyForVerifying()); } return(PaymentFetchResult.Failed(callbackResult.Message)); }
private async Task <PasargadCallbackResult> GetCallbackResult(InvoiceContext context, CancellationToken cancellationToken) { var callBackTransaction = context.Transactions.SingleOrDefault(x => x.Type == TransactionType.Callback); var account = await GetAccountAsync(context.Payment).ConfigureAwaitFalse(); PasargadCallbackResult callbackResult; if (callBackTransaction == null) { callbackResult = await PasargadHelper.CreateCallbackResult( _httpContextAccessor.HttpContext.Request, _messageOptions.Value, cancellationToken) .ConfigureAwaitFalse(); } else { callbackResult = JsonConvert.DeserializeObject <PasargadCallbackResult>(callBackTransaction.AdditionalData); } return(callbackResult); }