Beispiel #1
0
        public TokenResponse TokenizeTest(GridMPGSConfig mpgsConfig)
        {
            try
            {
                GatewayApiConfig config = new GatewayApiConfig(mpgsConfig);

                GatewayApiRequest gatewayUpdateSessionRequest = new GatewayApiRequest(config);

                GatewayApiClient gatewayApiClient = new GatewayApiClient(config);

                //generate token
                GatewayApiRequest gatewayGenerateTokenRequest = new GatewayApiRequest(config);

                gatewayGenerateTokenRequest.SessionId = "SESSION0002676972204L29024409K5";

                gatewayGenerateTokenRequest.ApiMethod = GatewayApiClient.POST;

                gatewayGenerateTokenRequest.buildPayload();

                gatewayGenerateTokenRequest.buildTokenUrl();

                string request = JsonConvert.SerializeObject(gatewayGenerateTokenRequest);

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

                String response = gatewayApiClient.SendTransaction(gatewayGenerateTokenRequest);

                LogInfo.Information(response);

                TokenResponse tokenResponse = TokenResponse.ToTokenResponse(response);

                LogInfo.Information($"Tokenize response :  {response}");

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

                throw ex;
            }
        }
Beispiel #2
0
        public ActionResult tokenize(GatewayApiRequest gatewayApiRequest)
        {
//            Logger.LogInformation($"PaymentApiController ProcessHostedSession action gatewayApiRequest {JsonConvert.SerializeObject(gatewayApiRequest)}");

            //update session with order details
            GatewayApiRequest gatewayUpdateSessionRequest = new GatewayApiRequest(GatewayApiConfig);

            gatewayUpdateSessionRequest.ApiMethod = GatewayApiClient.PUT;

            //update the url appending session id
            gatewayUpdateSessionRequest.buildSessionRequestUrl(gatewayApiRequest.SessionId);

            gatewayUpdateSessionRequest.OrderId       = gatewayApiRequest.OrderId;
            gatewayUpdateSessionRequest.OrderCurrency = gatewayApiRequest.OrderCurrency;
            gatewayUpdateSessionRequest.OrderAmount   = gatewayApiRequest.OrderAmount;

            //build payload with order info
            gatewayUpdateSessionRequest.buildPayload();

            String response = GatewayApiClient.SendTransaction(gatewayUpdateSessionRequest);

            //   Logger.LogInformation($"Tokenize updated session {response}");

            //validate transaction response
            if (JsonHelper.isErrorMessage(response))
            {
                return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response)));
            }

            //generate token
            GatewayApiRequest gatewayGenerateTokenRequest = new GatewayApiRequest(GatewayApiConfig);

            gatewayGenerateTokenRequest.SessionId = gatewayApiRequest.SessionId;
            gatewayGenerateTokenRequest.ApiMethod = GatewayApiClient.POST;
            gatewayGenerateTokenRequest.buildPayload();
            gatewayGenerateTokenRequest.buildTokenUrl();

            response = GatewayApiClient.SendTransaction(gatewayGenerateTokenRequest);

            //validate token response
            if (JsonHelper.isErrorMessage(response))
            {
                return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response)));
            }

            //convert json to model
            TokenResponse tokenResponse = TokenResponse.ToTokenResponse(response);

            //payment with token
            GatewayApiRequest gatewayGeneratePaymentRequest = new GatewayApiRequest(GatewayApiConfig);

            gatewayGeneratePaymentRequest.ApiOperation = "PAY";
            gatewayGeneratePaymentRequest.ApiMethod    = GatewayApiClient.PUT;

            gatewayGeneratePaymentRequest.Token         = tokenResponse.Token;
            gatewayGeneratePaymentRequest.SessionId     = gatewayApiRequest.SessionId;
            gatewayGeneratePaymentRequest.OrderId       = gatewayApiRequest.OrderId;
            gatewayGeneratePaymentRequest.TransactionId = gatewayApiRequest.TransactionId;

            gatewayGeneratePaymentRequest.buildPayload();
            gatewayGeneratePaymentRequest.buildRequestUrl();

            response = GatewayApiClient.SendTransaction(gatewayGeneratePaymentRequest);

            buildViewData(gatewayGeneratePaymentRequest, response, 0);

            return(View(ViewList["ApiResponse"]));
        }