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)); }
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)); }
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)); }
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)); }
public Checkout CreateCheckoutSession(GridMPGSConfig mpgsConfig, customerBilling customerBillingDetails, string MpgsOrderID, string transactionID, string receiptNumber, string orderNumber) { try { LogInfo.Information(EnumExtensions.GetDescription(MPGSAPIOperation.CREATE_CHECKOUT_SESSION)); GatewayApiConfig config = new GatewayApiConfig(mpgsConfig); GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(config, customerBillingDetails, receiptNumber, orderNumber); gatewayApiRequest.ApiOperation = MPGSAPIOperation.CREATE_CHECKOUT_SESSION.ToString(); gatewayApiRequest.OrderId = MpgsOrderID; gatewayApiRequest.TransactionId = transactionID; gatewayApiRequest.OrderCurrency = config.Currency; gatewayApiRequest.buildSessionRequestUrl(); gatewayApiRequest.buildPayload(); gatewayApiRequest.ApiMethod = GatewayApiClient.POST; GatewayApiClient gatewayApiClient = new GatewayApiClient(config); String response = gatewayApiClient.SendTransaction(gatewayApiRequest); LogInfo.Information(EnumExtensions.GetDescription(MPGSAPIResponse.HostedCheckoutResponse) + response); CheckoutSessionModel checkoutSessionModel = CheckoutSessionModel.toCheckoutSessionModel(response); Checkout checkOut = new Checkout(); checkOut.CheckoutJsUrl = $@"{config.GatewayUrl}/checkout/version/{config.Version}/checkout.js"; checkOut.MerchantId = config.MerchantId; checkOut.OrderId = gatewayApiRequest.OrderId; checkOut.TransactionID = gatewayApiRequest.TransactionId; checkOut.CheckoutSession = checkoutSessionModel; checkOut.Currency = config.Currency; return(checkOut); } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); throw ex; } }
public ActionResult HostedCheckoutReceipt(string orderId, string result, string sessionId) { // Logger.LogInformation($"PaymentApiController HostedCheckoutReceipt action orderId {orderId} result {result} sessionId {sessionId}"); if (result == "SUCCESS") { GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(GatewayApiConfig) { ApiOperation = "RETRIEVE_ORDER", OrderId = orderId, ApiMethod = GatewayApiClient.GET }; gatewayApiRequest.buildOrderUrl(); string response = GatewayApiClient.SendTransaction(gatewayApiRequest); // Logger.LogInformation($"Hosted checkout retrieve order response {response}"); //parse response TransactionResponseModel transactionResponseModel = null; try { transactionResponseModel = TransactionResponseModel.toTransactionResponseModel(response); } catch (Exception e) { // Logger.LogError($"Hosted Checkout Receipt error : {JsonConvert.SerializeObject(e)}"); return(View("Error", new ErrorViewModel { RequestId = getRequestId(), Cause = e.InnerException != null ? e.InnerException.StackTrace : e.StackTrace, Message = e.Message })); } return(View(ViewList["Receipt"], transactionResponseModel)); } else { // Logger.LogError($"The payment was unsuccessful {result}"); return(View("Error", new ErrorViewModel { RequestId = getRequestId(), Cause = "Payment was unsuccessful", Message = "There was a problem completing your transaction." })); } }
public ActionResult ProcessHostedSession(int?ReservationId, GatewayApiRequest gatewayApiRequest) { if (ReservationId == null) { return(HttpNotFound()); } // Logger.LogInformation($"PaymentApiController ProcessHostedSession action gatewayApiRequest {JsonConvert.SerializeObject(gatewayApiRequest)}"); gatewayApiRequest.GatewayApiConfig = GatewayApiConfig; gatewayApiRequest.buildRequestUrl(); gatewayApiRequest.buildPayload(); string response = GatewayApiClient.SendTransaction(gatewayApiRequest); buildViewData(gatewayApiRequest, response, (int)ReservationId); return(View(ViewList["ApiResponse"])); }
public ActionResult browserPaymentReceipt(String transactionId, String orderId) { //get order id from page parameter //create a gateway parameters request to retrieve the transaction result GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(); gatewayApiRequest.GatewayApiConfig = GatewayApiConfig; gatewayApiRequest.ApiMethod = GatewayApiClient.GET; gatewayApiRequest.ApiOperation = "RETRIEVE_TRANSACTION"; gatewayApiRequest.OrderId = orderId; gatewayApiRequest.buildOrderUrl(); gatewayApiRequest.buildPayload(); string response = GatewayApiClient.SendTransaction(gatewayApiRequest); //validate transaction response if (JsonHelper.isErrorMessage(response)) { return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response))); } //parse response to model TransactionResponseModel model = null; try { model = TransactionResponseModel.toTransactionResponseModel(response); } catch (Exception e) { // Logger.LogError($"browserPaymentReceipt error : {JsonConvert.SerializeObject(e)}"); return(View("Error", new ErrorViewModel { RequestId = getRequestId(), Cause = e.InnerException != null ? e.InnerException.StackTrace : e.StackTrace, Message = e.Message })); } return(View(ViewList["Receipt"], model)); }
public string RetrieveCheckOutTransaction(GridMPGSConfig mpgsConfig, CheckOutResponseUpdate responseUpdate) { try { LogInfo.Information($" {EnumExtensions.GetDescription(MPGSAPIResponse.HostedCheckoutRetrieveReceipt) + " orderId " + responseUpdate.MPGSOrderID} result {responseUpdate.Result} sessionId {responseUpdate.CheckOutSessionID}"); GatewayApiConfig config = new GatewayApiConfig(mpgsConfig); if (responseUpdate.Result == MPGSAPIResponse.SUCCESS.ToString() || responseUpdate.Result == MPGSAPIResponse.CAPTURED.ToString()) { GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(config) { ApiOperation = MPGSAPIOperation.RETRIEVE_ORDER.ToString(), OrderId = responseUpdate.MPGSOrderID, ApiMethod = GatewayApiClient.GET }; gatewayApiRequest.buildOrderUrl(); GatewayApiClient gatewayApiClient = new GatewayApiClient(config); string response = gatewayApiClient.SendTransaction(gatewayApiRequest); LogInfo.Information($" {EnumExtensions.GetDescription(MPGSAPIResponse.HostedCheckoutRetrieveReceipt) + " " + response}"); //parse response return(response); } else { LogInfo.Error($" {MPGSAPIResponse.Unsuccessful.ToString()+ ". " + responseUpdate.Result}"); return(string.Empty); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); throw ex; } }
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; } }
public ActionResult ShowHostedCheckout() { // Logger.LogInformation("Payment controller HostedCheckout action"); GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(GatewayApiConfig); gatewayApiRequest.ApiOperation = "CREATE_CHECKOUT_SESSION"; gatewayApiRequest.OrderId = IdUtils.generateSampleId(); gatewayApiRequest.OrderCurrency = GatewayApiConfig.Currency; gatewayApiRequest.buildSessionRequestUrl(); gatewayApiRequest.buildPayload(); gatewayApiRequest.ApiMethod = GatewayApiClient.POST; try { String response = GatewayApiClient.SendTransaction(gatewayApiRequest); // Logger.LogInformation("HostedCheckout response -- " + response); CheckoutSessionModel checkoutSessionModel = CheckoutSessionModel.toCheckoutSessionModel(response); ViewBag.CheckoutJsUrl = $@"{GatewayApiConfig.GatewayUrl}/checkout/version/{GatewayApiConfig.Version}/checkout.js"; ViewBag.MerchantId = GatewayApiConfig.MerchantId; ViewBag.OrderId = gatewayApiRequest.OrderId; ViewBag.CheckoutSession = checkoutSessionModel; ViewBag.Currency = GatewayApiConfig.Currency; } catch (Exception e) { // Logger.LogError($"Hosted Checkout error : {JsonConvert.SerializeObject(e)}"); return(View("Error", new ErrorViewModel { RequestId = getRequestId(), Cause = e.InnerException != null ? e.InnerException.StackTrace : e.StackTrace, Message = e.Message })); } return(View("HostedCheckout")); }
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; } }
public ActionResult Process(GatewayApiRequest gatewayApiRequest) { // Logger.LogInformation($"PaymentApiController Process action gatewayApiRequest {JsonConvert.SerializeObject(gatewayApiRequest)}"); gatewayApiRequest.GatewayApiConfig = GatewayApiConfig; //retrieve order doesnt require transaction information on the url if ("RETRIEVE_ORDER" == gatewayApiRequest.ApiOperation) { gatewayApiRequest.buildOrderUrl(); } else { gatewayApiRequest.buildRequestUrl(); } gatewayApiRequest.buildPayload(); string response = GatewayApiClient.SendTransaction(gatewayApiRequest); buildViewData(gatewayApiRequest, response, 0); return(View(ViewList["ApiResponse"])); }
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"])); }
public ActionResult masterpassResponse(String oauth_token, String oauth_verifier, String checkoutId, String checkout_resource_url, String mpstatus) { String UPDATE_SESSION_FROM_WALLET = "UPDATE_SESSION_FROM_WALLET"; String WALLET_PROVIDER = "MASTERPASS_ONLINE"; //get session values String sessionId = getSessionValueAsString("sessionId"); String amount = getSessionValueAsString("amount"); String currency = getSessionValueAsString("currency"); String orderId = getSessionValueAsString("orderId"); //remove session values removeSessionValue("sessionId"); removeSessionValue("amount"); removeSessionValue("currency"); removeSessionValue("orderId"); // UPDATE_SESSION_FROM_WALLET - Retrieve payment details from wallet using session ID GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(GatewayApiConfig); gatewayApiRequest.ApiMethod = GatewayApiClient.POST; gatewayApiRequest.ApiOperation = UPDATE_SESSION_FROM_WALLET; gatewayApiRequest.MasterpassOnline = WALLET_PROVIDER; gatewayApiRequest.MasterpassOauthToken = oauth_token; gatewayApiRequest.MasterpassOauthVerifier = oauth_verifier; gatewayApiRequest.MasterpassCheckoutUrl = checkout_resource_url; gatewayApiRequest.buildSessionRequestUrl(sessionId); //build json gatewayApiRequest.buildPayload(); string response = GatewayApiClient.SendTransaction(gatewayApiRequest); // Logger.LogInformation($"Masterpass update session : {response}"); //validate transaction response if (JsonHelper.isErrorMessage(response)) { return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response))); } // Make a payment using the session // Construct API request GatewayApiRequest gatewayPayApiRequest = new GatewayApiRequest(GatewayApiConfig); gatewayPayApiRequest.ApiMethod = GatewayApiClient.PUT; gatewayPayApiRequest.ApiOperation = "PAY"; gatewayPayApiRequest.SessionId = sessionId; //order info gatewayPayApiRequest.OrderAmount = amount; gatewayPayApiRequest.OrderId = orderId; gatewayPayApiRequest.OrderCurrency = currency; gatewayPayApiRequest.TransactionId = IdUtils.generateSampleId(); //build payload gatewayPayApiRequest.buildPayload(); gatewayPayApiRequest.buildRequestUrl(); response = GatewayApiClient.SendTransaction(gatewayPayApiRequest); // Logger.LogInformation($"Masterpass PAY operation : {response}"); //validate transaction response if (JsonHelper.isErrorMessage(response)) { return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response))); } //parse response to default transaction response model TransactionResponseModel model = null; try { model = TransactionResponseModel.fromMasterpassResponseToTransactionResponseModel(response); } catch (Exception e) { // Logger.LogError($"MasterpassResponse error : {JsonConvert.SerializeObject(e)}"); return(View("Error", new ErrorViewModel { RequestId = getRequestId(), Cause = e.InnerException != null ? e.InnerException.StackTrace : e.StackTrace, Message = e.Message })); } return(View(ViewList["Receipt"], model)); }
public ActionResult ProcessMasterpass(GatewayApiRequest gatewayApiRequest) { // Logger.LogInformation($"PaymentApiController Process Master Pass action gatewayApiRequest {JsonConvert.SerializeObject(gatewayApiRequest)}"); String response = null; // Create session to use with OPEN_WALLET operation GatewayApiRequest gatewaySessionRequest = new GatewayApiRequest(GatewayApiConfig); gatewaySessionRequest.buildSessionRequestUrl(); gatewaySessionRequest.ApiMethod = GatewayApiClient.POST; response = GatewayApiClient.SendTransaction(gatewaySessionRequest); //validate transaction response if (JsonHelper.isErrorMessage(response)) { return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response))); } //convert json to model CheckoutSessionModel checkoutSessionModel = CheckoutSessionModel.toCheckoutSessionModel(response); // Logger.LogInformation($"Masterpass hostedSession created {response}"); // Call UPDATE_SESSION to add order information to session //update http verb GatewayApiRequest gatewayUpdateSessionRequest = new GatewayApiRequest(GatewayApiConfig); gatewayUpdateSessionRequest.ApiMethod = GatewayApiClient.PUT; //update the url appending session id gatewayUpdateSessionRequest.buildSessionRequestUrl(checkoutSessionModel.Id); gatewayUpdateSessionRequest.OrderId = gatewayApiRequest.OrderId; gatewayUpdateSessionRequest.OrderCurrency = gatewayApiRequest.OrderCurrency; gatewayUpdateSessionRequest.OrderAmount = gatewayApiRequest.OrderAmount; //build payload with order info gatewayUpdateSessionRequest.buildPayload(); response = GatewayApiClient.SendTransaction(gatewayUpdateSessionRequest); // Logger.LogInformation($"Masterpass updated session {response}"); //validate transaction response if (JsonHelper.isErrorMessage(response)) { return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response))); } // Call OPEN_WALLET to retrieve Masterpass configuration //It will use session URL GatewayApiRequest gatewayOpenWalletRequest = new GatewayApiRequest(GatewayApiConfig); gatewayOpenWalletRequest.buildSessionRequestUrl(checkoutSessionModel.Id); gatewayOpenWalletRequest.ApiMethod = GatewayApiClient.POST; gatewayOpenWalletRequest.MasterpassOnline = gatewayApiRequest.MasterpassOnline; gatewayOpenWalletRequest.MasterpassOriginUrl = gatewayApiRequest.MasterpassOriginUrl; gatewayOpenWalletRequest.OrderCurrency = gatewayApiRequest.OrderCurrency; gatewayOpenWalletRequest.OrderAmount = gatewayApiRequest.OrderAmount; gatewayOpenWalletRequest.buildPayload(); response = GatewayApiClient.SendTransaction(gatewayOpenWalletRequest); //validate transaction response if (JsonHelper.isErrorMessage(response)) { return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response))); } //parse response to model MasterpassWalletResponse masterpassWalletResponse = null; try { masterpassWalletResponse = MasterpassWalletResponse.toMasterpassWalletResponse(response); } catch (Exception e) { // Logger.LogError($"ProcessMasterpass error : {JsonConvert.SerializeObject(e)}"); return(View("Error", new ErrorViewModel { RequestId = getRequestId(), Cause = e.InnerException != null ? e.InnerException.StackTrace : e.StackTrace, Message = e.Message })); } // Logger.LogInformation($"Masterpass wallet configuration {response}"); // Save this value in HttpSession to retrieve after returning from issuer authentication form setSessionValue("sessionId", checkoutSessionModel.Id); setSessionValue("amount", gatewayApiRequest.OrderAmount); setSessionValue("currency", gatewayApiRequest.OrderCurrency); setSessionValue("orderId", gatewayApiRequest.OrderId); //set values for view usage ViewBag.requestToken = masterpassWalletResponse.RequestToken; ViewBag.merchantCheckoutId = masterpassWalletResponse.MerchantCheckoutId; ViewBag.allowedCardTypes = masterpassWalletResponse.AllowedCardTypes; return(View(ViewList["MasterpassButton"])); }
public ActionResult Check3dsEnrollment(GatewayApiRequest gatewayApiRequest) { // Logger.LogInformation($"PaymentApiController Check3dsEnrollment action SessionId {JsonConvert.SerializeObject(gatewayApiRequest)} gatewayApiRequest.SessionId {gatewayApiRequest.SessionId}"); gatewayApiRequest.GatewayApiConfig = GatewayApiConfig; // Retrieve session gatewayApiRequest.buildSessionRequestUrl(); gatewayApiRequest.ApiMethod = GatewayApiClient.GET; // Logger.LogInformation($"gatewayApiRequest {JsonConvert.SerializeObject(gatewayApiRequest)}"); string response = GatewayApiClient.SendTransaction(gatewayApiRequest); // Logger.LogInformation("Get session response -- " + response); //validate transaction response if (JsonHelper.isErrorMessage(response)) { return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response))); } CheckoutSessionModel checkoutSessionModel = CheckoutSessionModel.toCheckoutSessionModel(response); // Logger.LogInformation($@"checkoutSession.Id {checkoutSessionModel.Id} gatewayApiRequest.SessionId {gatewayApiRequest.SessionId}"); string secureId = IdUtils.generateSampleId(); gatewayApiRequest.SecureId = secureId; gatewayApiRequest.buildSecureIdRequestUrl(); gatewayApiRequest.buildPayload(); gatewayApiRequest.ApiMethod = GatewayApiClient.PUT; //add values in session to use it after processing response setSessionValue("secureId", secureId); setSessionValue("sessionId", checkoutSessionModel.Id); setSessionValue("amount", gatewayApiRequest.OrderAmount); setSessionValue("currency", gatewayApiRequest.OrderCurrency); setSessionValue("orderId", gatewayApiRequest.OrderId); setSessionValue("transactionId", gatewayApiRequest.TransactionId); response = GatewayApiClient.SendTransaction(gatewayApiRequest); // Logger.LogInformation($"SecureId response {response}"); //validate transaction response if (JsonHelper.isErrorMessage(response)) { return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response))); } //parse response SecureIdEnrollmentResponseModel model = null; try { model = SecureIdEnrollmentResponseModel.toSecureIdEnrollmentResponseModel(Request, response); } catch (Exception e) { // Logger.LogError($"Check3dsEnrollment error : {JsonConvert.SerializeObject(e)}"); return(View("Error", new ErrorViewModel { RequestId = getRequestId(), Cause = e.InnerException != null ? e.InnerException.StackTrace : e.StackTrace, Message = e.Message })); } //check process result // Logger.LogInformation($"SecureIdEnrollmentResponseModel {JsonConvert.SerializeObject(model)}"); if (model.Status != "CARD_ENROLLED") { // Logger.LogError($"Check3dsEnrollment was unsuccessful, status {model.Status}"); return(View("Error", new ErrorViewModel { RequestId = getRequestId(), Cause = model.Status, Message = "Card not enrolled in 3DS." })); } return(View(ViewList["SecureIdPayerAuthenticationForm"], model)); }
/// <summary> /// Generic method used for redirec to Browsers payments url. /// </summary> /// <returns>The payment page.</returns> /// <param name="gatewayApiRequest">Gateway API request.</param> private ActionResult browserPayment(GatewayApiRequest gatewayApiRequest) { //cons string INITIATE_BROWSER_PAYMENT = "INITIATE_BROWSER_PAYMENT"; string callbackController = "/browserPaymentReceipt"; //build api request gatewayApiRequest.GatewayApiConfig = GatewayApiConfig; gatewayApiRequest.ApiOperation = INITIATE_BROWSER_PAYMENT; gatewayApiRequest.ApiMethod = GatewayApiClient.PUT; //Build Redirect url //Concating the transaction and order ids. It will be used to retrieve the payment result on callback // string returnURL = Microsoft.AspNetCore.Http.Extensions.UriHelper.BuildAbsolute(Request.Scheme, Request.Host, Request.PathBase, callbackController); //add query string to return url // returnURL = QueryHelpers.AddQueryString(returnURL, "transactionId", gatewayApiRequest.TransactionId); // returnURL = QueryHelpers.AddQueryString(returnURL, "orderId", gatewayApiRequest.OrderId); // gatewayApiRequest.ReturnUrl = returnURL; gatewayApiRequest.buildRequestUrl(); gatewayApiRequest.buildPayload(); // Logger.LogInformation($"PaymentApiController action gatewayApiRequest {JsonConvert.SerializeObject(gatewayApiRequest)}"); string response = GatewayApiClient.SendTransaction(gatewayApiRequest); //validate transaction response if (JsonHelper.isErrorMessage(response)) { return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response))); } //parse response InitiateBrowserPaymentResponse initiateResponse = null; try { initiateResponse = InitiateBrowserPaymentResponse.toInitiateBrowserPaymentResponse(response); } catch (Exception e) { // Logger.LogError($"BrowserPayment error : {JsonConvert.SerializeObject(e)}"); return(View("Error", new ErrorViewModel { RequestId = getRequestId(), Cause = e.InnerException != null ? e.InnerException.StackTrace : e.StackTrace, Message = e.Message })); } //check result if ("SUCCESS" != initiateResponse.Result) { // Logger.LogInformation($"Browser controller action error response {response}"); return(View("Error", new ErrorViewModel { RequestId = getRequestId(), Cause = initiateResponse.Result, Message = "Browser Payment error." })); } //redirect to partner browser payment page return(Redirect(initiateResponse.RedirectUrl)); }
public ActionResult Process3dsAuthenticationResult() { String responseView = ViewList["ApiResponse"]; //cons String AUTHORIZE = "AUTHORIZE"; String PROCESS_ACS_RESULT = "PROCESS_ACS_RESULT"; //get secure / session information from session String secureId = getSessionValueAsString("secureId"); String sessionId = getSessionValueAsString("sessionId"); String amount = getSessionValueAsString("amount"); String currency = getSessionValueAsString("currency"); String orderId = getSessionValueAsString("orderId"); String transactionId = getSessionValueAsString("transactionId"); //remove values from session removeSessionValue("secureId"); removeSessionValue("sessionId"); removeSessionValue("amount"); removeSessionValue("currency"); removeSessionValue("orderId"); removeSessionValue("transactionId"); // Retrieve Payment Authentication Response (PaRes) from request String paRes = this.Request.Form["PaRes"]; //init aux variables String response = null; GatewayApiRequest gatewayApiRequest = null; // Process Access Control Server (ACS) result gatewayApiRequest = new GatewayApiRequest(); gatewayApiRequest.GatewayApiConfig = GatewayApiConfig; gatewayApiRequest.ApiMethod = GatewayApiClient.POST; gatewayApiRequest.PaymentAuthResponse = paRes; gatewayApiRequest.SecureId = secureId; gatewayApiRequest.ApiOperation = PROCESS_ACS_RESULT; gatewayApiRequest.buildPayload(); gatewayApiRequest.buildSecureIdRequestUrl(); response = GatewayApiClient.SendTransaction(gatewayApiRequest); //validate transaction response if (JsonHelper.isErrorMessage(response)) { return(View("Error", ErrorViewModel.toErrorViewModel(getRequestId(), response))); } //parse response to domain SecureIdEnrollmentResponseModel model = null; try { model = SecureIdEnrollmentResponseModel.toSecureIdEnrollmentResponseModel(Request, response); // Logger.LogInformation($"SecureIdEnrollmentResponseModel {JsonConvert.SerializeObject(model)}"); } catch (Exception e) { // Logger.LogError($"Process3dsAuthenticationResult error : {JsonConvert.SerializeObject(e)}"); return(View("Error", new ErrorViewModel { RequestId = getRequestId(), Cause = e.InnerException != null ? e.InnerException.StackTrace : e.StackTrace, Message = e.Message })); } //create 'authorize' API request in case of SUCCESS response if (model.Status != null && "AUTHENTICATION_FAILED" != model.Status) { //build authorize request gatewayApiRequest = new GatewayApiRequest(); gatewayApiRequest.GatewayApiConfig = GatewayApiConfig; gatewayApiRequest.ApiMethod = GatewayApiClient.PUT; gatewayApiRequest.ApiOperation = AUTHORIZE; gatewayApiRequest.SessionId = sessionId; gatewayApiRequest.SecureId3D = secureId; gatewayApiRequest.OrderCurrency = currency; gatewayApiRequest.OrderAmount = amount; gatewayApiRequest.TransactionId = transactionId; gatewayApiRequest.OrderId = orderId; gatewayApiRequest.buildPayload(); gatewayApiRequest.buildRequestUrl(); //call api response = GatewayApiClient.SendTransaction(gatewayApiRequest); //build response view this.buildViewData(gatewayApiRequest, response, 0); } else { //return error view return(View("Error", new ErrorViewModel { RequestId = getRequestId(), Cause = model.Status, Message = "3DS Authentication failed." })); } return(View(responseView)); }