Esempio n. 1
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));
        }
Esempio n. 2
0
        public static PaymentVerifyResult CreateSettleResult(
            string response,
            AsanPardakhtCallbackResult callbackResult,
            MessagesOptions messagesOptions)
        {
            var result = XmlHelper.GetNodeValueFromXml(response, "RequestReconciliationResult", "http://tempuri.org/");

            var    isSucceed = result == "600";
            string message;

            if (isSucceed)
            {
                message = messagesOptions.PaymentSucceed;
            }
            else
            {
                message = AsanPardakhtResultTranslator.TranslateReconcilation(result, messagesOptions) ??
                          messagesOptions.PaymentFailed;
            }

            var verifyResult = new PaymentVerifyResult
            {
                Status          = isSucceed ? PaymentVerifyResultStatus.Succeed : PaymentVerifyResultStatus.Failed,
                TransactionCode = callbackResult.Rrn,
                Message         = message
            };

            verifyResult.DatabaseAdditionalData.Add("PayGateTranId", callbackResult.PayGateTranId);
            verifyResult.DatabaseAdditionalData.Add("LastFourDigitOfPAN", callbackResult.LastFourDigitOfPAN);

            return(verifyResult);
        }
Esempio n. 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 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));
        }
Esempio n. 4
0
        public static AsanPardakhtVerifyResult CheckVerifyResult(
            string response,
            AsanPardakhtCallbackResult callbackResult,
            MessagesOptions messagesOptions)
        {
            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         = callbackResult.Result;
                verifyResult.Message = message;
            }

            return(new AsanPardakhtVerifyResult
            {
                IsSucceed = isSucceed,
                Result = verifyResult
            });
        }
Esempio n. 5
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
            });
        }
Esempio n. 6
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));
        }
Esempio n. 7
0
        public static PaymentVerifyResult CreateVerifyResult(string webServiceResponse, MessagesOptions messagesOptions)
        {
            var status = XmlHelper.GetNodeValueFromXml(webServiceResponse, "Status", "https://pec.Shaparak.ir/NewIPGServices/Confirm/ConfirmService");
            var rrn    = XmlHelper.GetNodeValueFromXml(webServiceResponse, "RRN", "https://pec.Shaparak.ir/NewIPGServices/Confirm/ConfirmService");
            var token  = XmlHelper.GetNodeValueFromXml(webServiceResponse, "Token", "https://pec.Shaparak.ir/NewIPGServices/Confirm/ConfirmService");

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

            var message = isSucceed
                ? messagesOptions.PaymentSucceed
                : $"Error in Verifying section: {status}";

            var result = new PaymentVerifyResult
            {
                Status          = isSucceed ? PaymentVerifyResultStatus.Succeed : PaymentVerifyResultStatus.Failed,
                TransactionCode = rrn,
                Message         = message
            };

            result.DatabaseAdditionalData.Add("token", token);

            return(result);
        }
Esempio n. 8
0
        public static PaymentVerifyResult CreateVerifyResult(string webServiceResponse, InvoiceContext context, SamanCallbackResult callbackResult, MessagesOptions messagesOptions)
        {
            var stringResult = XmlHelper.GetNodeValueFromXml(webServiceResponse, "result");

            //  This result is actually: TotalAmount
            //  it must be equals to TotalAmount in database.
            var numericResult = Convert.ToInt64(stringResult);

            var isSuccess = numericResult > 0 && numericResult == (long)context.Payment.Amount;

            var message = isSuccess
                ? messagesOptions.PaymentSucceed
                : SamanResultTranslator.Translate(numericResult, messagesOptions);

            var result = new PaymentVerifyResult
            {
                Status          = isSuccess ? PaymentVerifyResultStatus.Succeed : PaymentVerifyResultStatus.Failed,
                TransactionCode = callbackResult.TransactionId,
                Message         = message
            };

            result.AdditionalData.Add(AdditionalVerificationDataKey, new SamanAdditionalVerificationData
            {
                Cid       = callbackResult.Cid,
                TraceNo   = callbackResult.TraceNo,
                SecurePan = callbackResult.SecurePan,
                Rrn       = callbackResult.Rrn
            });

            return(result);
        }
Esempio n. 9
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
            });
        }
Esempio n. 10
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
            });
        }
Esempio n. 11
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
            });
        }
Esempio n. 12
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);
        }
Esempio n. 13
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
            });
        }
Esempio n. 14
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));
        }
Esempio n. 15
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
            });
        }
Esempio n. 16
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));
        }
Esempio n. 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 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));
        }
Esempio n. 18
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));
        }
Esempio n. 19
0
        public static IranKishCallbackResult CreateCallbackResult(
            InvoiceContext context,
            IranKishGatewayAccount account,
            HttpRequest httpRequest,
            MessagesOptions messagesOptions)
        {
            httpRequest.TryGetParam("ResultCode", out var resultCode);
            httpRequest.Form.TryGetValue("Token", out var token);
            httpRequest.TryGetParam("MerchantId", out var merchantId);

            // Equals to TrackingNumber in Parbad system.
            httpRequest.TryGetParamAs <long>("InvoiceNumber", out var invoiceNumber);

            // Equals to TransactionCode in Parbad system.
            httpRequest.TryGetParam("ReferenceId", out var referenceId);

            var isSucceed = false;
            PaymentVerifyResult verifyResult = null;

            if (merchantId != account.MerchantId ||
                invoiceNumber != context.Payment.TrackingNumber ||
                token.IsNullOrEmpty())
            {
                verifyResult = new PaymentVerifyResult
                {
                    TrackingNumber  = invoiceNumber,
                    TransactionCode = referenceId,
                    IsSucceed       = false,
                    Message         = messagesOptions.InvalidDataReceivedFromGateway
                };
            }
            else
            {
                var translatedMessage = IranKishGatewayResultTranslator.Translate(resultCode, messagesOptions);

                isSucceed = resultCode == OkResult;

                if (!isSucceed)
                {
                    verifyResult = new PaymentVerifyResult
                    {
                        TrackingNumber  = invoiceNumber,
                        TransactionCode = referenceId,
                        IsSucceed       = false,
                        Message         = translatedMessage
                    };
                }
            }

            return(new IranKishCallbackResult
            {
                IsSucceed = isSucceed,
                Token = token,
                InvoiceNumber = invoiceNumber,
                ReferenceId = referenceId,
                Result = verifyResult
            });
        }
Esempio n. 20
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));
        }
Esempio n. 21
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));
        }
Esempio n. 22
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
            });
        }
Esempio n. 23
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));
        }
Esempio n. 24
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));
        }
Esempio n. 25
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));
        }
Esempio n. 26
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
            });
        }
Esempio n. 27
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));
        }
Esempio n. 28
0
        public static PaymentVerifyResult ToPaymentVerifyResult(this MellatVerifyPaymentResult input)
        {
            input.CheckArgumentIsNull(nameof(input));

            var result = new PaymentVerifyResult();

            if (input.Success)
            {
                result.Status = PaymentVerifiyStatus.Succeeded;
            }

            if (input.Message.IsNotNull())
            {
                result.Message = input.Message;
            }

            return(result);
        }
Esempio n. 29
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
            });
        }
Esempio n. 30
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
            });
        }