Beispiel #1
0
        /// <inheritdoc />
        public override async Task <IPaymentRefundResult> RefundAsync(InvoiceContext context, Money amount, CancellationToken cancellationToken = default)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (amount == null)
            {
                throw new ArgumentNullException(nameof(amount));
            }

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

            var data = PasargadHelper.CreateRefundData(context, amount, account);

            var responseMessage = await _httpClient.PostFormAsync(
                PasargadHelper.RefundPaymentPageUrl,
                data,
                cancellationToken)
                                  .ConfigureAwaitFalse();

            var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse();

            return(PasargadHelper.CreateRefundResult(response, _messageOptions.Value));
        }
Beispiel #2
0
        /// <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(PasargadHelper.CreateRequestResult(invoice, _httpContextAccessor.HttpContext, account, _crypto, _gatewayOptions));
        }
Beispiel #3
0
        /// <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));
        }
Beispiel #4
0
        /// <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));
        }
Beispiel #5
0
        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);
        }