Exemplo n.º 1
0
        public static object CreateRequestData(Invoice invoice, MelliGatewayAccount account)
        {
            var signedData = SignRequestData(account.TerminalId, account.TerminalKey, invoice.TrackingNumber, invoice.Amount);

            return(CreateRequestObject(
                       account.TerminalId,
                       account.MerchantId,
                       invoice.Amount,
                       signedData,
                       invoice.CallbackUrl,
                       invoice.TrackingNumber));
        }
Exemplo n.º 2
0
        public static MelliCallbackResult CreateCallbackResult(VerifyContext context, HttpRequest httpRequest, MelliGatewayAccount account, MessagesOptions messagesOptions)
        {
            httpRequest.TryGetParamAs <int>("ResCode", out var apiResponseCode);

            if (apiResponseCode != SuccessCode)
            {
                return(new MelliCallbackResult
                {
                    IsSucceed = false,
                    Result = PaymentVerifyResult.Failed(messagesOptions.PaymentFailed)
                });
            }

            httpRequest.TryGetParam("Token", out var apiToken);
            httpRequest.TryGetParamAs <long>("OrderId", out var apiOrderId);

            if (apiOrderId != context.Payment.TrackingNumber)
            {
                return(new MelliCallbackResult
                {
                    IsSucceed = false,
                    Token = apiToken,
                    Result = PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway)
                });
            }

            var signedData = SignVerifyData(account.TerminalKey, apiToken);

            var dataToVerify = CreateVerifyObject(apiToken, signedData);

            return(new MelliCallbackResult
            {
                IsSucceed = true,
                Token = apiToken,
                JsonDataToVerify = dataToVerify
            });
        }
Exemplo n.º 3
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));
            }

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

            return(PaymentRequestResult.Succeed(new GatewayRedirect(httpContextAccessor, paymentPageUrl), account.Name));
        }