Ejemplo n.º 1
0
        public static object CreateRequestData(Invoice invoice, MelliGatewayAccount account, IMelliGatewayCrypto crypto)
        {
            var data = $"{account.TerminalId};{invoice.TrackingNumber};{(long)invoice.Amount}";

            var signedData = crypto.Encrypt(account.TerminalKey, data);

            return(CreateRequestObject(
                       account.TerminalId,
                       account.MerchantId,
                       invoice.Amount,
                       signedData,
                       invoice.CallbackUrl,
                       invoice.TrackingNumber));
        }
Ejemplo n.º 2
0
        public static async Task <MelliCallbackResult> CreateCallbackResultAsync(
            InvoiceContext context,
            HttpRequest httpRequest,
            MelliGatewayAccount account,
            IMelliGatewayCrypto crypto,
            MessagesOptions messagesOptions,
            CancellationToken cancellationToken)
        {
            var apiResponseCode = await httpRequest.TryGetParamAsAsync <int>("ResCode", cancellationToken).ConfigureAwaitFalse();

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

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

            var apiOrderId = await httpRequest.TryGetParamAsAsync <long>("OrderId", cancellationToken).ConfigureAwaitFalse();

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

            var signedData = crypto.Encrypt(account.TerminalKey, apiToken.Value);

            var dataToVerify = CreateVerifyObject(apiToken.Value, signedData);

            return(new MelliCallbackResult
            {
                IsSucceed = true,
                Token = apiToken.Value,
                JsonDataToVerify = dataToVerify
            });
        }