Example #1
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 #2
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));
        }