Example #1
0
        /// <inheritdoc />
        public override async Task <IPaymentVerifyResult> VerifyAsync(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(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));
        }
Example #2
0
        /// <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));
        }
Example #3
0
        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);
        }