Example #1
0
        public static PaymentRequestResult CreateRequestResult(MelliApiRequestResult result, IHttpContextAccessor httpContextAccessor, MelliGatewayAccount account, MessagesOptions messagesOptions)
        {
            if (result == null)
            {
                return(PaymentRequestResult.Failed(messagesOptions.UnexpectedErrorText));
            }

            var isSucceed = result.ResCode == SuccessCode;

            if (!isSucceed)
            {
                string message;

                if (result.ResCode == DuplicateTrackingNumberCode)
                {
                    message = messagesOptions.DuplicateTrackingNumber;
                }
                else
                {
                    message = !result.Description.IsNullOrEmpty()
                        ? result.Description
                        : MelliRequestResultTranslator.Translate(result.ResCode, messagesOptions);
                }

                return(PaymentRequestResult.Failed(message, account.Name));
            }

            var paymentPageUrl = $"{PaymentPageUrl}/Index?token={result.Token}";

            return(PaymentRequestResult.Succeed(new GatewayRedirect(httpContextAccessor, paymentPageUrl), account.Name));
        }
Example #2
0
        public static PaymentRequestResult CreateRequestResult(
            string response,
            Invoice invoice,
            AsanPardakhtGatewayAccount account,
            IHttpContextAccessor httpContextAccessor,
            MessagesOptions messagesOptions)
        {
            var result = XmlHelper.GetNodeValueFromXml(response, "RequestOperationResult", "http://tempuri.org/");

            var splitedResult = result.Split(',');

            var    isSucceed = splitedResult.Length == 2 && splitedResult[0] == "0";
            string message   = null;

            if (!isSucceed)
            {
                message = AsanPardakhtResultTranslator.TranslateRequest(splitedResult[0], messagesOptions);

                return(PaymentRequestResult.Failed(message));
            }

            var transporter = new GatewayPost(
                httpContextAccessor,
                PaymentPageUrl,
                new Dictionary <string, string>
            {
                { "RefId", splitedResult[1] }
            });

            return(PaymentRequestResult.Succeed(transporter, account.Name));
        }
Example #3
0
        public static async Task <PaymentRequestResult> CreateRequestResult(
            HttpResponseMessage responseMessage,
            HttpContext httpContext,
            YekPayGatewayAccount account,
            YekPayGatewayOptions gatewayOptions,
            MessagesOptions optionsMessages)
        {
            var message = await responseMessage.Content.ReadAsStringAsync();

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

            if (response == null)
            {
                return(PaymentRequestResult.Failed(optionsMessages.InvalidDataReceivedFromGateway, account.Name));
            }

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

                return(PaymentRequestResult.Failed(failureMessage, account.Name));
            }

            var paymentPageUrl = gatewayOptions.PaymentPageUrl + response.Authority;

            var result = PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, paymentPageUrl);

            result.DatabaseAdditionalData.Add(AuthorityAdditionalDataKey, response.Authority);

            return(result);
        }
Example #4
0
        public static PaymentRequestResult CreateRequestResult(
            string webServiceResponse,
            HttpContext httpContext,
            MellatGatewayOptions gatewayOptions,
            MessagesOptions messagesOptions,
            GatewayAccount account)
        {
            var result = XmlHelper.GetNodeValueFromXml(webServiceResponse, "return");

            var arrayResult = result.Split(',');

            var resCode = arrayResult[0];
            var refId   = arrayResult.Length > 1 ? arrayResult[1] : string.Empty;

            var isSucceed = resCode == OkResult;

            if (!isSucceed)
            {
                var message = resCode == DuplicateOrderNumberResult
                    ? messagesOptions.DuplicateTrackingNumber
                    : MellatGatewayResultTranslator.Translate(resCode, messagesOptions);

                return(PaymentRequestResult.Failed(message, account.Name));
            }

            return(PaymentRequestResult.SucceedWithPost(
                       account.Name,
                       httpContext,
                       gatewayOptions.PaymentPageUrl,
                       new Dictionary <string, string>
            {
                { "RefId", refId }
            }));
        }
Example #5
0
        public static async Task <PaymentRequestResult> CreateRequestResult(
            HttpResponseMessage responseMessage,
            HttpContext httpContext,
            ZibalGatewayAccount account,
            ZibalGatewayOptions gatewayOptions,
            MessagesOptions messagesOptions)
        {
            var message = await responseMessage.Content.ReadAsStringAsync();

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

            if (response == null)
            {
                return(PaymentRequestResult.Failed(messagesOptions.InvalidDataReceivedFromGateway, account.Name));
            }

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

                return(PaymentRequestResult.Failed(failureMessage, account.Name, response.Result.ToString()));
            }

            var paymentPageUrl = string.IsNullOrEmpty(response.PayLink)
                                ? GetPaymentPageUrl(gatewayOptions.PaymentPageUrl, response.TrackId)
                                : response.PayLink;

            var result = PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, paymentPageUrl);

            result.DatabaseAdditionalData.Add(TrackIdAdditionalDataKey, response.TrackId.ToString());

            return(result);
        }
Example #6
0
        public static PaymentRequestResult CreateRequestResult(string webServiceResponse, IHttpContextAccessor httpContextAccessor, MessagesOptions messagesOptions)
        {
            var result = XmlHelper.GetNodeValueFromXml(webServiceResponse, "return");

            var arrayResult = result.Split(',');

            var resCode = arrayResult[0];
            var refId   = arrayResult.Length > 1 ? arrayResult[1] : string.Empty;

            var isSucceed = resCode == OkResult;

            if (!isSucceed)
            {
                var message = resCode == DuplicateOrderNumberResult
                    ? messagesOptions.DuplicateTrackingNumber
                    : MellatGatewayResultTranslator.Translate(resCode, messagesOptions);

                return(PaymentRequestResult.Failed(message));
            }

            var transporter = new GatewayPost(
                httpContextAccessor,
                PaymentPageUrl,
                new Dictionary <string, string>
            {
                { "RefId", refId }
            });

            return(PaymentRequestResult.Succeed(transporter));
        }
        public static PaymentRequestResult CreateRequestResult(
            string response,
            AsanPardakhtGatewayAccount account,
            HttpContext httpContext,
            AsanPardakhtGatewayOptions gatewayOptions,
            MessagesOptions messagesOptions)
        {
            var result = XmlHelper.GetNodeValueFromXml(response, "RequestOperationResult", "http://tempuri.org/");

            var splitedResult = result.Split(',');

            var isSucceed = splitedResult.Length == 2 && splitedResult[0] == "0";

            if (!isSucceed)
            {
                var message = AsanPardakhtResultTranslator.TranslateRequest(splitedResult[0], messagesOptions);

                return(PaymentRequestResult.Failed(message, account.Name));
            }

            return(PaymentRequestResult.SucceedWithPost(
                       account.Name,
                       httpContext,
                       gatewayOptions.PaymentPageUrl,
                       new Dictionary <string, string>
            {
                { "RefId", splitedResult[1] }
            }));
        }
Example #8
0
        public static PaymentRequestResult CreateRequestResult(string response,
                                                               HttpContext httpContext,
                                                               ZarinPalGatewayAccount account,
                                                               MessagesOptions messagesOptions)
        {
            var status    = XmlHelper.GetNodeValueFromXml(response, "Status", "http://zarinpal.com/");
            var authority = XmlHelper.GetNodeValueFromXml(response, "Authority", "http://zarinpal.com/");

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

            if (!isSucceed)
            {
                var message = ZarinPalStatusTranslator.Translate(status, messagesOptions);

                return(PaymentRequestResult.Failed(message, account.Name));
            }

            var paymentPageUrl = GetWebPageUrl(account.IsSandbox) + authority;

            var transporterDescriptor = GatewayTransporterDescriptor.CreateRedirect(paymentPageUrl);

            var transporter = new DefaultGatewayTransporter(httpContext, transporterDescriptor);

            return(PaymentRequestResult.Succeed(transporter, account.Name));
        }
Example #9
0
        public static PaymentRequestResult CreateRequestResult(string webServiceResponse, IHttpContextAccessor httpContextAccessor, MessagesOptions messagesOptions)
        {
            var token   = XmlHelper.GetNodeValueFromXml(webServiceResponse, "Token", "https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService");
            var status  = XmlHelper.GetNodeValueFromXml(webServiceResponse, "Status", "https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService");
            var message = XmlHelper.GetNodeValueFromXml(webServiceResponse, "Message", "https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService");

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

            if (!isSucceed)
            {
                if (message == null)
                {
                    message = messagesOptions.PaymentFailed;
                }

                return(PaymentRequestResult.Failed(message));
            }

            var paymentPageUrl = $"{PaymentPageUrl}?Token={token}";

            var result = new PaymentRequestResult
            {
                IsSucceed          = true,
                GatewayTransporter = new GatewayRedirect(httpContextAccessor, paymentPageUrl)
            };

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

            return(result);
        }
Example #10
0
        public static PaymentRequestResult CreateRequestResult(
            string webServiceResponse,
            HttpContext httpContext,
            ParsianGatewayAccount account,
            ParsianGatewayOptions gatewayOptions,
            MessagesOptions messagesOptions)
        {
            var token   = XmlHelper.GetNodeValueFromXml(webServiceResponse, "Token", "https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService");
            var status  = XmlHelper.GetNodeValueFromXml(webServiceResponse, "Status", "https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService");
            var message = XmlHelper.GetNodeValueFromXml(webServiceResponse, "Message", "https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService");

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

            if (!isSucceed)
            {
                if (message == null)
                {
                    message = messagesOptions.PaymentFailed;
                }

                return(PaymentRequestResult.Failed(message, account.Name));
            }

            var paymentPageUrl = $"{gatewayOptions.PaymentPageUrl}?Token={token}";

            var result = PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, paymentPageUrl);

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

            return(result);
        }
Example #11
0
        public static PaymentRequestResult CreateRequestResult(
            string webServiceResponse,
            Invoice invoice,
            IranKishGatewayAccount account,
            HttpContext httpContext,
            MessagesOptions messagesOptions)
        {
            var result  = XmlHelper.GetNodeValueFromXml(webServiceResponse, "result", "http://schemas.datacontract.org/2004/07/Token");
            var message = XmlHelper.GetNodeValueFromXml(webServiceResponse, "message", "http://schemas.datacontract.org/2004/07/Token");
            var token   = XmlHelper.GetNodeValueFromXml(webServiceResponse, "token", "http://schemas.datacontract.org/2004/07/Token");

            var isSucceed = result.Equals("true", StringComparison.OrdinalIgnoreCase) && !token.IsNullOrEmpty();

            if (!isSucceed)
            {
                if (message.IsNullOrEmpty())
                {
                    message = messagesOptions.InvalidDataReceivedFromGateway;
                }

                return(PaymentRequestResult.Failed(message, account.Name));
            }

            var transporterDescriptor = GatewayTransporterDescriptor.CreatePost(
                PaymentPageUrl,
                new Dictionary <string, string>
            {
                { "merchantid", account.MerchantId },
                { "token", token }
            });

            var transporter = new DefaultGatewayTransporter(httpContext, transporterDescriptor);

            return(PaymentRequestResult.Succeed(transporter, account.Name));
        }
Example #12
0
        public static PaymentRequestResult CreateRequestResult(string response, IHttpContextAccessor httpContextAccessor, PayIrGatewayAccount account)
        {
            var result = JsonConvert.DeserializeObject <PayIrRequestResponseModel>(response);

            if (!result.IsSucceed)
            {
                return(PaymentRequestResult.Failed(result.ErrorMessage, account.Name));
            }

            var paymentPageUrl = $"{PaymentPageUrl}{result.Token}";

            return(PaymentRequestResult.Succeed(new GatewayRedirect(httpContextAccessor, paymentPageUrl), account.Name));
        }
Example #13
0
        public static PaymentRequestResult CreateRequestResult(string response, HttpContext httpContext, PayIrGatewayAccount account, PayIrGatewayOptions gatewayOptions)
        {
            var result = JsonConvert.DeserializeObject <PayIrRequestResponseModel>(response);

            if (!result.IsSucceed)
            {
                return(PaymentRequestResult.Failed(result.ErrorMessage, account.Name));
            }

            var paymentPageUrl = $"{gatewayOptions.PaymentPageUrl}{result.Token}";

            return(PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, paymentPageUrl));
        }
Example #14
0
        private static async Task <PaymentRequestResult> CreateMobilePaymentRequest(
            Invoice invoice,
            HttpContext httpContext,
            SamanGatewayAccount account,
            HttpClient httpClient,
            SamanGatewayOptions gatewayOptions,
            MessagesOptions messagesOptions,
            CancellationToken cancellationToken)
        {
            var data = new SamanMobilePaymentTokenRequest
            {
                TerminalId  = account.MerchantId,
                ResNum      = invoice.TrackingNumber.ToString(),
                Amount      = invoice.Amount,
                RedirectUrl = invoice.CallbackUrl,
                Action      = "Token"
            };

            var responseMessage = await httpClient.PostJsonAsync(gatewayOptions.MobileApiTokenUrl, data, cancellationToken);

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

            var tokenResponse = JsonConvert.DeserializeObject <SamanMobilePaymentTokenResponse>(response);

            if (tokenResponse == null)
            {
                var message = $"{messagesOptions.InvalidDataReceivedFromGateway} Serialized token response is null.";
                return(PaymentRequestResult.Failed(message, account.Name));
            }

            if (tokenResponse.Status == -1)
            {
                return(PaymentRequestResult.Failed(tokenResponse.GetError(), account.Name));
            }

            var result = PaymentRequestResult.SucceedWithPost(
                account.Name,
                httpContext,
                gatewayOptions.MobilePaymentPageUrl,
                new Dictionary <string, string>
            {
                { "Token", tokenResponse.Token }
            });

            result.DatabaseAdditionalData.Add(MobileGatewayKey, true.ToString());

            return(result);
        }
Example #15
0
        public static PaymentRequestResult CreateRequestResult(string response, HttpContext httpContext, PayIrGatewayAccount account)
        {
            var result = JsonConvert.DeserializeObject <PayIrRequestResponseModel>(response);

            if (!result.IsSucceed)
            {
                return(PaymentRequestResult.Failed(result.ErrorMessage, account.Name));
            }

            var paymentPageUrl = $"{PaymentPageUrl}{result.Token}";

            var transporterDescriptor = GatewayTransporterDescriptor.CreateRedirect(paymentPageUrl);

            var transporter = new DefaultGatewayTransporter(httpContext, transporterDescriptor);

            return(PaymentRequestResult.Succeed(transporter, account.Name));
        }
Example #16
0
        private static async Task <PaymentRequestResult> CreateWebPaymentRequest(
            Invoice invoice,
            HttpContext httpContext,
            SamanGatewayAccount account,
            HttpClient httpClient,
            SamanGatewayOptions gatewayOptions,
            MessagesOptions messagesOptions,
            CancellationToken cancellationToken)
        {
            var data = CreateTokenRequest(invoice, account);

            var responseMessage = await httpClient.PostXmlAsync(gatewayOptions.WebApiTokenUrl, data, cancellationToken);

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

            var token = XmlHelper.GetNodeValueFromXml(response, "result");

            string message   = null;
            var    isSucceed = true;

            if (token.IsNullOrEmpty())
            {
                message   = $"{messagesOptions.InvalidDataReceivedFromGateway} Token is null or empty.";
                isSucceed = false;
            }
            else if (long.TryParse(token, out var longToken) && longToken < 0)
            {
                message   = SamanResultTranslator.Translate(longToken, messagesOptions);
                isSucceed = false;
            }

            if (!isSucceed)
            {
                return(PaymentRequestResult.Failed(message, account.Name));
            }

            return(PaymentRequestResult.SucceedWithPost(
                       account.Name,
                       httpContext,
                       gatewayOptions.WebPaymentPageUrl,
                       new Dictionary <string, string>
            {
                { "Token", token },
                { "RedirectURL", invoice.CallbackUrl }
            }));
        }
Example #17
0
        public static async Task <PaymentRequestResult> CreateRequestResult(
            HttpResponseMessage responseMessage,
            IHttpContextAccessor httpContextAccessor,
            IdPayGatewayAccount account)
        {
            var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse();

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

                return(PaymentRequestResult.Failed(errorModel.ToString(), account.Name));
            }

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

            return(PaymentRequestResult.Succeed(new GatewayRedirect(httpContextAccessor, result.Link), account.Name));
        }
Example #18
0
        public static PaymentRequestResult CreateRequestResult(
            string webServiceResponse,
            Invoice invoice,
            HttpContext httpContext,
            MellatGatewayOptions gatewayOptions,
            MessagesOptions messagesOptions,
            GatewayAccount account)
        {
            var result = XmlHelper.GetNodeValueFromXml(webServiceResponse, "return");

            var arrayResult = result.Split(',');

            var resCode = arrayResult[0];
            var refId   = arrayResult.Length > 1 ? arrayResult[1] : string.Empty;

            var isSucceed = resCode == OkResult;

            if (!isSucceed)
            {
                var message = resCode == DuplicateOrderNumberResult
                    ? messagesOptions.DuplicateTrackingNumber
                    : MellatGatewayResultTranslator.Translate(resCode, messagesOptions);

                return(PaymentRequestResult.Failed(message, account.Name));
            }

            var form = new Dictionary <string, string>
            {
                { "RefId", refId }
            };

            var additionalData = invoice.GetMellatAdditionalData();

            if (!string.IsNullOrWhiteSpace(additionalData?.MobileNumber))
            {
                form.Add("MobileNo", additionalData.MobileNumber);
            }

            return(PaymentRequestResult.SucceedWithPost(
                       account.Name,
                       httpContext,
                       gatewayOptions.PaymentPageUrl,
                       form));
        }
Example #19
0
        public static async Task <PaymentRequestResult> CreateRequestResult(
            HttpResponseMessage responseMessage,
            HttpContext httpContext,
            SepehrGatewayAccount account,
            MessagesOptions messages)
        {
            if (!responseMessage.IsSuccessStatusCode)
            {
                return(PaymentRequestResult.Failed($"Operation failed. Http Status: {responseMessage.StatusCode}", account.Name));
            }

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

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

            if (result == null)
            {
                return(PaymentRequestResult.Failed(messages.InvalidDataReceivedFromGateway, account.Name));
            }

            if (result.Status != 0)
            {
                var message = SepehrGatewayResultTranslator.Translate(result.Status.ToString(), messages);

                return(PaymentRequestResult.Failed(message, account.Name));
            }

            if (result.AccessToken.IsNullOrWhiteSpace())
            {
                return(PaymentRequestResult.Failed(messages.InvalidDataReceivedFromGateway, account.Name));
            }

            var transporterDescriptor = GatewayTransporterDescriptor.CreatePost(
                PaymentPageUrl,
                new Dictionary <string, string>
            {
                { "TerminalID", account.TerminalId.ToString() },
                { "token", result.AccessToken }
            });

            var transporter = new DefaultGatewayTransporter(httpContext, transporterDescriptor);

            return(PaymentRequestResult.Succeed(transporter, account.Name));
        }
Example #20
0
        internal static async Task <PaymentRequestResult> CreateRequestResult(
            HttpResponseMessage responseMessage,
            HttpContext httpContext,
            FanAvaGatewayAccount account,
            FanAvaGatewayOptions gatewayOptions)
        {
            var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse();

            if (!responseMessage.IsSuccessStatusCode)
            {
                return(PaymentRequestResult.Failed(response.ToString(), account.Name));
            }

            var result = JsonSerializer.Deserialize <FanAvaRequestResultModel>(response);
            var url    = QueryHelpers.AddQueryString(gatewayOptions.PaymentPageUrl, new Dictionary <string, string> {
                { "token", result.Token },
                { "lang", "fa" }
            });

            return(PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, url));
        }
Example #21
0
        public static PaymentRequestResult CreateRequestResult(
            string response,
            IHttpContextAccessor httpContextAccessor,
            ZarinPalGatewayAccount account)
        {
            var status    = XmlHelper.GetNodeValueFromXml(response, "Status", "http://zarinpal.com/");
            var authority = XmlHelper.GetNodeValueFromXml(response, "Authority", "http://zarinpal.com/");

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

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

                return(PaymentRequestResult.Failed(message, account.Name));
            }

            var paymentPageUrl = GetWebPageUrl(account.IsSandbox) + authority;

            return(PaymentRequestResult.Succeed(new GatewayRedirect(httpContextAccessor, paymentPageUrl), account.Name));
        }
Example #22
0
        public static async Task <PaymentRequestResult> CreateRequestResult(
            HttpResponseMessage responseMessage,
            HttpContext httpContext,
            IdPayGatewayAccount account)
        {
            var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse();

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

                return(PaymentRequestResult.Failed(errorModel.ToString(), account.Name));
            }

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

            var transporterDescriptor = GatewayTransporterDescriptor.CreateRedirect(result.Link);

            var transporter = new DefaultGatewayTransporter(httpContext, transporterDescriptor);

            return(PaymentRequestResult.Succeed(transporter, account.Name));
        }
Example #23
0
        public async Task <PaymentRequestResult> InitiatePartnerPaymentAsync(IPaymentRequest paymentRequest)
        {
            #region Validation

            if (string.IsNullOrEmpty(paymentRequest.CustomerId))
            {
                throw new ArgumentNullException(nameof(paymentRequest.CustomerId));
            }

            if (string.IsNullOrEmpty(paymentRequest.PartnerId))
            {
                throw new ArgumentNullException(nameof(paymentRequest.PartnerId));
            }

            if (string.IsNullOrEmpty(paymentRequest.Currency))
            {
                throw new ArgumentNullException(nameof(paymentRequest.Currency));
            }

            var isPartnerIdValidGuid = Guid.TryParse(paymentRequest.PartnerId, out var partnerId);

            if (!isPartnerIdValidGuid)
            {
                return(PaymentRequestResult.Failed(PaymentRequestErrorCodes.PartnerIdIsNotAValidGuid));
            }

            var isCustomerIdValidGuid = Guid.TryParse(paymentRequest.CustomerId, out var customerGuid);

            if (!isCustomerIdValidGuid)
            {
                return(PaymentRequestResult.Failed(PaymentRequestErrorCodes.CustomerIdIsNotAValidGuid));
            }

            //We can have either amount in Tokens or in Fiat
            if (paymentRequest.FiatAmount != null && paymentRequest.TokensAmount != null)
            {
                return(PaymentRequestResult.Failed(PaymentRequestErrorCodes.CannotPassBothFiatAndTokensAmount));
            }

            //Fiat or Tokens Amount must be provided
            if (paymentRequest.FiatAmount == null && paymentRequest.TokensAmount == null)
            {
                return(PaymentRequestResult.Failed(PaymentRequestErrorCodes.EitherFiatOrTokensAmountShouldBePassed));
            }

            if (paymentRequest.TokensAmount != null && paymentRequest.TokensAmount <= 0)
            {
                return(PaymentRequestResult.Failed(PaymentRequestErrorCodes.InvalidTokensAmount));
            }

            if (paymentRequest.FiatAmount != null && paymentRequest.FiatAmount <= 0)
            {
                return(PaymentRequestResult.Failed(PaymentRequestErrorCodes.InvalidFiatAmount));
            }

            if (paymentRequest.TotalBillAmount <= 0)
            {
                return(PaymentRequestResult.Failed(PaymentRequestErrorCodes.InvalidTotalBillAmount));
            }

            var customerProfile = await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(paymentRequest.CustomerId);

            if (customerProfile.ErrorCode == CustomerProfileErrorCodes.CustomerProfileDoesNotExist)
            {
                return(PaymentRequestResult.Failed(PaymentRequestErrorCodes.CustomerDoesNotExist));
            }

            var customerWalletStatus =
                await _walletManagementClient.Api.GetCustomerWalletBlockStateAsync(paymentRequest.CustomerId);

            if (customerWalletStatus.Status == CustomerWalletActivityStatus.Blocked)
            {
                return(PaymentRequestResult.Failed(PaymentRequestErrorCodes.CustomerWalletBlocked));
            }

            var partnerDetails = await _partnerManagementClient.Partners.GetByIdAsync(partnerId);

            if (partnerDetails == null)
            {
                return(PaymentRequestResult.Failed(PaymentRequestErrorCodes.PartnerDoesNotExist));
            }

            if (!string.IsNullOrEmpty(paymentRequest.LocationId))
            {
                if (partnerDetails.Locations.All(x => x.Id.ToString() != paymentRequest.LocationId))
                {
                    return(PaymentRequestResult.Failed(PaymentRequestErrorCodes.NoSuchLocationForThisPartner));
                }
            }

            #endregion

            var paymentRequestId = Guid.NewGuid().ToString();

            paymentRequest.PaymentRequestId = paymentRequestId;

            //Blockchain does not accept null
            if (paymentRequest.LocationId == null)
            {
                paymentRequest.LocationId = "";
            }

            var convertOptimalByPartnerModel = new ConvertOptimalByPartnerRequest
            {
                CustomerId   = customerGuid,
                PartnerId    = partnerId,
                Amount       = paymentRequest.TokensAmount ?? paymentRequest.FiatAmount.Value,
                FromCurrency = paymentRequest.TokensAmount.HasValue ? _tokenSymbol : paymentRequest.Currency,
                ToCurrency   = paymentRequest.TokensAmount.HasValue ? paymentRequest.Currency : _tokenSymbol
            };

            var convertOptimalByPartnerResponse =
                await _eligibilityEngineClient.ConversionRate.ConvertOptimalByPartnerAsync(convertOptimalByPartnerModel);

            if (convertOptimalByPartnerResponse.ErrorCode != EligibilityEngineErrors.None)
            {
                if (convertOptimalByPartnerResponse.ErrorCode == EligibilityEngineErrors.PartnerNotFound)
                {
                    return(PaymentRequestResult.Failed(PaymentRequestErrorCodes.PartnerDoesNotExist));
                }
                if (convertOptimalByPartnerResponse.ErrorCode == EligibilityEngineErrors.ConversionRateNotFound)
                {
                    return(PaymentRequestResult.Failed(PaymentRequestErrorCodes.InvalidTokensOrCurrencyRateInPartner));
                }
            }

            paymentRequest.TokensToFiatConversionRate = convertOptimalByPartnerResponse.UsedRate;

            if (paymentRequest.FiatAmount == null)
            {
                paymentRequest.FiatAmount = (decimal)convertOptimalByPartnerResponse.Amount;
            }
            else
            {
                paymentRequest.TokensAmount = convertOptimalByPartnerResponse.Amount;
            }

            var now = DateTime.UtcNow;
            paymentRequest.CustomerActionExpirationTimestamp = paymentRequest.CustomerExpirationInSeconds.HasValue
                ? now.AddSeconds(paymentRequest.CustomerExpirationInSeconds.Value)
                : now.Add(_settingsService.GetRequestsExpirationPeriod());

            await _paymentsRepository.AddAsync(paymentRequest);

            await _paymentRequestCreatedPublisher.PublishAsync(new PartnerPaymentRequestCreatedEvent
            {
                PaymentRequestId = paymentRequestId,
                CustomerId       = paymentRequest.CustomerId,
                PartnerId        = paymentRequest.PartnerId,
                Timestamp        = DateTime.UtcNow
            });

            return(PaymentRequestResult.Succeeded(PaymentRequestStatus.Created, paymentRequestId));
        }