Example #1
0
        public static async Task <IPaymentFetchResult> CreateFetchResult(HttpRequest httpRequest, InvoiceContext invoiceContext, MessagesOptions messagesOptions, CancellationToken cancellationToken)
        {
            var trackId = await httpRequest.TryGetParamAsync("trackId", cancellationToken).ConfigureAwaitFalse();

            var status = await httpRequest.TryGetParamAsAsync <int>("status", cancellationToken).ConfigureAwaitFalse();

            var trackIdInDatabase = GetTrackId(invoiceContext.Transactions);

            var isSucceed = status.Exists && status.Value == SuccessCode &&
                            trackId.Exists && trackId.Value == trackIdInDatabase;

            string?message;

            if (isSucceed)
            {
                message = messagesOptions.PaymentSucceed;
            }
            else
            {
                message = ZibalTranslator.TranslateStatus(status.Value) ?? messagesOptions.PaymentFailed;
            }

            return(new PaymentFetchResult
            {
                Status = isSucceed ? PaymentFetchResultStatus.ReadyForVerifying : PaymentFetchResultStatus.Failed,
                GatewayResponseCode = status.Value.ToString(),
                Message = message,
            });
        }
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));
        }