Ejemplo n.º 1
0
        private async Task <CallbackResultModel> GetCallbackResult(InvoiceContext context, CancellationToken cancellationToken)
        {
            var callBackTransaction = context.Transactions.SingleOrDefault(x => x.Type == TransactionType.Callback);

            var account = await GetAccountAsync(context.Payment).ConfigureAwaitFalse();

            CallbackResultModel callbackResult;

            if (callBackTransaction == null)
            {
                callbackResult = await SepehrHelper.CreateCallbackResultAsync(
                    context,
                    _httpContextAccessor.HttpContext.Request,
                    account,
                    _options.Messages,
                    cancellationToken)
                                 .ConfigureAwaitFalse();
            }
            else
            {
                callbackResult =
                    JsonConvert.DeserializeObject <CallbackResultModel>(callBackTransaction.AdditionalData);
            }

            return(callbackResult);
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public override async Task <IPaymentVerifyResult> VerifyAsync(InvoiceContext context, CancellationToken cancellationToken = default)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var account = await GetAccountAsync(context.Payment).ConfigureAwaitFalse();

            var callbackResult = await SepehrHelper.CreateCallbackResultAsync(
                context,
                _httpContextAccessor.HttpContext.Request,
                account,
                _options.Messages,
                cancellationToken)
                                 .ConfigureAwaitFalse();

            if (!callbackResult.IsSucceed)
            {
                return(callbackResult.Result);
            }

            var data = SepehrHelper.CreateVerifyData(callbackResult, account);

            var responseMessage = await _httpClient
                                  .PostJsonAsync(SepehrHelper.ApiAdviceUrl, data, DefaultSerializerSettings, cancellationToken)
                                  .ConfigureAwaitFalse();

            return(await SepehrHelper.CreateVerifyResult(context, responseMessage, callbackResult, _options.Messages));
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public override async Task <IPaymentFetchResult> FetchAsync(InvoiceContext context, CancellationToken cancellationToken = default)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var account = await GetAccountAsync(context.Payment).ConfigureAwaitFalse();

            var callbackResult = await SepehrHelper.CreateCallbackResultAsync(
                context,
                _httpContextAccessor.HttpContext.Request,
                account,
                _options.Messages,
                cancellationToken)
                                 .ConfigureAwaitFalse();

            if (callbackResult.IsSucceed)
            {
                return(PaymentFetchResult.ReadyForVerifying());
            }

            return(PaymentFetchResult.Failed(callbackResult.Message));
        }