From bba343baf62bd16df6a3367840d49c97398d434b Mon Sep 17 00:00:00 2001 From: Surya Prakash Nayak Date: Wed, 30 Oct 2024 18:40:08 +0530 Subject: [PATCH] Auth Sample code commented | GENAI=NO --- .../AuthSampleCode/DeleteGenerateHeaders.java | 188 +++++----- .../AuthSampleCode/DeleteMethod.java | 180 ++++----- .../AuthSampleCode/GetGenerateHeaders.java | 222 ++++++------ .../AuthSampleCode/GetMethod.java | 134 +++---- .../AuthSampleCode/GetObjectMethod.java | 140 +++---- .../AuthSampleCode/PostGenerateHeaders.java | 306 ++++++++-------- .../AuthSampleCode/PostMethod.java | 244 ++++++------- .../AuthSampleCode/PostObjectMethod.java | 126 +++---- .../AuthSampleCode/PutGenerateHeaders.java | 200 +++++----- .../AuthSampleCode/PutMethod.java | 132 +++---- .../authentication/AuthSampleCode/Test.java | 20 +- .../AuthSampleCode/reportDownload.java | 342 +++++++++--------- 12 files changed, 1117 insertions(+), 1117 deletions(-) diff --git a/src/main/java/samples/authentication/AuthSampleCode/DeleteGenerateHeaders.java b/src/main/java/samples/authentication/AuthSampleCode/DeleteGenerateHeaders.java index e41b92c..61415ac 100644 --- a/src/main/java/samples/authentication/AuthSampleCode/DeleteGenerateHeaders.java +++ b/src/main/java/samples/authentication/AuthSampleCode/DeleteGenerateHeaders.java @@ -1,38 +1,38 @@ -package samples.authentication.AuthSampleCode; - -import java.lang.invoke.MethodHandles; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Properties; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import com.cybersource.authsdk.core.Authorization; -import com.cybersource.authsdk.core.MerchantConfig; -import com.cybersource.authsdk.util.GlobalLabelParameters; -import samples.authentication.harness.MerchantProperties; +//package samples.authentication.AuthSampleCode; +// +//import java.lang.invoke.MethodHandles; +//import java.time.ZoneId; +//import java.time.ZonedDateTime; +//import java.time.format.DateTimeFormatter; +//import java.util.Properties; +// +//import org.apache.logging.log4j.LogManager; +//import org.apache.logging.log4j.Logger; +//import com.cybersource.authsdk.core.Authorization; +//import com.cybersource.authsdk.core.MerchantConfig; +//import com.cybersource.authsdk.util.GlobalLabelParameters; +//import samples.authentication.harness.MerchantProperties; /** * This class generates the Headers that are present in the token was sent the server for transaction, * Delete operations. * * */ -public class DeleteGenerateHeaders { - - private Properties merchantProp; - private MerchantConfig merchantConfig; - private String authenticationType = null; - private Authorization auth; - private static String requestType = "DELETE"; - private String date = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneId.of("GMT"))); - Logger logger; - - private String tempSig; - - public static void WriteLogAudit(int status) { - String filename = MethodHandles.lookup().lookupClass().getSimpleName(); - System.out.println("[Sample Code Testing] [" + filename + "] " + status); - } +//public class DeleteGenerateHeaders { +// +// private Properties merchantProp; +// private MerchantConfig merchantConfig; +// private String authenticationType = null; +// private Authorization auth; +// private static String requestType = "DELETE"; +// private String date = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneId.of("GMT"))); +// Logger logger; +// +// private String tempSig; +// +// public static void WriteLogAudit(int status) { +// String filename = MethodHandles.lookup().lookupClass().getSimpleName(); +// System.out.println("[Sample Code Testing] [" + filename + "] " + status); +// } /** * @@ -41,78 +41,78 @@ public static void WriteLogAudit(int status) { * @throws Exception * : */ - public DeleteGenerateHeaders(MerchantConfig merchantConfig) throws Exception { - logger = LogManager.getLogger(getClass()); - merchantConfig.validateMerchantDetails(); - auth = new Authorization(); - generateDeleteHeaders(merchantConfig); - } - - public DeleteGenerateHeaders() throws Exception { - auth = new Authorization(); - merchantProp = MerchantProperties.getMerchantProperties(); - merchantConfig = new MerchantConfig(merchantProp); - merchantConfig.setRequestType(requestType); - - this.logger = LogManager.getLogger(getClass()); - this.logger.info(GlobalLabelParameters.BEGIN_TRANSACTION + "\n******************* Delete Generate Headers *******************"); - - System.out.println("Authentication Type : " + merchantConfig.getAuthenticationType().trim()); - - boolean isMerchant = merchantConfig.validateMerchantDetails(); - if(isMerchant){ - generateDeleteHeaders(merchantConfig); - } else { - WriteLogAudit(400); - } - - this.logger.info(GlobalLabelParameters.END_TRANSACTION + "\n"); - } +// public DeleteGenerateHeaders(MerchantConfig merchantConfig) throws Exception { +// logger = LogManager.getLogger(getClass()); +// merchantConfig.validateMerchantDetails(); +// auth = new Authorization(); +// generateDeleteHeaders(merchantConfig); +// } +// +// public DeleteGenerateHeaders() throws Exception { +// auth = new Authorization(); +// merchantProp = MerchantProperties.getMerchantProperties(); +// merchantConfig = new MerchantConfig(merchantProp); +// merchantConfig.setRequestType(requestType); +// +// this.logger = LogManager.getLogger(getClass()); +// this.logger.info(GlobalLabelParameters.BEGIN_TRANSACTION + "\n******************* Delete Generate Headers *******************"); +// +// System.out.println("Authentication Type : " + merchantConfig.getAuthenticationType().trim()); +// +// boolean isMerchant = merchantConfig.validateMerchantDetails(); +// if(isMerchant){ +// generateDeleteHeaders(merchantConfig); +// } else { +// WriteLogAudit(400); +// } +// +// this.logger.info(GlobalLabelParameters.END_TRANSACTION + "\n"); +// } /** * This method generates the detailed header detail of the transaction and displays and log them. * @throws Exception */ - private void generateDeleteHeaders(MerchantConfig merchantConfig) throws Exception { - authenticationType = merchantConfig.getAuthenticationType().trim(); - - this.logger.info(GlobalLabelParameters.AUTENTICATION_TYPE + authenticationType); - this.logger.info(GlobalLabelParameters.REQUEST_TYPE + " : " + requestType); - this.logger.info(GlobalLabelParameters.DATE + " : " + date); - this.logger.info(GlobalLabelParameters.HOST + " : " + merchantConfig.getRequestHost()); - this.logger.info(GlobalLabelParameters.V_C_MERCHANTID + " : " + merchantConfig.getMerchantID().trim()); - this.logger.info(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); - - System.out.println("Request Type : " + requestType); - System.out.println("Date : " + date); - System.out.println("MerchantID : " + merchantConfig.getMerchantID().trim()); - System.out.println("HOST : " + merchantConfig.getRequestHost()); - System.out.println(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); - - if (authenticationType.equalsIgnoreCase(GlobalLabelParameters.HTTP)) { - System.out.println(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); - this.logger.info(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); - - tempSig = auth.getToken(merchantConfig); - System.out.println("Signature : " + tempSig.toString()); - WriteLogAudit(200); - - } else { - String jwtRequestBody = null; - auth.setJWTRequestBody(jwtRequestBody); - tempSig = auth.getToken(merchantConfig); - System.out.println("Authorization, Bearer " + tempSig.toString()); - WriteLogAudit(200); - } - } +// private void generateDeleteHeaders(MerchantConfig merchantConfig) throws Exception { +// authenticationType = merchantConfig.getAuthenticationType().trim(); +// +// this.logger.info(GlobalLabelParameters.AUTENTICATION_TYPE + authenticationType); +// this.logger.info(GlobalLabelParameters.REQUEST_TYPE + " : " + requestType); +// this.logger.info(GlobalLabelParameters.DATE + " : " + date); +// this.logger.info(GlobalLabelParameters.HOST + " : " + merchantConfig.getRequestHost()); +// this.logger.info(GlobalLabelParameters.V_C_MERCHANTID + " : " + merchantConfig.getMerchantID().trim()); +// this.logger.info(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); +// +// System.out.println("Request Type : " + requestType); +// System.out.println("Date : " + date); +// System.out.println("MerchantID : " + merchantConfig.getMerchantID().trim()); +// System.out.println("HOST : " + merchantConfig.getRequestHost()); +// System.out.println(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); +// +// if (authenticationType.equalsIgnoreCase(GlobalLabelParameters.HTTP)) { +// System.out.println(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); +// this.logger.info(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); +// +// tempSig = auth.getToken(merchantConfig); +// System.out.println("Signature : " + tempSig.toString()); +// WriteLogAudit(200); +// +// } else { +// String jwtRequestBody = null; +// auth.setJWTRequestBody(jwtRequestBody); +// tempSig = auth.getToken(merchantConfig); +// System.out.println("Authorization, Bearer " + tempSig.toString()); +// WriteLogAudit(200); +// } +// } /** * * @param args : Contains getId entry. * @throws Exception */ - public static void main(String[] args) throws Exception { - - new DeleteGenerateHeaders(); - } -} +// public static void main(String[] args) throws Exception { +// +// new DeleteGenerateHeaders(); +// } +//} diff --git a/src/main/java/samples/authentication/AuthSampleCode/DeleteMethod.java b/src/main/java/samples/authentication/AuthSampleCode/DeleteMethod.java index 14d01ab..c46a8a0 100644 --- a/src/main/java/samples/authentication/AuthSampleCode/DeleteMethod.java +++ b/src/main/java/samples/authentication/AuthSampleCode/DeleteMethod.java @@ -1,54 +1,54 @@ -package samples.authentication.AuthSampleCode; - -import java.lang.invoke.MethodHandles; -import java.util.Properties; - -import org.apache.commons.lang3.StringUtils; - -import com.cybersource.apisdk.controller.ApiController; -import com.cybersource.apisdk.model.Response; -import com.cybersource.authsdk.core.MerchantConfig; -import samples.authentication.harness.MerchantProperties; +//package samples.authentication.AuthSampleCode; +// +//import java.lang.invoke.MethodHandles; +//import java.util.Properties; +// +//import org.apache.commons.lang3.StringUtils; +// +//import com.cybersource.apisdk.controller.ApiController; +//import com.cybersource.apisdk.model.Response; +//import com.cybersource.authsdk.core.MerchantConfig; +//import samples.authentication.harness.MerchantProperties; /** * Depending on the authentication type HTTP or JWT , this class performs the * PUT operation on the test url 'apitest.cybersource.com'. */ -public class DeleteMethod { - private ApiController apiController; - private String authenticationType; - private String response; - private String responseCode; - private Properties merchantProp; - private MerchantConfig merchantConfig; - private Response responseObj; - /* Request Type is always PUT */ - private String requestType = "DELETE"; - /* Give the url path to where the data needs to be authenticated. */ - private String url; - /* Request Target. */ - private String requestTarget = "/reporting/v2/reportSubscriptions/TRRReport?organizationId=testrest"; - private String requestJson = "{ \"startDay\":\"23\",\r\n" + - " \"timeZone\":\"America/Chicago\",\r\n" + - " \"reportDefinitionName\":\"TransactionRequestClass\",\r\n" + - " \"startTime\":\"1100\",\r\n" + - " \"reportFrequency\":\"DAILY\",\r\n" + - " \"ReportName\":\"TRRReport\",\r\n" + - " \"reportFormat\":\"csv\",\r\n" + - " \"orgId\":\"testrest\",\r\n" + - " \"reportType\":\"detail\",\r\n" + - " \"reportFields\": [\"Request.RequestID\",\"Request.TransactionDate\",\"Request.MerchantReferenceNumber\",\"Request.MerchantID\"]\r\n" + - "}"; - - public static void WriteLogAudit(int status) { - String filename = MethodHandles.lookup().lookupClass().getSimpleName(); - System.out.println("[Sample Code Testing] [" + filename + "] " + status); - } +//public class DeleteMethod { +// private ApiController apiController; +// private String authenticationType; +// private String response; +// private String responseCode; +// private Properties merchantProp; +// private MerchantConfig merchantConfig; +// private Response responseObj; +// /* Request Type is always PUT */ +// private String requestType = "DELETE"; +// /* Give the url path to where the data needs to be authenticated. */ +// private String url; +// /* Request Target. */ +// private String requestTarget = "/reporting/v2/reportSubscriptions/TRRReport?organizationId=testrest"; +// private String requestJson = "{ \"startDay\":\"23\",\r\n" + +// " \"timeZone\":\"America/Chicago\",\r\n" + +// " \"reportDefinitionName\":\"TransactionRequestClass\",\r\n" + +// " \"startTime\":\"1100\",\r\n" + +// " \"reportFrequency\":\"DAILY\",\r\n" + +// " \"ReportName\":\"TRRReport\",\r\n" + +// " \"reportFormat\":\"csv\",\r\n" + +// " \"orgId\":\"testrest\",\r\n" + +// " \"reportType\":\"detail\",\r\n" + +// " \"reportFields\": [\"Request.RequestID\",\"Request.TransactionDate\",\"Request.MerchantReferenceNumber\",\"Request.MerchantID\"]\r\n" + +// "}"; +// +// public static void WriteLogAudit(int status) { +// String filename = MethodHandles.lookup().lookupClass().getSimpleName(); +// System.out.println("[Sample Code Testing] [" + filename + "] " + status); +// } /* This method initiates or begins the process. */ - public static void main(String[] args) throws Exception { - new DeleteMethod(); - } +// public static void main(String[] args) throws Exception { +// new DeleteMethod(); +// } /** * @@ -56,55 +56,55 @@ public static void main(String[] args) throws Exception { * @return * @throws Exception */ - public DeleteMethod() throws Exception { - apiController = new ApiController(); - - merchantProp = MerchantProperties.getMerchantProperties(); - merchantConfig = new MerchantConfig(merchantProp); - merchantConfig.setRequestType(requestType); - - authenticationType = merchantConfig.getAuthenticationType().trim(); - - merchantConfig.setRequestData(requestJson); - merchantConfig.setRequestTarget(requestTarget); - /* Begin PUT process. */ - url = "https://" + merchantConfig.getRequestHost() + merchantConfig.getRequestTarget(); - process(); - } +// public DeleteMethod() throws Exception { +// apiController = new ApiController(); +// +// merchantProp = MerchantProperties.getMerchantProperties(); +// merchantConfig = new MerchantConfig(merchantProp); +// merchantConfig.setRequestType(requestType); +// +// authenticationType = merchantConfig.getAuthenticationType().trim(); +// +// merchantConfig.setRequestData(requestJson); +// merchantConfig.setRequestTarget(requestTarget); +// /* Begin PUT process. */ +// url = "https://" + merchantConfig.getRequestHost() + merchantConfig.getRequestTarget(); +// process(); +// } /** * Calls the APISDK for processing the payment request. * * @throws Exception */ - private void process() throws Exception { - System.out.println(authenticationType.toUpperCase() + " Request"); - - try { - /* Call payment method of Api Controller class */ - responseObj = apiController.paymentGet(merchantConfig); - response = responseObj.getResponseMessage(); - /* Display Response Message from the server. */ - responseCode = responseObj.getResponseCode(); - if (responseCode.equals("200") || responseCode.equals("404")) { - WriteLogAudit(200); - } else { - WriteLogAudit(Integer.parseInt(responseCode)); - } - String vcCorrelationId = responseObj.getVcCorelationId(); - if (!StringUtils.isBlank(responseCode)&& !StringUtils.isBlank(response)) { - new DeleteGenerateHeaders(merchantConfig); - System.out.println("URL : " + url); - System.out.println("Response Code : " + responseCode); - System.out.println("V-C-Corealation ID : " + vcCorrelationId); - System.out.println("Response Message : " + response); - } - else { - System.out.println(responseObj.getResponseMessage()); - } - } catch (Exception e) { - System.out.println(e.getMessage()); - WriteLogAudit(400); - } - } -} +// private void process() throws Exception { +// System.out.println(authenticationType.toUpperCase() + " Request"); +// +// try { +// /* Call payment method of Api Controller class */ +// responseObj = apiController.paymentGet(merchantConfig); +// response = responseObj.getResponseMessage(); +// /* Display Response Message from the server. */ +// responseCode = responseObj.getResponseCode(); +// if (responseCode.equals("200") || responseCode.equals("404")) { +// WriteLogAudit(200); +// } else { +// WriteLogAudit(Integer.parseInt(responseCode)); +// } +// String vcCorrelationId = responseObj.getVcCorelationId(); +// if (!StringUtils.isBlank(responseCode)&& !StringUtils.isBlank(response)) { +// new DeleteGenerateHeaders(merchantConfig); +// System.out.println("URL : " + url); +// System.out.println("Response Code : " + responseCode); +// System.out.println("V-C-Corealation ID : " + vcCorrelationId); +// System.out.println("Response Message : " + response); +// } +// else { +// System.out.println(responseObj.getResponseMessage()); +// } +// } catch (Exception e) { +// System.out.println(e.getMessage()); +// WriteLogAudit(400); +// } +// } +//} diff --git a/src/main/java/samples/authentication/AuthSampleCode/GetGenerateHeaders.java b/src/main/java/samples/authentication/AuthSampleCode/GetGenerateHeaders.java index 767bddf..8395fff 100644 --- a/src/main/java/samples/authentication/AuthSampleCode/GetGenerateHeaders.java +++ b/src/main/java/samples/authentication/AuthSampleCode/GetGenerateHeaders.java @@ -1,58 +1,58 @@ -package samples.authentication.AuthSampleCode; - -import java.lang.invoke.MethodHandles; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Properties; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.cybersource.authsdk.core.Authorization; -import com.cybersource.authsdk.core.MerchantConfig; -import com.cybersource.authsdk.util.GlobalLabelParameters; -import com.cybersource.authsdk.util.Utility; - -import samples.authentication.harness.MerchantProperties; +//package samples.authentication.AuthSampleCode; +// +//import java.lang.invoke.MethodHandles; +//import java.time.ZoneId; +//import java.time.ZonedDateTime; +//import java.time.format.DateTimeFormatter; +//import java.util.Properties; +// +//import org.apache.logging.log4j.LogManager; +//import org.apache.logging.log4j.Logger; +// +//import com.cybersource.authsdk.core.Authorization; +//import com.cybersource.authsdk.core.MerchantConfig; +//import com.cybersource.authsdk.util.GlobalLabelParameters; +//import com.cybersource.authsdk.util.Utility; +// +//import samples.authentication.harness.MerchantProperties; /** * This class generates the Headers that are present in the token was sent the server for transaction, * GET operations. * * */ -public class GetGenerateHeaders { - - private Properties merchantProp; - private MerchantConfig merchantConfig; - private String authenticationType = null; - private Authorization auth; - private Logger logger; - private String tempSig; - - public static void WriteLogAudit(int status) { - String filename = MethodHandles.lookup().lookupClass().getSimpleName(); - System.out.println("[Sample Code Testing] [" + filename + "] " + status); - } +//public class GetGenerateHeaders { +// +// private Properties merchantProp; +// private MerchantConfig merchantConfig; +// private String authenticationType = null; +// private Authorization auth; +// private Logger logger; +// private String tempSig; +// +// public static void WriteLogAudit(int status) { +// String filename = MethodHandles.lookup().lookupClass().getSimpleName(); +// System.out.println("[Sample Code Testing] [" + filename + "] " + status); +// } /** * DATE * [Non-Editable] */ - private String date = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneId.of("GMT"))); + //private String date = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneId.of("GMT"))); /** * REQUEST - TYPE * [Non-Editable] * */ - private String requestType = "GET"; + //private String requestType = "GET"; /** * * UNQUIE GetID * [Editable] */ - private String getID = "5265502011846829204101"; + //private String getID = "5265502011846829204101"; /** * @@ -61,11 +61,11 @@ public static void WriteLogAudit(int status) { * @throws Exception * : */ - public GetGenerateHeaders(String requestTarget) throws Exception { - setGenerateHeaders(); - this.getID = Utility.retrieveGetIDFromRequestTarget(requestTarget); - generateGetHeaders(); - } +// public GetGenerateHeaders(String requestTarget) throws Exception { +// setGenerateHeaders(); +// this.getID = Utility.retrieveGetIDFromRequestTarget(requestTarget); +// generateGetHeaders(); +// } /** * @@ -73,40 +73,40 @@ public GetGenerateHeaders(String requestTarget) throws Exception { * : this object contains all the cybs.properites details. * @throws Exception */ - public GetGenerateHeaders(MerchantConfig merchantConfig) throws Exception { - this.merchantConfig = merchantConfig; - - // merchantConfig.setGetID(getID); - merchantConfig.setRequestType(requestType); - - this.logger = LogManager.getLogger(getClass()); - - auth = new Authorization(); - generateGetHeaders(); - - this.logger.info(GlobalLabelParameters.END_TRANSACTION + "\n"); - } - - public GetGenerateHeaders() throws Exception { - setGenerateHeaders(); - - System.out.println("Authentication Type : " + merchantConfig.getAuthenticationType().trim()); - this.logger.info(GlobalLabelParameters.BEGIN_TRANSACTION + "\n******************* Generate GET Headers *******************"); - - merchantConfig.validateMerchantDetails(); - generateGetHeaders(); - - this.logger.info(GlobalLabelParameters.END_TRANSACTION + "\n"); - } - - private void setGenerateHeaders() throws Exception { - merchantProp = MerchantProperties.getMerchantProperties(); - merchantConfig = new MerchantConfig(merchantProp); - authenticationType = merchantConfig.getAuthenticationType().trim(); - merchantConfig.setRequestType(requestType); - this.logger = LogManager.getLogger(getClass()); - auth = new Authorization(); - } +// public GetGenerateHeaders(MerchantConfig merchantConfig) throws Exception { +// this.merchantConfig = merchantConfig; +// +// // merchantConfig.setGetID(getID); +// merchantConfig.setRequestType(requestType); +// +// this.logger = LogManager.getLogger(getClass()); +// +// auth = new Authorization(); +// generateGetHeaders(); +// +// this.logger.info(GlobalLabelParameters.END_TRANSACTION + "\n"); +// } + +// public GetGenerateHeaders() throws Exception { +// setGenerateHeaders(); +// +// System.out.println("Authentication Type : " + merchantConfig.getAuthenticationType().trim()); +// this.logger.info(GlobalLabelParameters.BEGIN_TRANSACTION + "\n******************* Generate GET Headers *******************"); +// +// merchantConfig.validateMerchantDetails(); +// generateGetHeaders(); +// +// this.logger.info(GlobalLabelParameters.END_TRANSACTION + "\n"); +// } +// +// private void setGenerateHeaders() throws Exception { +// merchantProp = MerchantProperties.getMerchantProperties(); +// merchantConfig = new MerchantConfig(merchantProp); +// authenticationType = merchantConfig.getAuthenticationType().trim(); +// merchantConfig.setRequestType(requestType); +// this.logger = LogManager.getLogger(getClass()); +// auth = new Authorization(); +// } /** * This method generates the detailed header detail of the transaction and @@ -115,41 +115,41 @@ private void setGenerateHeaders() throws Exception { * @throws Exception * : Throws runtime exception. */ - private void generateGetHeaders() throws Exception { - authenticationType = merchantConfig.getAuthenticationType().trim(); - - this.logger.info(GlobalLabelParameters.AUTENTICATION_TYPE + authenticationType); - this.logger.info(GlobalLabelParameters.REQUEST_TYPE + " : " + requestType); - this.logger.info(GlobalLabelParameters.DATE + " : " + date); - this.logger.info(GlobalLabelParameters.V_C_MERCHANTID + " : " + merchantConfig.getMerchantID().trim()); - this.logger.info(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); - this.logger.info(GlobalLabelParameters.HOST + " : " + merchantConfig.getRequestHost()); - this.logger.info(GlobalLabelParameters.GET + "_ID : " + this.getID); - this.logger.info(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); - - System.out.println("Request Type : " + requestType); - System.out.println("ID : " + this.getID); - System.out.println("Date : " + date); - System.out.println("MerchantID : " + merchantConfig.getMerchantID().trim()); - System.out.println("HOST : " + merchantConfig.getRequestHost()); - System.out.println(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); - - if (authenticationType.equalsIgnoreCase(GlobalLabelParameters.HTTP)) { - System.out.println(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); - this.logger.info(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); - - tempSig = auth.getToken(merchantConfig); - System.out.println("Signature : " + tempSig.toString()); - WriteLogAudit(200); - - } else { - String jwtRequestBody = getID; - auth.setJWTRequestBody(jwtRequestBody); - tempSig = auth.getToken(merchantConfig); - System.out.println("Authorization, Bearer " + tempSig.toString()); - WriteLogAudit(200); - } - } +// private void generateGetHeaders() throws Exception { +// authenticationType = merchantConfig.getAuthenticationType().trim(); +// +// this.logger.info(GlobalLabelParameters.AUTENTICATION_TYPE + authenticationType); +// this.logger.info(GlobalLabelParameters.REQUEST_TYPE + " : " + requestType); +// this.logger.info(GlobalLabelParameters.DATE + " : " + date); +// this.logger.info(GlobalLabelParameters.V_C_MERCHANTID + " : " + merchantConfig.getMerchantID().trim()); +// this.logger.info(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); +// this.logger.info(GlobalLabelParameters.HOST + " : " + merchantConfig.getRequestHost()); +// this.logger.info(GlobalLabelParameters.GET + "_ID : " + this.getID); +// this.logger.info(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); +// +// System.out.println("Request Type : " + requestType); +// System.out.println("ID : " + this.getID); +// System.out.println("Date : " + date); +// System.out.println("MerchantID : " + merchantConfig.getMerchantID().trim()); +// System.out.println("HOST : " + merchantConfig.getRequestHost()); +// System.out.println(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); +// +// if (authenticationType.equalsIgnoreCase(GlobalLabelParameters.HTTP)) { +// System.out.println(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); +// this.logger.info(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); +// +// tempSig = auth.getToken(merchantConfig); +// System.out.println("Signature : " + tempSig.toString()); +// WriteLogAudit(200); +// +// } else { +// String jwtRequestBody = getID; +// auth.setJWTRequestBody(jwtRequestBody); +// tempSig = auth.getToken(merchantConfig); +// System.out.println("Authorization, Bearer " + tempSig.toString()); +// WriteLogAudit(200); +// } +// } /** * @@ -157,7 +157,7 @@ private void generateGetHeaders() throws Exception { * : Contains getId entry. * @throws Exception */ - public static void main(String[] args) throws Exception { - new GetGenerateHeaders(); - } -} +// public static void main(String[] args) throws Exception { +// new GetGenerateHeaders(); +// } +//} diff --git a/src/main/java/samples/authentication/AuthSampleCode/GetMethod.java b/src/main/java/samples/authentication/AuthSampleCode/GetMethod.java index 5bcb85a..726a300 100644 --- a/src/main/java/samples/authentication/AuthSampleCode/GetMethod.java +++ b/src/main/java/samples/authentication/AuthSampleCode/GetMethod.java @@ -1,86 +1,86 @@ -package samples.authentication.AuthSampleCode; +//package samples.authentication.AuthSampleCode; +// +//import java.lang.invoke.MethodHandles; +//import java.util.Properties; +// +//import org.apache.commons.lang3.StringUtils; +// +//import com.cybersource.apisdk.controller.ApiController; +//import com.cybersource.apisdk.model.Response; +//import com.cybersource.authsdk.core.MerchantConfig; +// +//import samples.authentication.harness.MerchantProperties; -import java.lang.invoke.MethodHandles; -import java.util.Properties; +//public class GetMethod { +// private ApiController apiController; +// private Properties merchantProp; +// private MerchantConfig merchantConfig; +// private Response response; +// private String authenticationType; -import org.apache.commons.lang3.StringUtils; - -import com.cybersource.apisdk.controller.ApiController; -import com.cybersource.apisdk.model.Response; -import com.cybersource.authsdk.core.MerchantConfig; - -import samples.authentication.harness.MerchantProperties; - -public class GetMethod { - private ApiController apiController; - private Properties merchantProp; - private MerchantConfig merchantConfig; - private Response response; - private String authenticationType; - /** * REQUEST TARGET / UNIQUE GET ID [Editable] */ - private String requestTarget = "/pts/v2/payments/6065710300556203803003"; - - public static void WriteLogAudit(int status) { - String filename = MethodHandles.lookup().lookupClass().getSimpleName(); - System.out.println("[Sample Code Testing] [" + filename + "] " + status); - } +// private String requestTarget = "/pts/v2/payments/6065710300556203803003"; +// +// public static void WriteLogAudit(int status) { +// String filename = MethodHandles.lookup().lookupClass().getSimpleName(); +// System.out.println("[Sample Code Testing] [" + filename + "] " + status); +// } /** * REQUEST-TYPE. [Non-Editable] */ - private String requestType = "GET"; - - private String url; - - /* This method initiates or begins the process. */ - public static void main(String args[]) throws Exception { - new GetMethod(); - } +// private String requestType = "GET"; +// +// private String url; +// +// /* This method initiates or begins the process. */ +// public static void main(String args[]) throws Exception { +// new GetMethod(); +// } /** * * @throws Exception * : Throws runtime exceptions. */ - public GetMethod() throws Exception { - apiController = new ApiController(); - - merchantProp = MerchantProperties.getMerchantProperties(); - merchantConfig = new MerchantConfig(merchantProp); - merchantConfig.setRequestType(requestType); - authenticationType = merchantConfig.getAuthenticationType().trim(); - merchantConfig.setRequestTarget(requestTarget); - url = "https://" + merchantConfig.getRequestHost() + merchantConfig.getRequestTarget(); - /* Begin the Get process. */ - process(); - } +// public GetMethod() throws Exception { +// apiController = new ApiController(); +// +// merchantProp = MerchantProperties.getMerchantProperties(); +// merchantConfig = new MerchantConfig(merchantProp); +// merchantConfig.setRequestType(requestType); +// authenticationType = merchantConfig.getAuthenticationType().trim(); +// merchantConfig.setRequestTarget(requestTarget); +// url = "https://" + merchantConfig.getRequestHost() + merchantConfig.getRequestTarget(); +// /* Begin the Get process. */ +// process(); +// } /** * */ - private void process() { - System.out.println(authenticationType.toUpperCase() + " Request"); - - try { - response = apiController.paymentGet(merchantConfig); - WriteLogAudit(Integer.parseInt(response.getResponseCode())); - - if (!StringUtils.isBlank(response.getResponseCode())&& !StringUtils.isBlank(response.getResponseMessage())) { - new GetGenerateHeaders(requestTarget); - System.out.println(" URL : " + url); - System.out.println(" Response Code : " + response.getResponseCode()); - System.out.println(" V-C-Corealation ID : " + response.getVcCorelationId()); - System.out.println(" Response Message : " + response.getResponseMessage()); - } - else { - System.out.println(response.getResponseMessage()); - } - } catch (Exception e) { - System.out.println(e.getMessage()); - WriteLogAudit(400); - } - } -} +// private void process() { +// System.out.println(authenticationType.toUpperCase() + " Request"); +// +// try { +// response = apiController.paymentGet(merchantConfig); +// WriteLogAudit(Integer.parseInt(response.getResponseCode())); +// +// if (!StringUtils.isBlank(response.getResponseCode())&& !StringUtils.isBlank(response.getResponseMessage())) { +// new GetGenerateHeaders(requestTarget); +// System.out.println(" URL : " + url); +// System.out.println(" Response Code : " + response.getResponseCode()); +// System.out.println(" V-C-Corealation ID : " + response.getVcCorelationId()); +// System.out.println(" Response Message : " + response.getResponseMessage()); +// } +// else { +// System.out.println(response.getResponseMessage()); +// } +// } catch (Exception e) { +// System.out.println(e.getMessage()); +// WriteLogAudit(400); +// } +// } +//} diff --git a/src/main/java/samples/authentication/AuthSampleCode/GetObjectMethod.java b/src/main/java/samples/authentication/AuthSampleCode/GetObjectMethod.java index bd90f41..6918a6f 100644 --- a/src/main/java/samples/authentication/AuthSampleCode/GetObjectMethod.java +++ b/src/main/java/samples/authentication/AuthSampleCode/GetObjectMethod.java @@ -1,83 +1,83 @@ -package samples.authentication.AuthSampleCode; - -import java.lang.invoke.MethodHandles; -import java.util.Properties; - -import org.apache.commons.lang3.StringUtils; - -import com.cybersource.apisdk.controller.ApiController; -import com.cybersource.apisdk.model.Response; -import com.cybersource.authsdk.core.MerchantConfig; - -import samples.authentication.Data.Configuration; - -public class GetObjectMethod { - private ApiController apiController; - private String authenticationType; - private Properties merchantProp; - private MerchantConfig merchantConfig; - private Response response; +//package samples.authentication.AuthSampleCode; +// +//import java.lang.invoke.MethodHandles; +//import java.util.Properties; +// +//import org.apache.commons.lang3.StringUtils; +// +//import com.cybersource.apisdk.controller.ApiController; +//import com.cybersource.apisdk.model.Response; +//import com.cybersource.authsdk.core.MerchantConfig; +// +//import samples.authentication.Data.Configuration; +// +//public class GetObjectMethod { +// private ApiController apiController; +// private String authenticationType; +// private Properties merchantProp; +// private MerchantConfig merchantConfig; +// private Response response; /** * REQUEST TARGET [Editable] */ - private String requestTarget = "/pts/v2/payments/6040716095406990004003"; - /* Request Type [Non-Editable.] */ - private String requestType = "GET"; - /* [Non Editable] */ - private String url; - - public static void WriteLogAudit(int status) { - String filename = MethodHandles.lookup().lookupClass().getSimpleName(); - System.out.println("[Sample Code Testing] [" + filename + "] " + status); - } - - /* This method initiates or begins the process. */ - public static void main(String[] args) throws Exception { - new GetObjectMethod(); - } +// private String requestTarget = "/pts/v2/payments/6040716095406990004003"; +// /* Request Type [Non-Editable.] */ +// private String requestType = "GET"; +// /* [Non Editable] */ +// private String url; +// +// public static void WriteLogAudit(int status) { +// String filename = MethodHandles.lookup().lookupClass().getSimpleName(); +// System.out.println("[Sample Code Testing] [" + filename + "] " + status); +// } +// +// /* This method initiates or begins the process. */ +// public static void main(String[] args) throws Exception { +// new GetObjectMethod(); +// } /** * @throws Exception */ - public GetObjectMethod() throws Exception { - apiController = new ApiController(); - /* Read Merchant details. */ - merchantProp = Configuration.getMerchantDetails(); - merchantConfig = new MerchantConfig(merchantProp); - /* Set Request Type */ - merchantConfig.setRequestType(requestType); - /* Extract Authentication Type from cybs.properties */ - authenticationType = merchantConfig.getAuthenticationType().trim(); - merchantConfig.setRequestTarget(requestTarget); - /* Construct the URL with respect to GETID. */ - url = "https://" + merchantConfig.getRequestHost() + merchantConfig.getRequestTarget(); - /* Begin the Get process. */ - process(); - } +// public GetObjectMethod() throws Exception { +// apiController = new ApiController(); +// /* Read Merchant details. */ +// merchantProp = Configuration.getMerchantDetails(); +// merchantConfig = new MerchantConfig(merchantProp); +// /* Set Request Type */ +// merchantConfig.setRequestType(requestType); +// /* Extract Authentication Type from cybs.properties */ +// authenticationType = merchantConfig.getAuthenticationType().trim(); +// merchantConfig.setRequestTarget(requestTarget); +// /* Construct the URL with respect to GETID. */ +// url = "https://" + merchantConfig.getRequestHost() + merchantConfig.getRequestTarget(); +// /* Begin the Get process. */ +// process(); +// } /** * Calls the APISDK for processing the payment request. * * @throws Exception */ - private void process() { - System.out.println(authenticationType.toUpperCase() + " Request"); - - try { - /* Calling APISDK, com.cybersouce.api.controller. */ - response = apiController.paymentGet(merchantConfig); - WriteLogAudit(Integer.parseInt(response.getResponseCode())); - /* Display response message and Headers in console. */ - if (!StringUtils.isBlank(response.getResponseCode()) && !StringUtils.isBlank(response.getResponseMessage())) { - new GetGenerateHeaders(merchantConfig); - System.out.println("URL : " + url); - System.out.println("Response Code : " + response.getResponseCode()); - System.out.println("V-C-Corealation ID : " + response.getVcCorelationId()); - System.out.println("Response Message : " + response.getResponseMessage()); - } - } catch (Exception e) { - System.out.println(e.getMessage()); - WriteLogAudit(400); - } - } -} +// private void process() { +// System.out.println(authenticationType.toUpperCase() + " Request"); +// +// try { +// /* Calling APISDK, com.cybersouce.api.controller. */ +// response = apiController.paymentGet(merchantConfig); +// WriteLogAudit(Integer.parseInt(response.getResponseCode())); +// /* Display response message and Headers in console. */ +// if (!StringUtils.isBlank(response.getResponseCode()) && !StringUtils.isBlank(response.getResponseMessage())) { +// new GetGenerateHeaders(merchantConfig); +// System.out.println("URL : " + url); +// System.out.println("Response Code : " + response.getResponseCode()); +// System.out.println("V-C-Corealation ID : " + response.getVcCorelationId()); +// System.out.println("Response Message : " + response.getResponseMessage()); +// } +// } catch (Exception e) { +// System.out.println(e.getMessage()); +// WriteLogAudit(400); +// } +// } +//} diff --git a/src/main/java/samples/authentication/AuthSampleCode/PostGenerateHeaders.java b/src/main/java/samples/authentication/AuthSampleCode/PostGenerateHeaders.java index 9dda426..da78acf 100644 --- a/src/main/java/samples/authentication/AuthSampleCode/PostGenerateHeaders.java +++ b/src/main/java/samples/authentication/AuthSampleCode/PostGenerateHeaders.java @@ -1,132 +1,132 @@ -package samples.authentication.AuthSampleCode; - -import java.lang.invoke.MethodHandles; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Properties; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.cybersource.authsdk.core.Authorization; -import com.cybersource.authsdk.core.MerchantConfig; -import com.cybersource.authsdk.payloaddigest.PayloadDigest; -import com.cybersource.authsdk.util.GlobalLabelParameters; -import samples.authentication.harness.MerchantProperties; +//package samples.authentication.AuthSampleCode; +// +//import java.lang.invoke.MethodHandles; +//import java.time.ZoneId; +//import java.time.ZonedDateTime; +//import java.time.format.DateTimeFormatter; +//import java.util.Properties; +// +//import org.apache.logging.log4j.LogManager; +//import org.apache.logging.log4j.Logger; +// +//import com.cybersource.authsdk.core.Authorization; +//import com.cybersource.authsdk.core.MerchantConfig; +//import com.cybersource.authsdk.payloaddigest.PayloadDigest; +//import com.cybersource.authsdk.util.GlobalLabelParameters; +//import samples.authentication.harness.MerchantProperties; /** * This class generates the Headers that are present in the token was sent the * server for transaction, for POST operation. * */ -public class PostGenerateHeaders { - private Properties merchantProp; - private MerchantConfig merchantConfig; - private String authenticationType = null; - private Authorization auth; - private PayloadDigest digest; - private Logger logger = null; - private String tempSig; +//public class PostGenerateHeaders { +// private Properties merchantProp; +// private MerchantConfig merchantConfig; +// private String authenticationType = null; +// private Authorization auth; +// private PayloadDigest digest; +// private Logger logger = null; +// private String tempSig; /** * DATE GMT [Non - Editable] * */ - private String date = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneId.of("GMT"))); - - public static void WriteLogAudit(int status) { - String filename = MethodHandles.lookup().lookupClass().getSimpleName(); - System.out.println("[Sample Code Testing] [" + filename + "] " + status); - } - +// private String date = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneId.of("GMT"))); +// +// public static void WriteLogAudit(int status) { +// String filename = MethodHandles.lookup().lookupClass().getSimpleName(); +// System.out.println("[Sample Code Testing] [" + filename + "] " + status); +// } +// /** * REQUEST - TYPE [Non-Editable] * */ - private String requestType = "POST"; - - private String requestJson = "{\r\n" + - " \"clientReferenceInformation\": {\r\n" + - " \"code\": \"TC50171_3\"\r\n" + - " },\r\n" + - " \"processingInformation\": {\r\n" + - " \"commerceIndicator\": \"internet\"\r\n" + - " },\r\n" + - " \"aggregatorInformation\": {\r\n" + - " \"subMerchant\": {\r\n" + - " \"cardAcceptorID\": \"1234567890\",\r\n" + - " \"country\": \"US\",\r\n" + - " \"phoneNumber\": \"650-432-0000\",\r\n" + - " \"address1\": \"900 Metro Center\",\r\n" + - " \"postalCode\": \"94404-2775\",\r\n" + - " \"locality\": \"Foster City\",\r\n" + - " \"name\": \"Visa Inc\",\r\n" + - " \"administrativeArea\": \"CA\",\r\n" + - " \"region\": \"PEN\",\r\n" + - " \"email\": \"test@cybs.com\"\r\n" + - " },\r\n" + - " \"name\": \"V-Internatio\",\r\n" + - " \"aggregatorID\": \"123456789\"\r\n" + - " },\r\n" + - " \"orderInformation\": {\r\n" + - " \"billTo\": {\r\n" + - " \"country\": \"US\",\r\n" + - " \"lastName\": \"VDP\",\r\n" + - " \"address2\": \"Address 2\",\r\n" + - " \"address1\": \"201 S. Division St.\",\r\n" + - " \"postalCode\": \"48104-2201\",\r\n" + - " \"locality\": \"Ann Arbor\",\r\n" + - " \"administrativeArea\": \"MI\",\r\n" + - " \"firstName\": \"RTS\",\r\n" + - " \"phoneNumber\": \"999999999\",\r\n" + - " \"district\": \"MI\",\r\n" + - " \"buildingNumber\": \"123\",\r\n" + - " \"company\": \"Visa\",\r\n" + - " \"email\": \"test@cybs.com\"\r\n" + - " },\r\n" + - " \"amountDetails\": {\r\n" + - " \"totalAmount\": \"102.21\",\r\n" + - " \"currency\": \"USD\"\r\n" + - " }\r\n" + - " },\r\n" + - " \"paymentInformation\": {\r\n" + - " \"card\": {\r\n" + - " \"expirationYear\": \"2031\",\r\n" + - " \"number\": \"5555555555554444\",\r\n" + - " \"securityCode\": \"123\",\r\n" + - " \"expirationMonth\": \"12\",\r\n" + - " \"type\": \"002\"\r\n" + - " }\r\n" + - " }\r\n" + - "}"; +// private String requestType = "POST"; +// +// private String requestJson = "{\r\n" + +// " \"clientReferenceInformation\": {\r\n" + +// " \"code\": \"TC50171_3\"\r\n" + +// " },\r\n" + +// " \"processingInformation\": {\r\n" + +// " \"commerceIndicator\": \"internet\"\r\n" + +// " },\r\n" + +// " \"aggregatorInformation\": {\r\n" + +// " \"subMerchant\": {\r\n" + +// " \"cardAcceptorID\": \"1234567890\",\r\n" + +// " \"country\": \"US\",\r\n" + +// " \"phoneNumber\": \"650-432-0000\",\r\n" + +// " \"address1\": \"900 Metro Center\",\r\n" + +// " \"postalCode\": \"94404-2775\",\r\n" + +// " \"locality\": \"Foster City\",\r\n" + +// " \"name\": \"Visa Inc\",\r\n" + +// " \"administrativeArea\": \"CA\",\r\n" + +// " \"region\": \"PEN\",\r\n" + +// " \"email\": \"test@cybs.com\"\r\n" + +// " },\r\n" + +// " \"name\": \"V-Internatio\",\r\n" + +// " \"aggregatorID\": \"123456789\"\r\n" + +// " },\r\n" + +// " \"orderInformation\": {\r\n" + +// " \"billTo\": {\r\n" + +// " \"country\": \"US\",\r\n" + +// " \"lastName\": \"VDP\",\r\n" + +// " \"address2\": \"Address 2\",\r\n" + +// " \"address1\": \"201 S. Division St.\",\r\n" + +// " \"postalCode\": \"48104-2201\",\r\n" + +// " \"locality\": \"Ann Arbor\",\r\n" + +// " \"administrativeArea\": \"MI\",\r\n" + +// " \"firstName\": \"RTS\",\r\n" + +// " \"phoneNumber\": \"999999999\",\r\n" + +// " \"district\": \"MI\",\r\n" + +// " \"buildingNumber\": \"123\",\r\n" + +// " \"company\": \"Visa\",\r\n" + +// " \"email\": \"test@cybs.com\"\r\n" + +// " },\r\n" + +// " \"amountDetails\": {\r\n" + +// " \"totalAmount\": \"102.21\",\r\n" + +// " \"currency\": \"USD\"\r\n" + +// " }\r\n" + +// " },\r\n" + +// " \"paymentInformation\": {\r\n" + +// " \"card\": {\r\n" + +// " \"expirationYear\": \"2031\",\r\n" + +// " \"number\": \"5555555555554444\",\r\n" + +// " \"securityCode\": \"123\",\r\n" + +// " \"expirationMonth\": \"12\",\r\n" + +// " \"type\": \"002\"\r\n" + +// " }\r\n" + +// " }\r\n" + +// "}"; /** * * @throws Exception * : Error while generating headers. */ - public PostGenerateHeaders() throws Exception { - merchantProp = MerchantProperties.getMerchantProperties(); - merchantConfig = new MerchantConfig(merchantProp); - this.logger = LogManager.getLogger(getClass()); - System.out.println("Authentication Type : " + merchantConfig.getAuthenticationType().trim()); - this.logger.info(GlobalLabelParameters.BEGIN_TRANSACTION + "\n******************* Generate POST Headers *******************"); - - merchantConfig.setRequestType(requestType); - merchantConfig.setRequestData(requestJson); - - digest = new PayloadDigest(this.merchantConfig); - boolean isMerchant = merchantConfig.validateMerchantDetails(); - - auth = new Authorization(); - digest = new PayloadDigest(merchantConfig); - if (isMerchant) { - generatePostHeaders(); - } - - this.logger.info(GlobalLabelParameters.END_TRANSACTION + "\n"); - } +// public PostGenerateHeaders() throws Exception { +// merchantProp = MerchantProperties.getMerchantProperties(); +// merchantConfig = new MerchantConfig(merchantProp); +// this.logger = LogManager.getLogger(getClass()); +// System.out.println("Authentication Type : " + merchantConfig.getAuthenticationType().trim()); +// this.logger.info(GlobalLabelParameters.BEGIN_TRANSACTION + "\n******************* Generate POST Headers *******************"); +// +// merchantConfig.setRequestType(requestType); +// merchantConfig.setRequestData(requestJson); +// +// digest = new PayloadDigest(this.merchantConfig); +// boolean isMerchant = merchantConfig.validateMerchantDetails(); +// +// auth = new Authorization(); +// digest = new PayloadDigest(merchantConfig); +// if (isMerchant) { +// generatePostHeaders(); +// } +// +// this.logger.info(GlobalLabelParameters.END_TRANSACTION + "\n"); +// } /** * @@ -134,13 +134,13 @@ public PostGenerateHeaders() throws Exception { * : this object contains all the cybs.properites details. * @throws Exception */ - public PostGenerateHeaders(MerchantConfig merchantConfig) throws Exception { - this.merchantConfig = merchantConfig; - auth = new Authorization(); - logger = LogManager.getLogger(getClass()); - digest = new PayloadDigest(this.merchantConfig); - generatePostHeaders(); - } +// public PostGenerateHeaders(MerchantConfig merchantConfig) throws Exception { +// this.merchantConfig = merchantConfig; +// auth = new Authorization(); +// logger = LogManager.getLogger(getClass()); +// digest = new PayloadDigest(this.merchantConfig); +// generatePostHeaders(); +// } /** * This method generates, displays and log the detailed header truncation @@ -148,41 +148,41 @@ public PostGenerateHeaders(MerchantConfig merchantConfig) throws Exception { * * @throws Exception */ - private void generatePostHeaders() throws Exception { - authenticationType = merchantConfig.getAuthenticationType().trim(); - - this.logger.info(GlobalLabelParameters.AUTENTICATION_TYPE + authenticationType); - this.logger.info(GlobalLabelParameters.REQUEST_TYPE + " : " + requestType); - this.logger.info(GlobalLabelParameters.DATE + " : " + date); - this.logger.info(GlobalLabelParameters.V_C_MERCHANTID + " : " + merchantConfig.getMerchantID().trim()); - this.logger.info(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); - this.logger.info(GlobalLabelParameters.HOST + " : " + merchantConfig.getRequestHost()); - - System.out.println(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); - System.out.println("MerchantID : " + merchantConfig.getMerchantID().trim()); - System.out.println("Date : " + date); - System.out.println("Request Type : " + requestType); - System.out.println("HOST : " + merchantConfig.getRequestHost()); - - if (authenticationType.equalsIgnoreCase(GlobalLabelParameters.HTTP)) { - System.out.println(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); - this.logger.info(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); - - System.out.println("Digest : " + digest.getDigest()); - - tempSig = auth.getToken(merchantConfig); - System.out.println("Signature : " + tempSig.toString()); - WriteLogAudit(200); - - } else { - auth.setJWTRequestBody(requestJson); - tempSig = auth.getToken(merchantConfig); - System.out.println("Authorization, Bearer " + tempSig.toString()); - WriteLogAudit(200); - } - } - - public static void main(String[] args) throws Exception { - new PostGenerateHeaders(); - } -} +// private void generatePostHeaders() throws Exception { +// authenticationType = merchantConfig.getAuthenticationType().trim(); +// +// this.logger.info(GlobalLabelParameters.AUTENTICATION_TYPE + authenticationType); +// this.logger.info(GlobalLabelParameters.REQUEST_TYPE + " : " + requestType); +// this.logger.info(GlobalLabelParameters.DATE + " : " + date); +// this.logger.info(GlobalLabelParameters.V_C_MERCHANTID + " : " + merchantConfig.getMerchantID().trim()); +// this.logger.info(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); +// this.logger.info(GlobalLabelParameters.HOST + " : " + merchantConfig.getRequestHost()); +// +// System.out.println(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); +// System.out.println("MerchantID : " + merchantConfig.getMerchantID().trim()); +// System.out.println("Date : " + date); +// System.out.println("Request Type : " + requestType); +// System.out.println("HOST : " + merchantConfig.getRequestHost()); +// +// if (authenticationType.equalsIgnoreCase(GlobalLabelParameters.HTTP)) { +// System.out.println(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); +// this.logger.info(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); +// +// System.out.println("Digest : " + digest.getDigest()); +// +// tempSig = auth.getToken(merchantConfig); +// System.out.println("Signature : " + tempSig.toString()); +// WriteLogAudit(200); +// +// } else { +// auth.setJWTRequestBody(requestJson); +// tempSig = auth.getToken(merchantConfig); +// System.out.println("Authorization, Bearer " + tempSig.toString()); +// WriteLogAudit(200); +// } +// } +// +// public static void main(String[] args) throws Exception { +// new PostGenerateHeaders(); +// } +//} diff --git a/src/main/java/samples/authentication/AuthSampleCode/PostMethod.java b/src/main/java/samples/authentication/AuthSampleCode/PostMethod.java index ff09535..e995f5c 100644 --- a/src/main/java/samples/authentication/AuthSampleCode/PostMethod.java +++ b/src/main/java/samples/authentication/AuthSampleCode/PostMethod.java @@ -1,151 +1,151 @@ -package samples.authentication.AuthSampleCode; - -import java.lang.invoke.MethodHandles; -import java.util.Properties; - -import org.apache.commons.lang3.StringUtils; - -import com.cybersource.apisdk.controller.ApiController; -import com.cybersource.apisdk.model.Response; -import com.cybersource.authsdk.core.MerchantConfig; - -import samples.authentication.harness.MerchantProperties; +//package samples.authentication.AuthSampleCode; +// +//import java.lang.invoke.MethodHandles; +//import java.util.Properties; +// +//import org.apache.commons.lang3.StringUtils; +// +//import com.cybersource.apisdk.controller.ApiController; +//import com.cybersource.apisdk.model.Response; +//import com.cybersource.authsdk.core.MerchantConfig; +// +//import samples.authentication.harness.MerchantProperties; /** * Depending on the authentication type HTTP or JWT , this class performs the * POST operation on the test url 'apitest.cybersource.com'. - * + * */ -public class PostMethod { - private ApiController apiController; - private String authenticationType; - private Properties merchantProp; - private MerchantConfig merchantConfig; - private Response responseObj; - - public static void WriteLogAudit(int status) { - String filename = MethodHandles.lookup().lookupClass().getSimpleName(); - System.out.println("[Sample Code Testing] [" + filename + "] " + status); - } +//public class PostMethod { +// private ApiController apiController; +// private String authenticationType; +// private Properties merchantProp; +// private MerchantConfig merchantConfig; +// private Response responseObj; +// +// public static void WriteLogAudit(int status) { +// String filename = MethodHandles.lookup().lookupClass().getSimpleName(); +// System.out.println("[Sample Code Testing] [" + filename + "] " + status); +// } /** * REQUEST TARGET [Editable] */ - private String requestTarget = "/pts/v2/payments/"; - private String requestJson = "{\r\n" + - " \"clientReferenceInformation\": {\r\n" + - " \"code\": \"TC50171_3\"\r\n" + - " },\r\n" + - " \"processingInformation\": {\r\n" + - " \"commerceIndicator\": \"internet\"\r\n" + - " },\r\n" + - " \"aggregatorInformation\": {\r\n" + - " \"subMerchant\": {\r\n" + - " \"cardAcceptorID\": \"1234567890\",\r\n" + - " \"country\": \"US\",\r\n" + - " \"phoneNumber\": \"650-432-0000\",\r\n" + - " \"address1\": \"900 Metro Center\",\r\n" + - " \"postalCode\": \"94404-2775\",\r\n" + - " \"locality\": \"Foster City\",\r\n" + - " \"name\": \"Visa Inc\",\r\n" + - " \"administrativeArea\": \"CA\",\r\n" + - " \"region\": \"PEN\",\r\n" + - " \"email\": \"test@cybs.com\"\r\n" + - " },\r\n" + - " \"name\": \"V-Internatio\",\r\n" + - " \"aggregatorID\": \"123456789\"\r\n" + - " },\r\n" + - " \"orderInformation\": {\r\n" + - " \"billTo\": {\r\n" + - " \"country\": \"US\",\r\n" + - " \"lastName\": \"VDP\",\r\n" + - " \"address2\": \"Address 2\",\r\n" + - " \"address1\": \"201 S. Division St.\",\r\n" + - " \"postalCode\": \"48104-2201\",\r\n" + - " \"locality\": \"Ann Arbor\",\r\n" + - " \"administrativeArea\": \"MI\",\r\n" + - " \"firstName\": \"RTS\",\r\n" + - " \"phoneNumber\": \"999999999\",\r\n" + - " \"district\": \"MI\",\r\n" + - " \"buildingNumber\": \"123\",\r\n" + - " \"company\": \"Visa\",\r\n" + - " \"email\": \"test@cybs.com\"\r\n" + - " },\r\n" + - " \"amountDetails\": {\r\n" + - " \"totalAmount\": \"102.21\",\r\n" + - " \"currency\": \"USD\"\r\n" + - " }\r\n" + - " },\r\n" + - " \"paymentInformation\": {\r\n" + - " \"card\": {\r\n" + - " \"expirationYear\": \"2031\",\r\n" + - " \"number\": \"5555555555554444\",\r\n" + - " \"securityCode\": \"123\",\r\n" + - " \"expirationMonth\": \"12\",\r\n" + - " \"type\": \"002\"\r\n" + - " }\r\n" + - " }\r\n" + - "}"; +// private String requestTarget = "/pts/v2/payments/"; +// private String requestJson = "{\r\n" + +// " \"clientReferenceInformation\": {\r\n" + +// " \"code\": \"TC50171_3\"\r\n" + +// " },\r\n" + +// " \"processingInformation\": {\r\n" + +// " \"commerceIndicator\": \"internet\"\r\n" + +// " },\r\n" + +// " \"aggregatorInformation\": {\r\n" + +// " \"subMerchant\": {\r\n" + +// " \"cardAcceptorID\": \"1234567890\",\r\n" + +// " \"country\": \"US\",\r\n" + +// " \"phoneNumber\": \"650-432-0000\",\r\n" + +// " \"address1\": \"900 Metro Center\",\r\n" + +// " \"postalCode\": \"94404-2775\",\r\n" + +// " \"locality\": \"Foster City\",\r\n" + +// " \"name\": \"Visa Inc\",\r\n" + +// " \"administrativeArea\": \"CA\",\r\n" + +// " \"region\": \"PEN\",\r\n" + +// " \"email\": \"test@cybs.com\"\r\n" + +// " },\r\n" + +// " \"name\": \"V-Internatio\",\r\n" + +// " \"aggregatorID\": \"123456789\"\r\n" + +// " },\r\n" + +// " \"orderInformation\": {\r\n" + +// " \"billTo\": {\r\n" + +// " \"country\": \"US\",\r\n" + +// " \"lastName\": \"VDP\",\r\n" + +// " \"address2\": \"Address 2\",\r\n" + +// " \"address1\": \"201 S. Division St.\",\r\n" + +// " \"postalCode\": \"48104-2201\",\r\n" + +// " \"locality\": \"Ann Arbor\",\r\n" + +// " \"administrativeArea\": \"MI\",\r\n" + +// " \"firstName\": \"RTS\",\r\n" + +// " \"phoneNumber\": \"999999999\",\r\n" + +// " \"district\": \"MI\",\r\n" + +// " \"buildingNumber\": \"123\",\r\n" + +// " \"company\": \"Visa\",\r\n" + +// " \"email\": \"test@cybs.com\"\r\n" + +// " },\r\n" + +// " \"amountDetails\": {\r\n" + +// " \"totalAmount\": \"102.21\",\r\n" + +// " \"currency\": \"USD\"\r\n" + +// " }\r\n" + +// " },\r\n" + +// " \"paymentInformation\": {\r\n" + +// " \"card\": {\r\n" + +// " \"expirationYear\": \"2031\",\r\n" + +// " \"number\": \"5555555555554444\",\r\n" + +// " \"securityCode\": \"123\",\r\n" + +// " \"expirationMonth\": \"12\",\r\n" + +// " \"type\": \"002\"\r\n" + +// " }\r\n" + +// " }\r\n" + +// "}"; /** * REQUEST-TYPE. [Non-Editable] */ - private String requestType = "POST"; - private String url; +// private String requestType = "POST"; +// private String url; /* This method initiates or begins the process. */ - public static void main(String[] args) throws Exception { + //public static void main(String[] args) throws Exception { /** - * + * */ - new PostMethod(); - } + //new PostMethod(); +// } /** - * + * * @param * @return * @throws Exception */ - public PostMethod() throws Exception { - apiController = new ApiController(); +// public PostMethod() throws Exception { +// apiController = new ApiController(); +// +// merchantProp = MerchantProperties.getMerchantProperties(); +// merchantConfig = new MerchantConfig(merchantProp); +// authenticationType = merchantConfig.getAuthenticationType().trim(); +// merchantConfig.setRequestType(requestType); +// merchantConfig.setRequestData(requestJson); +// merchantConfig.setRequestTarget(requestTarget); +// +// url = "https://" + merchantConfig.getRequestHost() + merchantConfig.getRequestTarget(); - merchantProp = MerchantProperties.getMerchantProperties(); - merchantConfig = new MerchantConfig(merchantProp); - authenticationType = merchantConfig.getAuthenticationType().trim(); - merchantConfig.setRequestType(requestType); - merchantConfig.setRequestData(requestJson); - merchantConfig.setRequestTarget(requestTarget); - - url = "https://" + merchantConfig.getRequestHost() + merchantConfig.getRequestTarget(); - /* Begin Post process. */ - process(); - } +// process(); +// } /** * Calls the APISDK for processing the payment request. - * + * * @throws Exception */ - private void process() throws Exception { - System.out.println(authenticationType.toUpperCase() + " Request"); - try { - responseObj = apiController.paymentPost(merchantConfig); - WriteLogAudit(Integer.parseInt(responseObj.getResponseCode())); - - if (!StringUtils.isBlank(responseObj.getResponseCode()) - && !StringUtils.isBlank(responseObj.getResponseMessage())) { - new PostGenerateHeaders(merchantConfig); - System.out.println(" URL : " + url); - System.out.println(" Response Code : " + responseObj.getResponseCode()); - System.out.println(" v-c-Co-relation ID : " + responseObj.getVcCorelationId()); - System.out.println(" Response Message : " + responseObj.getResponseMessage()); - } else { - System.out.println(responseObj.getResponseMessage()); - } - } catch (Exception e) { - System.out.println(e.getMessage()); - WriteLogAudit(400); - } - } -} +// private void process() throws Exception { +// System.out.println(authenticationType.toUpperCase() + " Request"); +// try { +// responseObj = apiController.paymentPost(merchantConfig); +// WriteLogAudit(Integer.parseInt(responseObj.getResponseCode())); +// +// if (!StringUtils.isBlank(responseObj.getResponseCode()) +// && !StringUtils.isBlank(responseObj.getResponseMessage())) { +// new PostGenerateHeaders(merchantConfig); +// System.out.println(" URL : " + url); +// System.out.println(" Response Code : " + responseObj.getResponseCode()); +// System.out.println(" v-c-Co-relation ID : " + responseObj.getVcCorelationId()); +// System.out.println(" Response Message : " + responseObj.getResponseMessage()); +// } else { +// System.out.println(responseObj.getResponseMessage()); +// } +// } catch (Exception e) { +// System.out.println(e.getMessage()); +// WriteLogAudit(400); +// } +// } +//} diff --git a/src/main/java/samples/authentication/AuthSampleCode/PostObjectMethod.java b/src/main/java/samples/authentication/AuthSampleCode/PostObjectMethod.java index 03a6ad2..2aefd9c 100644 --- a/src/main/java/samples/authentication/AuthSampleCode/PostObjectMethod.java +++ b/src/main/java/samples/authentication/AuthSampleCode/PostObjectMethod.java @@ -1,54 +1,54 @@ -package samples.authentication.AuthSampleCode; - -import java.lang.invoke.MethodHandles; -import java.util.Properties; - -import org.apache.commons.lang3.StringUtils; - -import com.cybersource.apisdk.controller.ApiController; -import com.cybersource.apisdk.model.Response; -import com.cybersource.authsdk.core.MerchantConfig; -import samples.authentication.Data.Configuration; -import samples.authentication.Data.PayloadData; +//package samples.authentication.AuthSampleCode; +// +//import java.lang.invoke.MethodHandles; +//import java.util.Properties; +// +//import org.apache.commons.lang3.StringUtils; +// +//import com.cybersource.apisdk.controller.ApiController; +//import com.cybersource.apisdk.model.Response; +//import com.cybersource.authsdk.core.MerchantConfig; +//import samples.authentication.Data.Configuration; +//import samples.authentication.Data.PayloadData; /** * Depending on the authentication type HTTP or JWT , this class performs the * POST operation on the test url 'apitest.cybersource.com'. * */ -public class PostObjectMethod { - private ApiController apiController; - private String authenticationType; - private Properties merchantProp; - private MerchantConfig merchantConfig; - private Response response; +//public class PostObjectMethod { +// private ApiController apiController; +// private String authenticationType; +// private Properties merchantProp; +// private MerchantConfig merchantConfig; +// private Response response; /** * REQUEST-TYPE. [Non-Editable] */ - private String requestType = "POST"; - - private String url; - - private String requestData = PayloadData.readData(); - - public static void WriteLogAudit(int status) { - String filename = MethodHandles.lookup().lookupClass().getSimpleName(); - System.out.println("[Sample Code Testing] [" + filename + "] " + status); - } +// private String requestType = "POST"; +// +// private String url; +// +// private String requestData = PayloadData.readData(); +// +// public static void WriteLogAudit(int status) { +// String filename = MethodHandles.lookup().lookupClass().getSimpleName(); +// System.out.println("[Sample Code Testing] [" + filename + "] " + status); +// } /** * REQUEST TARGET [Editable] */ - private String requestTarget = "/pts/v2/payments"; + //private String requestTarget = "/pts/v2/payments"; /* This method initiates or begins the process. */ - public static void main(String[] args) throws Exception { + //public static void main(String[] args) throws Exception { /** * */ - new PostObjectMethod(); - } +// new PostObjectMethod(); +// } /** * @@ -56,42 +56,42 @@ public static void main(String[] args) throws Exception { * @return * @throws Exception */ - public PostObjectMethod() throws Exception { - apiController = new ApiController(); - merchantProp = Configuration.getMerchantDetails(); - merchantConfig = new MerchantConfig(merchantProp); - merchantConfig.setRequestType(requestType); - authenticationType = merchantConfig.getAuthenticationType().trim(); - merchantConfig.setRequestData(requestData); - merchantConfig.setRequestTarget(requestTarget); - - url = "https://" + merchantConfig.getRequestHost() + merchantConfig.getRequestTarget(); +// public PostObjectMethod() throws Exception { +// apiController = new ApiController(); +// merchantProp = Configuration.getMerchantDetails(); +// merchantConfig = new MerchantConfig(merchantProp); +// merchantConfig.setRequestType(requestType); +// authenticationType = merchantConfig.getAuthenticationType().trim(); +// merchantConfig.setRequestData(requestData); +// merchantConfig.setRequestTarget(requestTarget); +// +// url = "https://" + merchantConfig.getRequestHost() + merchantConfig.getRequestTarget(); /* Begin Post process. */ - process(); - } +// process(); +// } /** * Calls the APISDK for processing the payment request. * * @throws Exception */ - private void process() throws Exception { - System.out.println(authenticationType.toUpperCase() + " Request"); - try { - response = apiController.paymentPost(merchantConfig); - WriteLogAudit(Integer.parseInt(response.getResponseCode())); - - if (!StringUtils.isBlank(response.getResponseCode()) && !StringUtils.isBlank(response.getResponseMessage())) { - new PostGenerateHeaders(merchantConfig); - System.out.println(" URL : " + url); - System.out.println(" Response Code : " + response.getResponseCode()); - System.out.println(" v-c-Co-relation ID : " + response.getVcCorelationId()); - System.out.println(" Response Message : " + response.getResponseMessage()); - } - } catch (Exception e) { - System.out.println(e.getMessage()); - WriteLogAudit(400); - } - } -} +// private void process() throws Exception { +// System.out.println(authenticationType.toUpperCase() + " Request"); +// try { +// response = apiController.paymentPost(merchantConfig); +// WriteLogAudit(Integer.parseInt(response.getResponseCode())); +// +// if (!StringUtils.isBlank(response.getResponseCode()) && !StringUtils.isBlank(response.getResponseMessage())) { +// new PostGenerateHeaders(merchantConfig); +// System.out.println(" URL : " + url); +// System.out.println(" Response Code : " + response.getResponseCode()); +// System.out.println(" v-c-Co-relation ID : " + response.getVcCorelationId()); +// System.out.println(" Response Message : " + response.getResponseMessage()); +// } +// } catch (Exception e) { +// System.out.println(e.getMessage()); +// WriteLogAudit(400); +// } +// } +//} diff --git a/src/main/java/samples/authentication/AuthSampleCode/PutGenerateHeaders.java b/src/main/java/samples/authentication/AuthSampleCode/PutGenerateHeaders.java index 9ee1b0a..2c6ad09 100644 --- a/src/main/java/samples/authentication/AuthSampleCode/PutGenerateHeaders.java +++ b/src/main/java/samples/authentication/AuthSampleCode/PutGenerateHeaders.java @@ -1,109 +1,109 @@ -package samples.authentication.AuthSampleCode; - -import java.lang.invoke.MethodHandles; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Properties; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import com.cybersource.authsdk.core.Authorization; -import com.cybersource.authsdk.core.MerchantConfig; -import com.cybersource.authsdk.payloaddigest.PayloadDigest; -import com.cybersource.authsdk.util.GlobalLabelParameters; -import samples.authentication.harness.FileReader; -import samples.authentication.harness.MerchantProperties; +//package samples.authentication.AuthSampleCode; +// +//import java.lang.invoke.MethodHandles; +//import java.time.ZoneId; +//import java.time.ZonedDateTime; +//import java.time.format.DateTimeFormatter; +//import java.util.Properties; +//import org.apache.logging.log4j.LogManager; +//import org.apache.logging.log4j.Logger; +//import com.cybersource.authsdk.core.Authorization; +//import com.cybersource.authsdk.core.MerchantConfig; +//import com.cybersource.authsdk.payloaddigest.PayloadDigest; +//import com.cybersource.authsdk.util.GlobalLabelParameters; +//import samples.authentication.harness.FileReader; +//import samples.authentication.harness.MerchantProperties; /** * This class generates the Headers that are present in the token was sent the * server for transaction, for PUT operations. * */ -public class PutGenerateHeaders { - private static Properties merchantProp; - private static MerchantConfig merchantConfig; - private String authenticationType = null; - private Authorization auth; - private String requestType = "PUT"; - private String date = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneId.of("GMT"))); - private PayloadDigest digest; - private Logger logger; - private String jsonRequestData; - private String TempSig; - - public static void WriteLogAudit(int status) { - String filename = MethodHandles.lookup().lookupClass().getSimpleName(); - System.out.println("[Sample Code Testing] [" + filename + "] " + status); - } - - public PutGenerateHeaders(MerchantConfig merchantConfig) throws Exception { - auth = new Authorization(); - logger = LogManager.getLogger(getClass()); - digest = new PayloadDigest(merchantConfig); - PutMethodHeaders(merchantConfig); - } - - public PutGenerateHeaders() throws Exception { - auth = new Authorization(); - this.logger = LogManager.getLogger(getClass()); - - this.jsonRequestData = FileReader.readJsonFromFile("src/main/resources/TRRReport.json"); - - merchantConfig.setRequestData(jsonRequestData); - - digest = new PayloadDigest(merchantConfig); - this.logger.info(GlobalLabelParameters.BEGIN_TRANSACTION + "\n******************* Generate PUT Headers *******************"); - - boolean isMerchant = merchantConfig.validateMerchantDetails(); - if(isMerchant){ - PutMethodHeaders(merchantConfig); - } - - this.logger.info(GlobalLabelParameters.END_TRANSACTION + "\n"); - } - - private void PutMethodHeaders(MerchantConfig merchantConfig) throws Exception { - authenticationType = merchantConfig.getAuthenticationType().trim(); - - this.logger.info(GlobalLabelParameters.AUTENTICATION_TYPE + authenticationType); - this.logger.info(GlobalLabelParameters.REQUEST_TYPE + " : " + requestType); - this.logger.info(GlobalLabelParameters.DATE + " : " + date); - this.logger.info(GlobalLabelParameters.V_C_MERCHANTID + " : " + merchantConfig.getMerchantID().trim()); - this.logger.info(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); - this.logger.info(GlobalLabelParameters.HOST + " : " + merchantConfig.getRequestHost()); +//public class PutGenerateHeaders { +// private static Properties merchantProp; +// private static MerchantConfig merchantConfig; +// private String authenticationType = null; +// private Authorization auth; +// private String requestType = "PUT"; +// private String date = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneId.of("GMT"))); +// private PayloadDigest digest; +// private Logger logger; +// private String jsonRequestData; +// private String TempSig; +// +// public static void WriteLogAudit(int status) { +// String filename = MethodHandles.lookup().lookupClass().getSimpleName(); +// System.out.println("[Sample Code Testing] [" + filename + "] " + status); +// } - System.out.println("MerchantID : " + merchantConfig.getMerchantID().trim()); - System.out.println("Date : " + date); - System.out.println("Request Type : " + requestType); - System.out.println("HOST : " + merchantConfig.getRequestHost()); - System.out.println(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); - - if (authenticationType.equalsIgnoreCase(GlobalLabelParameters.HTTP)) { - System.out.println(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); - this.logger.info(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); - - System.out.println("Digest : " + digest.getDigest()); - - TempSig = auth.getToken(merchantConfig); - System.out.println("Signature : " + TempSig.toString()); - WriteLogAudit(200); - - } else { - String jwtRequestBody = this.jsonRequestData; - auth.setJWTRequestBody(jwtRequestBody); - TempSig = auth.getToken(merchantConfig); - System.out.println("Authorization, Bearer " + TempSig.toString()); - WriteLogAudit(200); - } - } +// public PutGenerateHeaders(MerchantConfig merchantConfig) throws Exception { +// auth = new Authorization(); +// logger = LogManager.getLogger(getClass()); +// digest = new PayloadDigest(merchantConfig); +// PutMethodHeaders(merchantConfig); +// } +// +// public PutGenerateHeaders() throws Exception { +// auth = new Authorization(); +// this.logger = LogManager.getLogger(getClass()); +// +// this.jsonRequestData = FileReader.readJsonFromFile("src/main/resources/TRRReport.json"); +// +// merchantConfig.setRequestData(jsonRequestData); +// +// digest = new PayloadDigest(merchantConfig); +// this.logger.info(GlobalLabelParameters.BEGIN_TRANSACTION + "\n******************* Generate PUT Headers *******************"); +// +// boolean isMerchant = merchantConfig.validateMerchantDetails(); +// if(isMerchant){ +// PutMethodHeaders(merchantConfig); +// } +// +// this.logger.info(GlobalLabelParameters.END_TRANSACTION + "\n"); +// } +// +// private void PutMethodHeaders(MerchantConfig merchantConfig) throws Exception { +// authenticationType = merchantConfig.getAuthenticationType().trim(); +// +// this.logger.info(GlobalLabelParameters.AUTENTICATION_TYPE + authenticationType); +// this.logger.info(GlobalLabelParameters.REQUEST_TYPE + " : " + requestType); +// this.logger.info(GlobalLabelParameters.DATE + " : " + date); +// this.logger.info(GlobalLabelParameters.V_C_MERCHANTID + " : " + merchantConfig.getMerchantID().trim()); +// this.logger.info(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); +// this.logger.info(GlobalLabelParameters.HOST + " : " + merchantConfig.getRequestHost()); +// +// System.out.println("MerchantID : " + merchantConfig.getMerchantID().trim()); +// System.out.println("Date : " + date); +// System.out.println("Request Type : " + requestType); +// System.out.println("HOST : " + merchantConfig.getRequestHost()); +// System.out.println(GlobalLabelParameters.CONTENT_TYPE + " : " + GlobalLabelParameters.APPLICATION_JSON); +// +// if (authenticationType.equalsIgnoreCase(GlobalLabelParameters.HTTP)) { +// System.out.println(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); +// this.logger.info(GlobalLabelParameters.USERAGENT + " : " + GlobalLabelParameters.USER_AGENT_VALUE); +// +// System.out.println("Digest : " + digest.getDigest()); +// +// TempSig = auth.getToken(merchantConfig); +// System.out.println("Signature : " + TempSig.toString()); +// WriteLogAudit(200); +// +// } else { +// String jwtRequestBody = this.jsonRequestData; +// auth.setJWTRequestBody(jwtRequestBody); +// TempSig = auth.getToken(merchantConfig); +// System.out.println("Authorization, Bearer " + TempSig.toString()); +// WriteLogAudit(200); +// } +// } /* This method initiate the PUT Header program. */ - public static void main(String[] args) throws Exception { - merchantProp = MerchantProperties.getMerchantProperties(); - merchantConfig = new MerchantConfig(merchantProp); - - merchantConfig.setRequestType("PUT"); - - new PutGenerateHeaders(); - } -} +// public static void main(String[] args) throws Exception { +// merchantProp = MerchantProperties.getMerchantProperties(); +// merchantConfig = new MerchantConfig(merchantProp); +// +// merchantConfig.setRequestType("PUT"); +// +// new PutGenerateHeaders(); +// } +//} diff --git a/src/main/java/samples/authentication/AuthSampleCode/PutMethod.java b/src/main/java/samples/authentication/AuthSampleCode/PutMethod.java index 2cf07f0..e0bc34b 100644 --- a/src/main/java/samples/authentication/AuthSampleCode/PutMethod.java +++ b/src/main/java/samples/authentication/AuthSampleCode/PutMethod.java @@ -1,52 +1,52 @@ -package samples.authentication.AuthSampleCode; - -import java.lang.invoke.MethodHandles; -import java.util.Properties; - -import org.apache.commons.lang3.StringUtils; - -import samples.authentication.Data.PayloadData; -import samples.authentication.harness.MerchantProperties; - -import com.cybersource.apisdk.controller.ApiController; -import com.cybersource.apisdk.model.Response; -import com.cybersource.authsdk.core.MerchantConfig; +//package samples.authentication.AuthSampleCode; +// +//import java.lang.invoke.MethodHandles; +//import java.util.Properties; +// +//import org.apache.commons.lang3.StringUtils; +// +//import samples.authentication.Data.PayloadData; +//import samples.authentication.harness.MerchantProperties; +// +//import com.cybersource.apisdk.controller.ApiController; +//import com.cybersource.apisdk.model.Response; +//import com.cybersource.authsdk.core.MerchantConfig; /** * Depending on the authentication type HTTP or JWT , this class performs the * PUT operation on the given working domain. */ -public class PutMethod { - private ApiController apiController; - private String authenticationType; - private Response response; - private Properties merchantProp; - private MerchantConfig merchantConfig; - - public static void WriteLogAudit(int status) { - String filename = MethodHandles.lookup().lookupClass().getSimpleName(); - System.out.println("[Sample Code Testing] [" + filename + "] " + status); - } +//public class PutMethod { +// private ApiController apiController; +// private String authenticationType; +// private Response response; +// private Properties merchantProp; +// private MerchantConfig merchantConfig; +// +// public static void WriteLogAudit(int status) { +// String filename = MethodHandles.lookup().lookupClass().getSimpleName(); +// System.out.println("[Sample Code Testing] [" + filename + "] " + status); +// } /** * REQUEST-TARGET [Editable] */ - private String requestTarget = "/reporting/v3/reportSubscriptions/TRRReport?organizationId=testrest"; + //private String requestTarget = "/reporting/v3/reportSubscriptions/TRRReport?organizationId=testrest"; /** * REQUEST-TYPE. [Non-Editable] */ - private String requestType = "PUT"; - - private String url; +// private String requestType = "PUT"; +// +// private String url; /* Request Data. */ - private String requestData = PayloadData.readData(); + //private String requestData = PayloadData.readData(); /* This method initiates or begins the process. */ - public static void main(String[] args) throws Exception { - new PutMethod(); - } +// public static void main(String[] args) throws Exception { +// new PutMethod(); +// } /** * @@ -54,45 +54,45 @@ public static void main(String[] args) throws Exception { * @return * @throws Exception */ - public PutMethod() throws Exception { - apiController = new ApiController(); - merchantProp = MerchantProperties.getMerchantProperties(); - merchantConfig = new MerchantConfig(merchantProp); - merchantConfig.setRequestType(requestType); - - authenticationType = merchantConfig.getAuthenticationType().trim(); - - merchantConfig.setRequestTarget(requestTarget); - merchantConfig.setRequestData(requestData); - - url = "https://" + merchantConfig.getRequestHost() + merchantConfig.getRequestTarget(); +// public PutMethod() throws Exception { +// apiController = new ApiController(); +// merchantProp = MerchantProperties.getMerchantProperties(); +// merchantConfig = new MerchantConfig(merchantProp); +// merchantConfig.setRequestType(requestType); +// +// authenticationType = merchantConfig.getAuthenticationType().trim(); +// +// merchantConfig.setRequestTarget(requestTarget); +// merchantConfig.setRequestData(requestData); +// +// url = "https://" + merchantConfig.getRequestHost() + merchantConfig.getRequestTarget(); /* Begin PUT process. */ - process(); - } +// process(); +// } /** * Calls the APISDK for processing the payment request. * * @throws Exception */ - private void process() throws Exception { - System.out.println(authenticationType.toUpperCase() + " Request"); - try { - /* Call payment method of Api Controller class */ - response = apiController.paymentPut(merchantConfig); - WriteLogAudit(Integer.parseInt(response.getResponseCode())); - - if (!StringUtils.isBlank(response.getResponseCode()) && !StringUtils.isBlank(response.getResponseMessage())) { - new PutGenerateHeaders(merchantConfig); - System.out.println(" URL : " + url); - System.out.println(" Response Code : " + response.getResponseCode()); - System.out.println(" v-c-Co-relation ID : " + response.getVcCorelationId()); - System.out.println(" Response Message : " + response.getResponseMessage()); - } - } catch (Exception e) { - System.out.println(e.getMessage()); - WriteLogAudit(400); - } - } -} +// private void process() throws Exception { +// System.out.println(authenticationType.toUpperCase() + " Request"); +// try { +// /* Call payment method of Api Controller class */ +// response = apiController.paymentPut(merchantConfig); +// WriteLogAudit(Integer.parseInt(response.getResponseCode())); +// +// if (!StringUtils.isBlank(response.getResponseCode()) && !StringUtils.isBlank(response.getResponseMessage())) { +// new PutGenerateHeaders(merchantConfig); +// System.out.println(" URL : " + url); +// System.out.println(" Response Code : " + response.getResponseCode()); +// System.out.println(" v-c-Co-relation ID : " + response.getVcCorelationId()); +// System.out.println(" Response Message : " + response.getResponseMessage()); +// } +// } catch (Exception e) { +// System.out.println(e.getMessage()); +// WriteLogAudit(400); +// } +// } +//} diff --git a/src/main/java/samples/authentication/AuthSampleCode/Test.java b/src/main/java/samples/authentication/AuthSampleCode/Test.java index 485e94c..9533480 100644 --- a/src/main/java/samples/authentication/AuthSampleCode/Test.java +++ b/src/main/java/samples/authentication/AuthSampleCode/Test.java @@ -1,10 +1,10 @@ -package samples.authentication.AuthSampleCode; - -import org.apache.commons.lang3.StringUtils; - -public class Test { -static String test = ""; -public static void main(String[] args) { - System.out.println(StringUtils.isEmpty(test)); -} -} +//package samples.authentication.AuthSampleCode; +// +//import org.apache.commons.lang3.StringUtils; +// +//public class Test { +//static String test = ""; +//public static void main(String[] args) { +// System.out.println(StringUtils.isEmpty(test)); +//} +//} diff --git a/src/main/java/samples/authentication/AuthSampleCode/reportDownload.java b/src/main/java/samples/authentication/AuthSampleCode/reportDownload.java index d0b772d..fffdaa4 100644 --- a/src/main/java/samples/authentication/AuthSampleCode/reportDownload.java +++ b/src/main/java/samples/authentication/AuthSampleCode/reportDownload.java @@ -1,141 +1,141 @@ -package samples.authentication.AuthSampleCode; - -import java.lang.invoke.MethodHandles; -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; - -import java.io.*; -import java.net.HttpURLConnection; -import java.net.URL; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Base64; - -public class reportDownload { +//package samples.authentication.AuthSampleCode; +// +//import java.lang.invoke.MethodHandles; +//import javax.crypto.Mac; +//import javax.crypto.spec.SecretKeySpec; + +//import java.io.*; +//import java.net.HttpURLConnection; +//import java.net.URL; +//import java.security.MessageDigest; +//import java.security.NoSuchAlgorithmException; +//import java.time.ZoneId; +//import java.time.ZonedDateTime; +//import java.time.format.DateTimeFormatter; +//import java.util.Base64; +// +//public class reportDownload { // Before using this example, replace the generic values with your merchant ID, // shared secrect key, etc // Note: please use %20 for space if your report name has space eg.your report // name is "my test", then use "my20%test" - private final String USER_AGENT = "Mozilla/5.0"; - public String merchantKeyId = "08c94330-f618-42a3-b09d-e1e43be5efda"; - public String merchantsecretKey = "yBJxy6LjM2TmcPGu+GaJrHtkke25fPpUX+UY6/L/1tE="; - public String merchantId = "testrest"; +// private final String USER_AGENT = "Mozilla/5.0"; +// public String merchantKeyId = "08c94330-f618-42a3-b09d-e1e43be5efda"; +// public String merchantsecretKey = "yBJxy6LjM2TmcPGu+GaJrHtkke25fPpUX+UY6/L/1tE="; +// public String merchantId = "testrest"; /* * Add Request Header :: "Host" Sandbox Host: apitest.cybersource.com Production * Host: api.cybersource.com */ - public String requestHost = "apitest.cybersource.com"; - public String gmtDateTime = ""; - public static String resourceURI = "/reporting/v2/reportSubscriptions/TRRReport?organizationId=testrest"; - public static String resourceFile = "report"; - private static final String FILE_PATH = "src/main/resources/"; +// public String requestHost = "apitest.cybersource.com"; +// public String gmtDateTime = ""; +// public static String resourceURI = "/reporting/v2/reportSubscriptions/TRRReport?organizationId=testrest"; +// public static String resourceFile = "report"; +// private static final String FILE_PATH = "src/main/resources/"; - public static void WriteLogAudit(int status) { - String filename = MethodHandles.lookup().lookupClass().getSimpleName(); - System.out.println("[Sample Code Testing] [" + filename + "] " + status); - } +// public static void WriteLogAudit(int status) { +// String filename = MethodHandles.lookup().lookupClass().getSimpleName(); +// System.out.println("[Sample Code Testing] [" + filename + "] " + status); +// } - public static void main(String[] args) throws Exception { + //public static void main(String[] args) throws Exception { /* * Calculate HTTP Signature Digest and Authenticate Cybersource Report API using * HTTP Client */ - reportDownload http = new reportDownload(); - - try { - http.sendGet(resourceURI, resourceFile); - WriteLogAudit(200); - } catch (Exception e){ - WriteLogAudit(200); - throw e; - } - } +// reportDownload http = new reportDownload(); +// +// try { +// http.sendGet(resourceURI, resourceFile); +// WriteLogAudit(200); +// } catch (Exception e){ +// WriteLogAudit(200); +// throw e; +// } +// } // HTTP GET request - private void sendGet(String resourceURI, String resourceFile) throws Exception { - - String url = "https://" + requestHost + resourceURI; +// private void sendGet(String resourceURI, String resourceFile) throws Exception { +// +// String url = "https://" + requestHost + resourceURI; /* HTTP connection */ - URL obj = new URL(url); - HttpURLConnection con = (HttpURLConnection) obj.openConnection(); +// URL obj = new URL(url); +// HttpURLConnection con = (HttpURLConnection) obj.openConnection(); /* * Add Request Header :: "v-c-merchant-id" set value to Cybersource Merchant ID * or v-c-merchant-id This ID can be found on EBC2 portal */ - con.setRequestProperty("v-c-merchant-id", merchantId); + //con.setRequestProperty("v-c-merchant-id", merchantId); /* * Add Request Header :: "Date" The date and time that the message was * originated from. "HTTP-date" format as defined by RFC7231. */ - gmtDateTime = getDate(); - con.setRequestProperty("Date", gmtDateTime); +// gmtDateTime = getDate(); +// con.setRequestProperty("Date", gmtDateTime); /* * Add Request Header :: "Host" Sandbox Host: apitest.cybersource.com Production * Host: api.cybersource.com */ - con.setRequestProperty("Host", requestHost); + //con.setRequestProperty("Host", requestHost); /* * Add Request Header :: "Signature" Signature header contains keyId, algorithm, * headers and signature as paramters method getSignatureHeader() has more * details */ - StringBuilder signatureHeaderValue = getSignatureHeader("GET", resourceURI, resourceFile); - con.setRequestProperty("Signature", signatureHeaderValue.toString()); +// StringBuilder signatureHeaderValue = getSignatureHeader("GET", resourceURI, resourceFile); +// con.setRequestProperty("Signature", signatureHeaderValue.toString()); /* HTTP Method GET */ - con.setRequestMethod("GET"); + // con.setRequestMethod("GET"); /* Addition Request Headers */ - con.setRequestProperty("User-Agent", USER_AGENT); - con.setRequestProperty("Content-Type", "application/json"); +// con.setRequestProperty("User-Agent", USER_AGENT); +// con.setRequestProperty("Content-Type", "application/json"); /* Establishing HTTP connection */ // int responseCode = con.getResponseCode(); // String responseHeader = con.getHeaderField("v-c-correlation-id"); /* Download Report */ - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - org.apache.commons.io.IOUtils.copy(con.getInputStream(), outputStream); - byte[] bytes = outputStream.toByteArray(); - BufferedReader br = new BufferedReader(new InputStreamReader((new ByteArrayInputStream(bytes)))); - - String output; - String reportType = "csv"; - System.out.println("Output from Server .... \n"); - while ((output = br.readLine()) != null) { - if (output.contains("xml")) { - reportType = "xml"; - } - } - - BufferedReader br_write = new BufferedReader(new InputStreamReader((new ByteArrayInputStream(bytes)))); - BufferedWriter bw = new BufferedWriter(new FileWriter(new File(FILE_PATH + resourceFile + "." + reportType))); - while ((output = br_write.readLine()) != null) { - bw.write(output + "\n"); - } - - con.disconnect(); - bw.close(); - - } - - private String getDate() { +// ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); +// org.apache.commons.io.IOUtils.copy(con.getInputStream(), outputStream); +// byte[] bytes = outputStream.toByteArray(); +// BufferedReader br = new BufferedReader(new InputStreamReader((new ByteArrayInputStream(bytes)))); + +// String output; +// String reportType = "csv"; +// System.out.println("Output from Server .... \n"); +// while ((output = br.readLine()) != null) { +// if (output.contains("xml")) { +// reportType = "xml"; +// } +// } +// +// BufferedReader br_write = new BufferedReader(new InputStreamReader((new ByteArrayInputStream(bytes)))); +// BufferedWriter bw = new BufferedWriter(new FileWriter(new File(FILE_PATH + resourceFile + "." + reportType))); +// while ((output = br_write.readLine()) != null) { +// bw.write(output + "\n"); +// } +// +// con.disconnect(); +// bw.close(); +// +// } +// +// private String getDate() { /* This Method returns Date in GMT format as defined by RFC7231. */ - return (DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneId.of("GMT")))); - } - - private StringBuilder getSignatureHeader(String httpMethod, String resourceURI, String resourceFile) - throws Exception { +// return (DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneId.of("GMT")))); +// } +// +// private StringBuilder getSignatureHeader(String httpMethod, String resourceURI, String resourceFile) +// throws Exception { /* * This method return SignatureHeader Value that contains following paramters @@ -149,36 +149,36 @@ private StringBuilder getSignatureHeader(String httpMethod, String resourceURI, * header above in given order */ - StringBuilder signatureHeaderValue = new StringBuilder(); + //StringBuilder signatureHeaderValue = new StringBuilder(); /* KeyId is the key obtained from EBC */ - signatureHeaderValue.append("keyid=\"" + merchantKeyId + "\""); + //signatureHeaderValue.append("keyid=\"" + merchantKeyId + "\""); /* Algorithm should be always HmacSHA256 for http signature */ - signatureHeaderValue.append(", algorithm=\"HmacSHA256\""); + //signatureHeaderValue.append(", algorithm=\"HmacSHA256\""); /* * Headers - list is choosen based on HTTP method. Digest is not required for * GET Method */ - String getHeaders = "host date request-target" + " " + "v-c-merchant-id"; - String postHeaders = "host date request-target digest v-c-merchant-id"; - - if (httpMethod.equalsIgnoreCase("GET")) - signatureHeaderValue.append(", headers=\"" + getHeaders + "\""); - else if (httpMethod.equalsIgnoreCase("POST")) - signatureHeaderValue.append(", headers=\"" + postHeaders + "\""); - else if (httpMethod.equalsIgnoreCase("PUT")) - signatureHeaderValue.append(", headers=\"" + postHeaders + "\""); +// String getHeaders = "host date request-target" + " " + "v-c-merchant-id"; +// String postHeaders = "host date request-target digest v-c-merchant-id"; +// +// if (httpMethod.equalsIgnoreCase("GET")) +// signatureHeaderValue.append(", headers=\"" + getHeaders + "\""); +// else if (httpMethod.equalsIgnoreCase("POST")) +// signatureHeaderValue.append(", headers=\"" + postHeaders + "\""); +// else if (httpMethod.equalsIgnoreCase("PUT")) +// signatureHeaderValue.append(", headers=\"" + postHeaders + "\""); /* Get Value for paramter 'Signature' to be passed to Signature Header */ - String signatureValue = getSignatureParam(httpMethod, resourceURI, resourceFile); - signatureHeaderValue.append(", signature=\"" + signatureValue + "\""); - - return signatureHeaderValue; - } +// String signatureValue = getSignatureParam(httpMethod, resourceURI, resourceFile); +// signatureHeaderValue.append(", signature=\"" + signatureValue + "\""); +// +// return signatureHeaderValue; +// } - private String getSignatureParam(String httpMethod, String resourceURI, String resourceFile) throws Exception { + //private String getSignatureParam(String httpMethod, String resourceURI, String resourceFile) throws Exception { /* * This method returns value for paramter Signature which is then passed to @@ -192,81 +192,81 @@ private String getSignatureParam(String httpMethod, String resourceURI, String r * Cybersource Merchant ID This ID can be found on EBC portal */ - StringBuilder signatureString = new StringBuilder(); - signatureString.append('\n'); - signatureString.append("host"); - signatureString.append(": "); - signatureString.append(requestHost); - signatureString.append('\n'); - signatureString.append("date"); - signatureString.append(": "); - signatureString.append(gmtDateTime); - signatureString.append('\n'); - signatureString.append("request-target"); - signatureString.append(": "); - - String getRequestTarget = "get " + resourceURI; - - if (httpMethod.equalsIgnoreCase("GET")) - signatureString.append(getRequestTarget); - signatureString.append('\n'); - - if (httpMethod.equalsIgnoreCase("POST") || httpMethod.equalsIgnoreCase("PUT")) { - signatureString.append("digest"); - signatureString.append(": "); - signatureString.append(getDigest(resourceFile)); - signatureString.append('\n'); - } - - signatureString.append("v-c-merchant-id"); - signatureString.append(": "); - signatureString.append(merchantId); - signatureString.delete(0, 1); - String signatureStr = signatureString.toString(); +// StringBuilder signatureString = new StringBuilder(); +// signatureString.append('\n'); +// signatureString.append("host"); +// signatureString.append(": "); +// signatureString.append(requestHost); +// signatureString.append('\n'); +// signatureString.append("date"); +// signatureString.append(": "); +// signatureString.append(gmtDateTime); +// signatureString.append('\n'); +// signatureString.append("request-target"); +// signatureString.append(": "); +// +// String getRequestTarget = "get " + resourceURI; +// +// if (httpMethod.equalsIgnoreCase("GET")) +// signatureString.append(getRequestTarget); +// signatureString.append('\n'); +// +// if (httpMethod.equalsIgnoreCase("POST") || httpMethod.equalsIgnoreCase("PUT")) { +// signatureString.append("digest"); +// signatureString.append(": "); +// signatureString.append(getDigest(resourceFile)); +// signatureString.append('\n'); +// } +// +// signatureString.append("v-c-merchant-id"); +// signatureString.append(": "); +// signatureString.append(merchantId); +// signatureString.delete(0, 1); +// String signatureStr = signatureString.toString(); /* * Signature string generated from above parameters is Signed with SecretKey * hased with SHA256 and base64 encoded. Secret Key is Base64 decoded before * signing */ - SecretKeySpec secretKey = new SecretKeySpec(Base64.getDecoder().decode(merchantsecretKey), "HmacSHA256"); - Mac aKeyId = Mac.getInstance("HmacSHA256"); - aKeyId.init(secretKey); - aKeyId.update(signatureStr.getBytes()); - byte[] aHeaders = aKeyId.doFinal(); - String base64EncodedSignature = Base64.getEncoder().encodeToString(aHeaders); - - return base64EncodedSignature; - } - - private String getDigest(String resourceFile) throws NoSuchAlgorithmException, IOException { +// SecretKeySpec secretKey = new SecretKeySpec(Base64.getDecoder().decode(merchantsecretKey), "HmacSHA256"); +// Mac aKeyId = Mac.getInstance("HmacSHA256"); +// aKeyId.init(secretKey); +// aKeyId.update(signatureStr.getBytes()); +// byte[] aHeaders = aKeyId.doFinal(); +// String base64EncodedSignature = Base64.getEncoder().encodeToString(aHeaders); +// +// return base64EncodedSignature; +// } + + //private String getDigest(String resourceFile) throws NoSuchAlgorithmException, IOException { /* * This method return Digest value which is SHA-256 hash of payload that is * BASE64 encoded */ - String messageBody = getPayload(resourceFile); - MessageDigest digestString = MessageDigest.getInstance("SHA-256"); - byte[] digestBytes = digestString.digest(messageBody.getBytes("UTF-8")); - - String bluePrint = Base64.getEncoder().encodeToString(digestBytes); - bluePrint = "SHA-256=" + bluePrint; - return bluePrint; - } - - private String getPayload(String resourceFile) throws IOException { - - URL path = reportDownload.class.getResource("resource/" + resourceFile); - File fr = new File(path.getFile()); - BufferedReader buf = new BufferedReader(new FileReader(fr)); - String line = buf.readLine(); - StringBuilder sb = new StringBuilder(); - while (line != null) { - sb.append(line).append("\n"); - line = buf.readLine(); - } - String messageBody = sb.toString(); - buf.close(); - return messageBody; - } -} \ No newline at end of file +// String messageBody = getPayload(resourceFile); +// MessageDigest digestString = MessageDigest.getInstance("SHA-256"); +// byte[] digestBytes = digestString.digest(messageBody.getBytes("UTF-8")); +// +// String bluePrint = Base64.getEncoder().encodeToString(digestBytes); +// bluePrint = "SHA-256=" + bluePrint; +// return bluePrint; +// } + +// private String getPayload(String resourceFile) throws IOException { +// +// URL path = reportDownload.class.getResource("resource/" + resourceFile); +// File fr = new File(path.getFile()); +// BufferedReader buf = new BufferedReader(new FileReader(fr)); +// String line = buf.readLine(); +// StringBuilder sb = new StringBuilder(); +// while (line != null) { +// sb.append(line).append("\n"); +// line = buf.readLine(); +// } +// String messageBody = sb.toString(); +// buf.close(); +// return messageBody; +// } +//} \ No newline at end of file