Exemplo n.º 1
0
        public static PaymentVerifyResult CreateVerifyResult(
            string webServiceResponse,
            InvoiceContext context,
            IranKishCallbackResult callbackResult,
            MessagesOptions messagesOptions)
        {
            var result = XmlHelper.GetNodeValueFromXml(webServiceResponse, "KicccPaymentsVerificationResult", "http://tempuri.org/");

            // The result object is actually the amount of invoice . It must equal to invoice's amount.
            if (!long.TryParse(result, out var numericResult))
            {
                return(new PaymentVerifyResult
                {
                    TrackingNumber = callbackResult.InvoiceNumber,
                    TransactionCode = callbackResult.ReferenceId,
                    Status = PaymentVerifyResultStatus.Failed,
                    Message = $"{messagesOptions.InvalidDataReceivedFromGateway} Result: {result}"
                });
            }

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

            var translatedMessage = isSuccess
                ? messagesOptions.PaymentSucceed
                : IranKishGatewayResultTranslator.Translate(result, messagesOptions);

            return(new PaymentVerifyResult
            {
                TrackingNumber = callbackResult.InvoiceNumber,
                TransactionCode = callbackResult.ReferenceId,
                Status = isSuccess ? PaymentVerifyResultStatus.Succeed : PaymentVerifyResultStatus.Failed,
                Message = translatedMessage
            });
        }
Exemplo n.º 2
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
            });
        }
Exemplo n.º 3
0
        public static async Task <IranKishCallbackResult> CreateCallbackResultAsync(InvoiceContext context,
                                                                                    IranKishGatewayAccount account,
                                                                                    HttpRequest httpRequest,
                                                                                    MessagesOptions messagesOptions,
                                                                                    CancellationToken cancellationToken)
        {
            var resultCode = await httpRequest.TryGetParamAsync("ResultCode", cancellationToken).ConfigureAwaitFalse();

            var token = await httpRequest.TryGetParamAsync("Token", cancellationToken).ConfigureAwaitFalse();

            var merchantId = await httpRequest.TryGetParamAsync("MerchantId", cancellationToken).ConfigureAwaitFalse();

            // Equals to TrackingNumber in Parbad system.
            var invoiceNumber = await httpRequest.TryGetParamAsAsync <long>("InvoiceNumber", cancellationToken).ConfigureAwaitFalse();

            // Equals to TransactionCode in Parbad system.
            var referenceId = await httpRequest.TryGetParamAsync("ReferenceId", cancellationToken).ConfigureAwaitFalse();

            var isSucceed = true;
            var message   = messagesOptions.InvalidDataReceivedFromGateway;
            PaymentVerifyResult verifyResult = null;

            if (!resultCode.Exists)
            {
                isSucceed = false;
                message  += "No ResultCode is received.";
            }

            if (!merchantId.Exists)
            {
                isSucceed = false;
                message  += " No MerchantId is received.";
            }
            else if (merchantId.Value != account.MerchantId)
            {
                isSucceed = false;
                message  += "MerchantId is not valid.";
            }

            if (!invoiceNumber.Exists)
            {
                isSucceed = false;
                message  += "No InvoiceNumber is received.";
            }
            else if (invoiceNumber.Value != context.Payment.TrackingNumber)
            {
                isSucceed = false;
                message  += "InvoiceNumber is not valid.";
            }

            if (!token.Exists || token.Value.IsNullOrEmpty())
            {
                isSucceed = false;
                message  += "No Token is received or it was null.";
            }

            if (!isSucceed)
            {
                verifyResult = new PaymentVerifyResult
                {
                    TrackingNumber  = invoiceNumber.Value,
                    TransactionCode = referenceId.Value,
                    Status          = PaymentVerifyResultStatus.Failed,
                    Message         = message
                };
            }
            else
            {
                isSucceed = resultCode.Value == OkResult;

                var translatedMessage = IranKishGatewayResultTranslator.Translate(resultCode.Value, messagesOptions);

                if (!isSucceed)
                {
                    verifyResult = new PaymentVerifyResult
                    {
                        TrackingNumber  = invoiceNumber.Value,
                        TransactionCode = referenceId.Value,
                        Status          = PaymentVerifyResultStatus.Failed,
                        Message         = translatedMessage
                    };
                }
            }

            return(new IranKishCallbackResult
            {
                IsSucceed = isSucceed,
                Token = token.Value,
                InvoiceNumber = invoiceNumber.Value,
                ReferenceId = referenceId.Value,
                Result = verifyResult
            });
        }