Exemplo n.º 1
0
        public string VoidTransaction(GridMPGSConfig mpgsConfig)
        {
            GatewayApiConfig config = new GatewayApiConfig(mpgsConfig);

            GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(config)
            {
                ApiMethod           = "VOID",
                TargetTransactionId = "ea2d89bb24",
                TransactionId       = GenerateOrderId(),
                Token = "440003320900022"
            };

            gatewayApiRequest.buildRequestUrl();

            gatewayApiRequest.buildPayload();

            string request = JsonConvert.SerializeObject(gatewayApiRequest);

            LogInfo.Information(JsonConvert.SerializeObject(gatewayApiRequest));

            GatewayApiClient gatewayApiClient = new GatewayApiClient(config);

            string response = gatewayApiClient.executeHTTPMethod(gatewayApiRequest);

            LogInfo.Information(response);

            return(TokenResponse.GetResponseResult(response));
        }
Exemplo n.º 2
0
        public string  Capture(GridMPGSConfig mpgsConfig, TokenSession tokenSession)
        {
            GatewayApiConfig config = new GatewayApiConfig(mpgsConfig);

            GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(config)
            {
                OrderId             = tokenSession.MPGSOrderID,
                ApiOperation        = MPGSAPIOperation.CAPTURE.ToString(),
                TransactionAmount   = tokenSession.Amount.ToString(),
                TransactionId       = PaymentHelper.GenerateOrderId(),
                TransactionCurrency = config.Currency,
                Token      = tokenSession.Token,
                SourceType = tokenSession.SourceOfFundType
            };

            gatewayApiRequest.buildRequestUrl();

            gatewayApiRequest.buildPayload();

            string request = JsonConvert.SerializeObject(gatewayApiRequest);

            LogInfo.Information(JsonConvert.SerializeObject(gatewayApiRequest));

            GatewayApiClient gatewayApiClient = new GatewayApiClient(config);

            string response = gatewayApiClient.SendTransaction(gatewayApiRequest);

            LogInfo.Information(response);

            return(TokenResponse.GetResponseResult(response));
        }
Exemplo n.º 3
0
        public string CaptureTest(GridMPGSConfig mpgsConfig)
        {
            GatewayApiConfig config = new GatewayApiConfig(mpgsConfig);

            GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(config)
            {
                OrderId             = "77749b36d8", // authorized order id
                ApiOperation        = MPGSAPIOperation.CAPTURE.ToString(),
                TransactionAmount   = "20",
                TransactionId       = PaymentHelper.GenerateOrderId(),
                TransactionCurrency = config.Currency,
                Token      = "4440008087700014",
                SourceType = "CARD"
            };

            gatewayApiRequest.buildRequestUrl();

            gatewayApiRequest.buildPayload();

            string request = JsonConvert.SerializeObject(gatewayApiRequest);

            LogInfo.Information(JsonConvert.SerializeObject(gatewayApiRequest));

            GatewayApiClient gatewayApiClient = new GatewayApiClient(config);

            string response = gatewayApiClient.SendTransaction(gatewayApiRequest);

            LogInfo.Information(response);

            return(TokenResponse.GetResponseResult(response));
        }
Exemplo n.º 4
0
        public string AuthorizeTest(GridMPGSConfig mpgsConfig)
        {
            GatewayApiConfig config = new GatewayApiConfig(mpgsConfig);

            GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(config)
            {
                // SessionId = "" ,//checkOutDetails.CheckoutSession.Id,
                OrderId          = GenerateOrderId(), //checkOutDetails.OrderId,
                TransactionId    = GenerateOrderId(), //checkOutDetails.TransactionID,
                ApiOperation     = MPGSAPIOperation.AUTHORIZE.ToString(),
                OrderAmount      = "20",
                OrderCurrency    = config.Currency,
                ApiMethod        = "PUT",
                Token            = "4440008087700014",
                SourceType       = "CARD",
                OrderDescription = "test pay",
            };

            gatewayApiRequest.buildRequestUrl();

            gatewayApiRequest.buildPayload();

            string request = JsonConvert.SerializeObject(gatewayApiRequest);

            LogInfo.Information(JsonConvert.SerializeObject(gatewayApiRequest));

            GatewayApiClient gatewayApiClient = new GatewayApiClient(config);

            string response = gatewayApiClient.SendTransaction(gatewayApiRequest);

            LogInfo.Information(response);

            return(TokenResponse.GetResponseResult(response));
        }
Exemplo n.º 5
0
        public string  Authorize(GridMPGSConfig mpgsConfig, Checkout checkOutDetails, PaymentMethod paymentMethod)
        {
            GatewayApiConfig config = new GatewayApiConfig(mpgsConfig);

            GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(config, checkOutDetails.ReceiptNumber, checkOutDetails.OrderNumber)
            {
                SessionId        = checkOutDetails.CheckoutSession.Id,
                OrderId          = checkOutDetails.OrderId,
                TransactionId    = checkOutDetails.TransactionID,
                ApiOperation     = MPGSAPIOperation.AUTHORIZE.ToString(),
                OrderAmount      = checkOutDetails.Amount.ToString(),
                OrderCurrency    = config.Currency,
                ApiMethod        = "PUT",
                Token            = paymentMethod.Token,
                SourceType       = paymentMethod.SourceType,
                OrderDescription = "",
            };

            gatewayApiRequest.buildRequestUrl();

            gatewayApiRequest.buildPayload();

            string request = JsonConvert.SerializeObject(gatewayApiRequest);

            LogInfo.Information(JsonConvert.SerializeObject(gatewayApiRequest));

            GatewayApiClient gatewayApiClient = new GatewayApiClient(config);

            string response = gatewayApiClient.SendTransaction(gatewayApiRequest);

            LogInfo.Information(response);

            return(TokenResponse.GetResponseResult(response));
        }
Exemplo n.º 6
0
        public string PayWithToken(GridMPGSConfig mpgsConfig, string token, string sessionID, string orderID, string transactionID, string amount)
        {
            try
            {
                //payment with token

                GatewayApiConfig config = new GatewayApiConfig(mpgsConfig);

                GatewayApiRequest gatewayGeneratePaymentRequest = new GatewayApiRequest(config);

                gatewayGeneratePaymentRequest.ApiOperation = "PAY";

                gatewayGeneratePaymentRequest.ApiMethod = GatewayApiClient.PUT;

                gatewayGeneratePaymentRequest.Token = token;                 //tokenResponse.Token;

                gatewayGeneratePaymentRequest.SessionId = sessionID;         // responseUpdate.MPGSResponse.session.id;

                gatewayGeneratePaymentRequest.OrderId = orderID;             //updateTokenSesisonDetails.MPGSOrderID;

                gatewayGeneratePaymentRequest.TransactionId = transactionID; // updateTokenSesisonDetails.TransactionID;

                gatewayGeneratePaymentRequest.OrderAmount = amount;

                gatewayGeneratePaymentRequest.buildPayload();

                gatewayGeneratePaymentRequest.buildRequestUrl();

                //payment response
                GatewayApiClient gatewayApiClient = new GatewayApiClient(config);

                string response = gatewayApiClient.SendTransaction(gatewayGeneratePaymentRequest);

                LogInfo.Information($" {EnumExtensions.GetDescription(MPGSAPIResponse.HostedCheckoutRetrieveReceipt) + " " + response}");

                return(TokenResponse.GetResponseResult(response));
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                throw ex;
            }
        }
Exemplo n.º 7
0
        public static GatewayApiRequest CreateTokenizationApiRequest(GatewayApiConfig gatewayApiConfig, string apiOperation = null, string sessionId = null)
        {
            GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(gatewayApiConfig)
            {
                SessionId     = sessionId,
                OrderId       = PaymentHelper.GenerateOrderId(),
                TransactionId = PaymentHelper.GenerateOrderId(),
                ApiOperation  = apiOperation,
                OrderAmount   = "",
                OrderCurrency = gatewayApiConfig.Currency
            };

            gatewayApiRequest.buildRequestUrl();

            if (apiOperation == "CAPTURE" || apiOperation == "REFUND")
            {
                gatewayApiRequest.TransactionAmount = "";

                gatewayApiRequest.TransactionCurrency = gatewayApiConfig.Currency;

                gatewayApiRequest.OrderId = null;
            }
            if (apiOperation == "VOID" || apiOperation == "UPDATE_AUTHORIZATION")
            {
                gatewayApiRequest.OrderId = null;
            }
            if (apiOperation == "RETRIEVE_ORDER" || apiOperation == "RETRIEVE_TRANSACTION")
            {
                gatewayApiRequest.ApiMethod = "GET";

                gatewayApiRequest.OrderId = null;

                gatewayApiRequest.TransactionId = null;
            }

            gatewayApiRequest.buildPayload();

            return(gatewayApiRequest);
        }
Exemplo n.º 8
0
        public Checkout CreateTokenizationCheckoutSession(GridMPGSConfig mpgsConfig, string apiOperation = null, string sessionId = null)
        {
            try
            {
                LogInfo.Information(EnumExtensions.GetDescription(MPGSAPIOperation.CREATE_CHECKOUT_SESSION));

                GatewayApiConfig config = new GatewayApiConfig(mpgsConfig);

                GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(config)
                {
                    SessionId     = sessionId,
                    OrderId       = GenerateOrderId(),
                    TransactionId = GenerateOrderId(),
                    ApiOperation  = apiOperation,
                    OrderAmount   = "",
                    OrderCurrency = config.Currency
                };

                gatewayApiRequest.buildRequestUrl();

                if (apiOperation == "CAPTURE" || apiOperation == "REFUND")
                {
                    gatewayApiRequest.TransactionAmount   = "";
                    gatewayApiRequest.TransactionCurrency = config.Currency;
                    gatewayApiRequest.OrderId             = null;
                }
                if (apiOperation == "VOID" || apiOperation == "UPDATE_AUTHORIZATION")
                {
                    gatewayApiRequest.OrderId = null;
                }
                if (apiOperation == "RETRIEVE_ORDER" || apiOperation == "RETRIEVE_TRANSACTION")
                {
                    gatewayApiRequest.ApiMethod     = "GET";
                    gatewayApiRequest.OrderId       = null;
                    gatewayApiRequest.TransactionId = null;
                }
                gatewayApiRequest.buildPayload();

                Checkout checkOut = new Checkout();

                checkOut.CheckoutJsUrl = $@"{config.GatewayUrl}/form/version/{config.Version}/merchant/{config.MerchantId}/session.js";

                checkOut.MerchantId = config.MerchantId;

                checkOut.OrderId = gatewayApiRequest.OrderId;

                checkOut.CheckoutSession = null;

                checkOut.Currency = config.Currency;

                checkOut.TransactionID = gatewayApiRequest.TransactionId;

                return(checkOut);
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                throw ex;
            }
        }