Example #1
0
        public static async Task <IdPayCallbackResult> CreateCallbackResultAsync(
            InvoiceContext context,
            HttpRequest httpRequest,
            MessagesOptions messagesOptions,
            CancellationToken cancellationToken)
        {
            var status = await httpRequest.TryGetParamAsync("status", cancellationToken).ConfigureAwaitFalse();

            var id = await httpRequest.TryGetParamAsync("id", cancellationToken).ConfigureAwaitFalse();

            var trackId = await httpRequest.TryGetParamAsync("track_id", cancellationToken).ConfigureAwaitFalse();

            var orderId = await httpRequest.TryGetParamAsync("order_id", cancellationToken).ConfigureAwaitFalse();

            var amount = await httpRequest.TryGetParamAsync("amount", cancellationToken).ConfigureAwaitFalse();

            var(isSucceed, message) = CheckCallback(status.Value, orderId.Value, id.Value, trackId.Value, amount.Value, context, messagesOptions);

            IPaymentVerifyResult verifyResult = null;

            if (!isSucceed)
            {
                verifyResult = PaymentVerifyResult.Failed(message);
            }

            return(new IdPayCallbackResult
            {
                Id = id.Value,
                IsSucceed = isSucceed,
                Result = verifyResult
            });
        }
Example #2
0
        /// <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 = ZarinPalHelper.CreateVerifyData(account, callbackResult, context.Payment.Amount);

            var responseMessage = await _httpClient
                                  .PostXmlAsync(ZarinPalHelper.GetApiUrl(account.IsSandbox, _gatewayOptions), data, cancellationToken)
                                  .ConfigureAwaitFalse();

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

            return(ZarinPalHelper.CreateVerifyResult(response, _messagesOptions.Value));
        }
Example #3
0
        public static async Task <PaymentVerifyResult> CreateVerifyResult(HttpResponseMessage responseMessage, MessagesOptions messagesOptions)
        {
            var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse();

            if (!responseMessage.IsSuccessStatusCode)
            {
                var errorModel = JsonConvert.DeserializeObject <IdPayErrorModel>(response);

                return(PaymentVerifyResult.Failed(errorModel.ToString()));
            }

            var result = JsonConvert.DeserializeObject <IdPayVerifyResultModel>(response);

            if (result == null)
            {
                return(PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway));
            }

            if (result.Status.IsNullOrEmpty() || result.TrackId.IsNullOrEmpty())
            {
                return(PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway));
            }

            if (result.Status != Succeed)
            {
                return(PaymentVerifyResult.Failed($"Verification failed. Status: {result.Status}"));
            }

            return(PaymentVerifyResult.Succeed(result.TrackId, messagesOptions.PaymentSucceed));
        }
Example #4
0
        public static async Task <PaymentVerifyResult> CreateVerifyResult(HttpResponseMessage responseMessage, MessagesOptions messagesOptions)
        {
            var message = await responseMessage.Content.ReadAsStringAsync();

            var response = JsonConvert.DeserializeObject <ZibalPaymentVerifyResponseModel>(message);

            if (response == null)
            {
                return(PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway));
            }

            if (response.Result != SuccessCode)
            {
                var verifyResult = PaymentVerifyResult.Failed(response.Message);
                verifyResult.GatewayResponseCode = response.Result.ToString();

                if (response.Result == PaymentAlreadyVerifiedCode)
                {
                    verifyResult.Status = PaymentVerifyResultStatus.AlreadyVerified;
                }

                return(verifyResult);
            }

            return(PaymentVerifyResult.Succeed(response.RefNumber.ToString(), messagesOptions.PaymentSucceed));
        }
Example #5
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 IranKishHelper.CreateCallbackResultAsync(
                context,
                account,
                _httpContextAccessor.HttpContext.Request,
                _messageOptions.Value,
                cancellationToken);

            if (!callbackResult.IsSucceed)
            {
                return(PaymentVerifyResult.Failed(callbackResult.Message));
            }

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

            _httpClient.DefaultRequestHeaders.Clear();
            _httpClient.DefaultRequestHeaders.Add(IranKishHelper.HttpVerifyHeader.Key, IranKishHelper.HttpVerifyHeader.Value);

            var responseMessage = await _httpClient
                                  .PostXmlAsync(_gatewayOptions.ApiVerificationUrl, data, cancellationToken)
                                  .ConfigureAwaitFalse();

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

            return(IranKishHelper.CreateVerifyResult(response, context, callbackResult, _messageOptions.Value));
        }
Example #6
0
        public static async Task <PaymentVerifyResult> CreateVerifyResult(HttpResponseMessage responseMessage, MessagesOptions optionsMessages)
        {
            var message = await responseMessage.Content.ReadAsStringAsync();

            var response = JsonConvert.DeserializeObject <ZibalVerifyResponseModel>(message);

            if (response == null)
            {
                return(PaymentVerifyResult.Failed(optionsMessages.InvalidDataReceivedFromGateway));
            }

            if (response.Result != SuccessCode)
            {
                var failureMessage = ZibalTranslator.TranslateResult(response.Result) ?? optionsMessages.PaymentFailed;

                if (response.Status != null)
                {
                    failureMessage = ZibalTranslator.TranslateStatus((int)response.Status)
                                     ?? optionsMessages.PaymentFailed;
                }

                return(PaymentVerifyResult.Failed(failureMessage));
            }

            var successMessage = $"{optionsMessages.PaymentSucceed}-status is {response.Result}";

            return(PaymentVerifyResult.Succeed(response.RefNumber.ToString(), successMessage));
        }
Example #7
0
        /// <inheritdoc />
        public override async Task <IPaymentVerifyResult> VerifyAsync(InvoiceContext context, CancellationToken cancellationToken = default)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var callbackResult = await IdPayHelper.CreateCallbackResultAsync(
                context,
                _httpContextAccessor.HttpContext.Request,
                _messagesOptions,
                cancellationToken)
                                 .ConfigureAwaitFalse();

            if (!callbackResult.IsSucceed)
            {
                return(PaymentVerifyResult.Failed(callbackResult.Message));
            }

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

            IdPayHelper.AssignHeaders(_httpClient.DefaultRequestHeaders, account);

            var data = IdPayHelper.CreateVerifyData(context, callbackResult);

            var responseMessage = await _httpClient
                                  .PostJsonAsync(_gatewayOptions.ApiVerificationUrl, data, DefaultSerializerSettings, cancellationToken)
                                  .ConfigureAwaitFalse();

            return(await IdPayHelper.CreateVerifyResult(responseMessage, _messagesOptions));
        }
Example #8
0
        public static PasargadCallbackResult CreateCallbackResult(HttpRequest httpRequest, MessagesOptions messagesOptions)
        {
            //  Reference ID
            httpRequest.TryGetParam("iN", out var invoiceNumber);

            //  Invoice Date
            httpRequest.TryGetParam("iD", out var invoiceDate);

            //  Transaction Code
            httpRequest.TryGetParam("tref", out var transactionId);

            var isSucceed = true;
            PaymentVerifyResult verifyResult = null;

            if (string.IsNullOrWhiteSpace(invoiceNumber) ||
                string.IsNullOrWhiteSpace(invoiceDate) ||
                string.IsNullOrWhiteSpace(transactionId))
            {
                isSucceed = false;

                verifyResult = PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway);
            }

            var data = new[] { new KeyValuePair <string, string>("invoiceUID", transactionId) };

            return(new PasargadCallbackResult
            {
                IsSucceed = isSucceed,
                InvoiceNumber = invoiceNumber,
                InvoiceDate = invoiceDate,
                TransactionId = transactionId,
                CallbackCheckData = data,
                Result = verifyResult
            });
        }
Example #9
0
        public static AsanPardakhtVerifyResult CheckVerifyResult(
            string response,
            AsanPardakhtCallbackResult callbackResult,
            MessagesOptions messagesOptions)
        {
            if (!callbackResult.IsSucceed)
            {
                return(new AsanPardakhtVerifyResult
                {
                    IsSucceed = false,
                    Result = PaymentVerifyResult.Failed(callbackResult.Message)
                });
            }

            var result = XmlHelper.GetNodeValueFromXml(response, "RequestVerificationResult", "http://tempuri.org/");

            var isSucceed = result == "500";

            PaymentVerifyResult verifyResult = null;

            if (!isSucceed)
            {
                var message = AsanPardakhtResultTranslator.TranslateVerification(result, messagesOptions);

                verifyResult         = PaymentVerifyResult.Failed(message);
                verifyResult.Message = message;
            }

            return(new AsanPardakhtVerifyResult
            {
                IsSucceed = isSucceed,
                Result = verifyResult
            });
        }
Example #10
0
        internal static async Task <FanAvaCheckResultModel> CreateCheckResult(HttpResponseMessage responseMessage, FanAvaGatewayAccount account, FanAvaCallbackResultModel callbackResult, MessagesOptions messagesOptions)
        {
            var response = await responseMessage.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <FanAvaCheckResultModel>(response);

            bool isSucceed;
            PaymentVerifyResult verifyResult = null;

            if (!result.IsSucceed)
            {
                isSucceed    = false;
                verifyResult = PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway);
            }
            else
            {
                isSucceed = result.Result.Equals("erSucceed", StringComparison.OrdinalIgnoreCase) &&
                            result.InvoiceNumber == callbackResult.InvoiceNumber;

                if (!isSucceed)
                {
                    verifyResult = PaymentVerifyResult.Failed(messagesOptions.PaymentFailed);
                }
            }

            return(new FanAvaCheckResultModel
            {
                IsSucceed = isSucceed,
                VerifyResult = verifyResult
            });
        }
Example #11
0
        public static PaymentVerifyResult CreateVerifyResult(string response, MessagesOptions messagesOptions)
        {
            var result = JsonConvert.DeserializeObject <PayIrVerifyResponseModel>(response);

            PaymentVerifyResult verifyResult;

            if (result.IsSucceed)
            {
                verifyResult = PaymentVerifyResult.Succeed(result.TransId, messagesOptions.PaymentSucceed);
            }
            else
            {
                var message = $"ErrorCode: {result.ErrorCode}, ErrorMessage: {result.ErrorMessage}";

                verifyResult = PaymentVerifyResult.Failed(message);
            }

            var additionalData = new PayIrVerifyAdditionalData
            {
                CardNumber   = result.CardNumber,
                FactorNumber = result.FactorNumber,
                Description  = result.Description,
                Mobile       = result.Mobile
            };

            verifyResult.SetPayIrAdditionalData(additionalData);

            return(verifyResult);
        }
Example #12
0
        public static PaymentVerifyResult CreateVerifyResult(MelliApiVerifyResult result, MessagesOptions messagesOptions)
        {
            if (result == null)
            {
                return(PaymentVerifyResult.Failed(messagesOptions.UnexpectedErrorText));
            }

            string message;

            if (!result.Description.IsNullOrEmpty())
            {
                message = result.Description;
            }
            else
            {
                message = MelliVerifyResultTranslator.Translate(result.ResCode, messagesOptions);
            }

            var status = result.ResCode == SuccessCode
                ? PaymentVerifyResultStatus.Succeed
                : PaymentVerifyResultStatus.Failed;

            return(new PaymentVerifyResult
            {
                Status = status,
                TransactionCode = result.RetrivalRefNo,
                Message = message
            });
        }
Example #13
0
        public static async Task <ZarinPalCallbackResult> CreateCallbackResultAsync(HttpRequest httpRequest,
                                                                                    CancellationToken cancellationToken)
        {
            var authority = await httpRequest.TryGetParamAsync("Authority", cancellationToken).ConfigureAwaitFalse();

            var status = await httpRequest.TryGetParamAsync("Status", cancellationToken).ConfigureAwaitFalse();

            IPaymentVerifyResult verifyResult = null;

            var isSucceed = status.Exists && string.Equals(status.Value, StringOkResult, StringComparison.InvariantCultureIgnoreCase);

            if (!isSucceed)
            {
                var message = $"Error {status}";

                verifyResult = PaymentVerifyResult.Failed(message);
            }

            return(new ZarinPalCallbackResult
            {
                Authority = authority.Value,
                IsSucceed = isSucceed,
                Result = verifyResult
            });
        }
Example #14
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 MelliHelper.CreateCallbackResultAsync(
                context,
                _httpContextAccessor.HttpContext.Request,
                account,
                _crypto,
                _messageOptions.Value,
                cancellationToken);

            if (!callbackResult.IsSucceed)
            {
                return(PaymentVerifyResult.Failed(callbackResult.Message));
            }

            var result = await PostJsonAsync <MelliApiVerifyResult>(_gatewayOptions.ApiVerificationUrl, callbackResult.JsonDataToVerify, cancellationToken).ConfigureAwaitFalse();

            return(MelliHelper.CreateVerifyResult(result, _messageOptions.Value));
        }
Example #15
0
        internal static async Task <FanAvaCheckResultModel> CreateCheckResult(HttpResponseMessage responseMessage, FanAvaGatewayAccount account, FanAvaCallbackResultModel callbackResult, MessagesOptions messagesOptions)
        {
            var result = await responseMessage.Content.ReadFromJsonAsync <FanAvaCheckResultModel>();

            bool isSucceed;
            PaymentVerifyResult verifyResult = null;

            if (!result.IsSucceed)
            {
                isSucceed    = false;
                verifyResult = PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway);
            }
            else
            {
                isSucceed = result.Result.Equals("erSucceed", StringComparison.OrdinalIgnoreCase) &&
                            result.InvoiceNumber == callbackResult.InvoiceNumber;

                if (!isSucceed)
                {
                    verifyResult = PaymentVerifyResult.Failed("پرداخت موفقيت آميز نبود و يا توسط خريدار کنسل شده است");
                }
            }

            return(new FanAvaCheckResultModel()
            {
                IsSucceed = isSucceed,
                VerifyResult = verifyResult
            });
        }
Example #16
0
        public static PaymentVerifyResult CreateVerifyResult(string response, MessagesOptions messagesOptions)
        {
            var result = JsonConvert.DeserializeObject <PayIrVerifyResponseModel>(response);

            if (!result.IsSucceed)
            {
                var message = $"ErrorCode: {result.ErrorCode}, ErrorMessage: {result.ErrorMessage}";

                return(PaymentVerifyResult.Failed(message));
            }

            return(PaymentVerifyResult.Succeed(result.TransId, messagesOptions.PaymentSucceed));
        }
Example #17
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(PaymentVerifyResult.Failed(callbackResult.Message));
            }

            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));
        }
Example #18
0
        public static async Task <SamanCallbackResult> CreateCallbackResultAsync(
            HttpRequest httpRequest,
            MessagesOptions messagesOptions,
            CancellationToken cancellationToken)
        {
            var isSuccess = false;
            PaymentVerifyResult verifyResult = null;
            StringValues        referenceId;
            StringValues        transactionId;

            var state = await httpRequest.TryGetParamAsync("state", cancellationToken).ConfigureAwaitFalse();

            if (!state.Exists || state.Value.IsNullOrEmpty())
            {
                verifyResult = PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway);
            }
            else
            {
                var referenceIdResult = await httpRequest.TryGetParamAsync("ResNum", cancellationToken).ConfigureAwaitFalse();

                if (referenceIdResult.Exists)
                {
                    referenceId = referenceIdResult.Value;
                }

                var transactionIdResult = await httpRequest.TryGetParamAsync("RefNum", cancellationToken).ConfigureAwaitFalse();

                if (transactionIdResult.Exists)
                {
                    transactionId = transactionIdResult.Value;
                }

                isSuccess = state.Value.Equals("OK", StringComparison.OrdinalIgnoreCase);

                if (!isSuccess)
                {
                    var message = SamanStateTranslator.Translate(state.Value, messagesOptions);

                    verifyResult = PaymentVerifyResult.Failed(message);
                }
            }

            return(new SamanCallbackResult
            {
                IsSucceed = isSuccess,
                ReferenceId = referenceId,
                TransactionId = transactionId,
                Result = verifyResult
            });
        }
Example #19
0
        /// <inheritdoc />
        public override async Task <IPaymentVerifyResult> VerifyAsync(InvoiceContext context, CancellationToken cancellationToken = default)
        {
            var request = _httpContextAccessor.HttpContext.Request;

            var callbackResult = await GetCallbackResult(cancellationToken);

            if (!callbackResult.IsSucceed)
            {
                return(PaymentVerifyResult.Failed(callbackResult.Message));
            }

            var transactionCode = await request.TryGetParamAsync("TransactionCode", cancellationToken).ConfigureAwaitFalse();

            return(PaymentVerifyResult.Succeed(transactionCode.Value, _messageOptions.Value.PaymentSucceed));
        }
Example #20
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 AsanPardakhtHelper.CreateCallbackResult(
                context,
                account,
                _httpContextAccessor.HttpContext.Request,
                _crypto,
                _messageOptions);

            if (!callbackResult.IsSucceed)
            {
                return(PaymentVerifyResult.Failed(callbackResult.Message));
            }

            var data = await AsanPardakhtHelper.CreateVerifyData(callbackResult, account, _crypto)
                       .ConfigureAwaitFalse();

            var responseMessage = await _httpClient
                                  .PostXmlAsync(_gatewayOptions.ApiUrl, data, cancellationToken)
                                  .ConfigureAwaitFalse();

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

            var verifyResult = AsanPardakhtHelper.CheckVerifyResult(response, callbackResult, _messageOptions);

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

            data = await AsanPardakhtHelper.CreateSettleData(callbackResult, account, _crypto)
                   .ConfigureAwaitFalse();

            responseMessage = await _httpClient
                              .PostXmlAsync(_gatewayOptions.ApiUrl, data, cancellationToken)
                              .ConfigureAwaitFalse();

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

            return(AsanPardakhtHelper.CreateSettleResult(response, callbackResult, _messageOptions));
        }
Example #21
0
        public static PaymentVerifyResult CreateVerifyResult(string response, MessagesOptions messagesOptions)
        {
            var status = XmlHelper.GetNodeValueFromXml(response, "Status", "http://zarinpal.com/");
            var refId  = XmlHelper.GetNodeValueFromXml(response, "RefID", "http://zarinpal.com/");

            var isSucceed = string.Equals(status, OkResult, StringComparison.InvariantCultureIgnoreCase);

            if (!isSucceed)
            {
                var message = $"Error {status}";

                return(PaymentVerifyResult.Failed(message));
            }

            return(PaymentVerifyResult.Succeed(refId, messagesOptions.PaymentSucceed));
        }
Example #22
0
        public static ParsianCallbackResult CreateCallbackResult(VerifyContext context, HttpRequest httpRequest, MessagesOptions messagesOptions)
        {
            httpRequest.Form.TryGetValue("token", out var token);
            httpRequest.Form.TryGetValue("status", out var status);
            httpRequest.Form.TryGetValue("orderId", out var orderId);
            httpRequest.Form.TryGetValue("amount", out var amount);
            httpRequest.Form.TryGetValue("RRN", out var rrn);

            var isSucceed = !status.IsNullOrEmpty() &&
                            status == "0" &&
                            !token.IsNullOrEmpty();

            string message = null;

            if (isSucceed)
            {
                if (rrn.IsNullOrEmpty() ||
                    amount.IsNullOrEmpty() ||
                    orderId.IsNullOrEmpty() ||
                    !long.TryParse(orderId, out var numberOrderNumber) ||
                    !long.TryParse(amount, out var numberAmount) ||
                    numberOrderNumber != context.Payment.TrackingNumber ||
                    numberAmount != (long)context.Payment.Amount)
                {
                    isSucceed = false;
                    message   = messagesOptions.InvalidDataReceivedFromGateway;
                }
            }
            else
            {
                message = $"Error {status}";
            }

            PaymentVerifyResult verifyResult = null;

            if (!isSucceed)
            {
                verifyResult = PaymentVerifyResult.Failed(message);
            }

            return(new ParsianCallbackResult
            {
                IsSucceed = isSucceed,
                RRN = rrn,
                Result = verifyResult
            });
        }
Example #23
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 PayPingGatewayHelper.GetCallbackResult(
                _httpContextAccessor.HttpContext.Request,
                context,
                _options.Messages,
                cancellationToken);

            if (!callbackResult.IsSucceed)
            {
                return(PaymentVerifyResult.Failed(callbackResult.Message));
            }

            var verificationModel = PayPingGatewayHelper.CreateVerificationModel(context, callbackResult);

            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", account.AccessToken);

            //Send Verify pay Request
            var response = await _httpClient.PostJsonAsync(_pingGatewayOptions.ApiVerificationUrl, verificationModel, cancellationToken);

            //Check if we ran into an Issue
            if (!response.IsSuccessStatusCode)
            {
                return(PaymentVerifyResult.Failed(_options.Messages.PaymentFailed));
            }

            //Get Response data
            var responseBody = await response.Content.ReadAsStringAsync();

            var responseModel = JsonConvert.DeserializeObject <VerifyPayResponseModel>(responseBody);

            if (responseModel.Amount != (long)context.Payment.Amount)
            {
                var message = $"{_options.Messages.PaymentFailed} Amount is not valid.";

                return(PaymentVerifyResult.Failed(message));
            }

            return(PaymentVerifyResult.Succeed(callbackResult.RefId, _options.Messages.PaymentSucceed));
        }
Example #24
0
        public static async Task <MelliCallbackResult> CreateCallbackResultAsync(
            InvoiceContext context,
            HttpRequest httpRequest,
            MelliGatewayAccount account,
            IMelliGatewayCrypto crypto,
            MessagesOptions messagesOptions,
            CancellationToken cancellationToken)
        {
            var apiResponseCode = await httpRequest.TryGetParamAsAsync <int>("ResCode", cancellationToken).ConfigureAwaitFalse();

            if (!apiResponseCode.Exists || apiResponseCode.Value != SuccessCode)
            {
                return(new MelliCallbackResult
                {
                    IsSucceed = false,
                    Result = PaymentVerifyResult.Failed(messagesOptions.PaymentFailed)
                });
            }

            var apiToken = await httpRequest.TryGetParamAsync("Token", cancellationToken).ConfigureAwaitFalse();

            var apiOrderId = await httpRequest.TryGetParamAsAsync <long>("OrderId", cancellationToken).ConfigureAwaitFalse();

            if (!apiOrderId.Exists || apiOrderId.Value != context.Payment.TrackingNumber)
            {
                return(new MelliCallbackResult
                {
                    IsSucceed = false,
                    Token = apiToken.Value,
                    Result = PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway)
                });
            }

            var signedData = crypto.Encrypt(account.TerminalKey, apiToken.Value);

            var dataToVerify = CreateVerifyObject(apiToken.Value, signedData);

            return(new MelliCallbackResult
            {
                IsSucceed = true,
                Token = apiToken.Value,
                JsonDataToVerify = dataToVerify
            });
        }
Example #25
0
        internal static async Task <IPaymentVerifyResult> CreateVerifyResult(HttpResponseMessage responseMessage, FanAvaCallbackResultModel callbackResult, MessagesOptions messagesOptions)
        {
            var verifyResult = await responseMessage.Content.ReadFromJsonAsync <FanAvaVerifyResultModel>()
                               .ConfigureAwaitFalse();

            var isSucceed = verifyResult.Result == "erSucceed";

            if (!isSucceed)
            {
                return(PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway));
            }
            return(new PaymentVerifyResult
            {
                IsSucceed = verifyResult.Result == "erSucceed",
                Amount = Money.Parse(verifyResult.Amount),
                TrackingNumber = long.Parse(verifyResult.InvoiceNumber),
                Status = PaymentVerifyResultStatus.Succeed
            });
        }
Example #26
0
        internal static async Task <IPaymentVerifyResult> CreateVerifyResult(HttpResponseMessage responseMessage, FanAvaCallbackResultModel callbackResult, MessagesOptions messagesOptions)
        {
            var response = await responseMessage.Content.ReadAsStringAsync();

            var verifyResult = JsonConvert.DeserializeObject <FanAvaVerifyResultModel>(response);

            if (!verifyResult.IsSucceed)
            {
                return(PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway));
            }

            return(new PaymentVerifyResult
            {
                IsSucceed = verifyResult.Result == "erSucceed",
                Amount = Money.Parse(verifyResult.Amount),
                TrackingNumber = long.Parse(verifyResult.InvoiceNumber),
                Status = PaymentVerifyResultStatus.Succeed
            });
        }
Example #27
0
        public static MelliCallbackResult CreateCallbackResult(Payment payment, HttpRequest httpRequest, MelliGatewayOptions options, MessagesOptions messagesOptions)
        {
            httpRequest.TryGetParamAs <int>("ResCode", out var apiResponseCode);

            if (apiResponseCode != SuccessCode)
            {
                return(new MelliCallbackResult
                {
                    IsSucceed = false,
                    Result = PaymentVerifyResult.Failed(messagesOptions.PaymentFailed)
                });
            }

            httpRequest.TryGetParam("Token", out var apiToken);
            httpRequest.TryGetParamAs <long>("OrderId", out var apiOrderId);

            if (apiOrderId != payment.TrackingNumber)
            {
                return(new MelliCallbackResult
                {
                    IsSucceed = false,
                    Token = apiToken,
                    Result = PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway)
                });
            }

            var signedData = SignVerifyData(options.TerminalKey, apiToken);

            var dataToVerify = new
            {
                token    = apiToken,
                SignData = signedData
            };

            return(new MelliCallbackResult
            {
                IsSucceed = true,
                Token = apiToken,
                JsonDataToVerify = dataToVerify,
                Result = null
            });
        }
Example #28
0
        public static async Task <PaymentVerifyResult> CreateVerifyResult(HttpResponseMessage responseMessage, MessagesOptions optionsMessages)
        {
            var message = await responseMessage.Content.ReadAsStringAsync();

            var response = JsonConvert.DeserializeObject <YekPayVerificationResponseModel>(message);

            if (response == null)
            {
                return(PaymentVerifyResult.Failed(optionsMessages.InvalidDataReceivedFromGateway));
            }

            if (response.Code != SuccessCode)
            {
                var failureMessage = response.Description ?? optionsMessages.PaymentFailed;

                return(PaymentVerifyResult.Failed(failureMessage));
            }

            return(PaymentVerifyResult.Succeed(response.Reference, optionsMessages.PaymentSucceed));
        }
Example #29
0
        public virtual Task <IPaymentVerifyResult> VerifyAsync(Payment payment, CancellationToken cancellationToken = default)
        {
            if (!_httpContextAccessor.HttpContext.Request.TryGetParam("Result", out var result))
            {
                return(PaymentVerifyResult.Failed(_messageOptions.Value.InvalidDataReceivedFromGateway).ToInterfaceAsync());
            }

            _httpContextAccessor.HttpContext.Request.TryGetParam("TransactionCode", out var transactionCode);

            var isSucceed = result.Equals("true", StringComparison.OrdinalIgnoreCase);

            var message = isSucceed ? _messageOptions.Value.PaymentSucceed : _messageOptions.Value.PaymentFailed;

            return(new PaymentVerifyResult
            {
                IsSucceed = isSucceed,
                TransactionCode = transactionCode,
                Message = message
            }.ToInterfaceAsync());
        }
Example #30
0
        public static PasargadCheckCallbackResult CreateCheckCallbackResult(string webServiceResponse, PasargadGatewayAccount account, PasargadCallbackResult callbackResult, MessagesOptions messagesOptions)
        {
            var compareReferenceId  = XmlHelper.GetNodeValueFromXml(webServiceResponse, "invoiceNumber");
            var compareAction       = XmlHelper.GetNodeValueFromXml(webServiceResponse, "action");
            var compareMerchantCode = XmlHelper.GetNodeValueFromXml(webServiceResponse, "merchantCode");
            var compareTerminalCode = XmlHelper.GetNodeValueFromXml(webServiceResponse, "terminalCode");

            bool isSucceed;
            PaymentVerifyResult verifyResult = null;

            if (compareReferenceId.IsNullOrWhiteSpace() ||
                compareAction.IsNullOrWhiteSpace() ||
                compareMerchantCode.IsNullOrWhiteSpace() ||
                compareTerminalCode.IsNullOrWhiteSpace())
            {
                isSucceed = false;

                verifyResult = PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway);
            }
            else
            {
                var responseResult = XmlHelper.GetNodeValueFromXml(webServiceResponse, "result");

                isSucceed = responseResult.Equals("true", StringComparison.OrdinalIgnoreCase) &&
                            compareReferenceId == callbackResult.InvoiceNumber &&
                            compareAction == ActionNumber &&
                            compareMerchantCode == account.MerchantCode &&
                            compareTerminalCode == account.TerminalCode;

                if (!isSucceed)
                {
                    verifyResult = PaymentVerifyResult.Failed("پرداخت موفقيت آميز نبود و يا توسط خريدار کنسل شده است");
                }
            }

            return(new PasargadCheckCallbackResult
            {
                IsSucceed = isSucceed,
                Result = verifyResult
            });
        }