예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
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));
        }
예제 #5
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);

            return(PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, result.Link));
        }
예제 #6
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));
        }
예제 #7
0
        public static PaymentRequestResult CreateRequestResult(string response,
                                                               HttpContext httpContext,
                                                               ZarinPalGatewayAccount account,
                                                               ZarinPalGatewayOptions gatewayOptions,
                                                               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, gatewayOptions) + authority;

            return(PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, paymentPageUrl));
        }
예제 #8
0
        /// <inheritdoc />
        public override async Task <IPaymentRequestResult> RequestAsync(Invoice invoice, CancellationToken cancellationToken = default)
        {
            if (invoice == null)
            {
                throw new ArgumentNullException(nameof(invoice));
            }

            var account = await GetAccountAsync(invoice).ConfigureAwaitFalse();

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

            var body = new CreatePayRequestModel
            {
                Amount        = invoice.Amount,
                Description   = invoice.GetPayPingRequest()?.Description,
                PayerIdentity = invoice.GetPayPingRequest()?.Mobile,
                PayerName     = invoice.GetPayPingRequest()?.PayerName,
                ReturnUrl     = invoice.CallbackUrl,
                ClientRefId   = invoice.TrackingNumber.ToString()
            };

            //Send Create pay Request
            var response = await _httpClient.PostJsonAsync(_pingGatewayOptions.ApiRequestUrl, body, cancellationToken);

            //Check if we ran into an Issue
            response.EnsureSuccessStatusCode();

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

            //Convert Response data to Model and get PayCode
            var createPayResult = JsonConvert.DeserializeObject <CreatePayResponseModel>(responseBody);

            //Redirect User to gateway with the Code

            var url = _pingGatewayOptions.PaymentPageUrl.ToggleStringAtEnd("/", shouldHave: true) + createPayResult.Code;

            return(PaymentRequestResult.SucceedWithRedirect(account.Name, _httpContextAccessor.HttpContext, url));
        }
예제 #9
0
        public static PaymentRequestResult CreateRequestResult(
            MelliApiRequestResult result,
            HttpContext httpContext,
            MelliGatewayAccount account,
            MelliGatewayOptions gatewayOptions,
            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 = $"{gatewayOptions.PaymentPageUrl}/Index?token={result.Token}";

            return(PaymentRequestResult.SucceedWithRedirect(account.Name, httpContext, paymentPageUrl));
        }