diff --git a/src/main/java/SecureNetRestApiSDK/Api/Models/AdditionalTerminalInfo.java b/src/main/java/SecureNetRestApiSDK/Api/Models/AdditionalTerminalInfo.java index 7e9e7e6..c11a6c6 100755 --- a/src/main/java/SecureNetRestApiSDK/Api/Models/AdditionalTerminalInfo.java +++ b/src/main/java/SecureNetRestApiSDK/Api/Models/AdditionalTerminalInfo.java @@ -69,6 +69,17 @@ public String getStoreNumber() { public void setStoreNumber(String value) { storeNumber = value; } + /** + * Represents the value for a Cardholder Activated Terminal type of transaction. + */ + private String catIndicator = new String(); + public String getCAIndicator() { + return catIndicator; + } + + public void setCATIndicator(String value) { + catIndicator = value; + } } diff --git a/src/main/java/SecureNetRestApiSDK/Api/Models/Transaction.java b/src/main/java/SecureNetRestApiSDK/Api/Models/Transaction.java index 2ec7d4a..034cc9a 100755 --- a/src/main/java/SecureNetRestApiSDK/Api/Models/Transaction.java +++ b/src/main/java/SecureNetRestApiSDK/Api/Models/Transaction.java @@ -466,6 +466,14 @@ public void setDynamicMCC(String value) { dynamicMCC = value; } + private String catIndicator = new String(); + public String getCATIndicator() { + return catIndicator; + } + + public void setCATIndicator(String value) { + catIndicator = value; + } } diff --git a/src/main/java/SecureNetRestApiSDK/Api/Requests/TransactionRetrieveRequest.java b/src/main/java/SecureNetRestApiSDK/Api/Requests/TransactionRetrieveRequest.java index 1f04304..c422f69 100755 --- a/src/main/java/SecureNetRestApiSDK/Api/Requests/TransactionRetrieveRequest.java +++ b/src/main/java/SecureNetRestApiSDK/Api/Requests/TransactionRetrieveRequest.java @@ -19,12 +19,13 @@ public void setTransactionId(int value) { } public String getUri() throws Exception { - return "api/transactions/Search"; - } - + return String.format("api/transactions/%d", getTransactionId()); + + } + public HttpMethodEnum getMethod() throws Exception { - return HttpMethodEnum.POST; - } + return HttpMethodEnum.GET; + } } diff --git a/src/main/java/SecureNetRestApiSDK/Api/Requests/TransactionSearchRequest.java b/src/main/java/SecureNetRestApiSDK/Api/Requests/TransactionSearchRequest.java index e8b43e7..19627a6 100755 --- a/src/main/java/SecureNetRestApiSDK/Api/Requests/TransactionSearchRequest.java +++ b/src/main/java/SecureNetRestApiSDK/Api/Requests/TransactionSearchRequest.java @@ -57,12 +57,12 @@ public void setAmount(double value) { public String getUri() throws Exception { - return String.format("api/transactions/%d", getTransactionId()); - } - + return "api/transactions/Search"; + } + public HttpMethodEnum getMethod() throws Exception { - return HttpMethodEnum.GET; - } + return HttpMethodEnum.POST; + } } diff --git a/src/main/java/SecureNetRestApiSDK/Api/Requests/VerifyRequest.java b/src/main/java/SecureNetRestApiSDK/Api/Requests/VerifyRequest.java new file mode 100644 index 0000000..779fd7c --- /dev/null +++ b/src/main/java/SecureNetRestApiSDK/Api/Requests/VerifyRequest.java @@ -0,0 +1,57 @@ +package SecureNetRestApiSDK.Api.Requests; + + +import SNET.Core.HttpMethodEnum; +import SecureNetRestApiSDK.Api.Models.Card; +import SecureNetRestApiSDK.Api.Models.Encryption; +import SecureNetRestApiSDK.Api.Models.ExtendedInformation; +import SecureNetRestApiSDK.Api.Models.PaymentVaultToken; + +public class VerifyRequest extends SecureNetRequest +{ + + /** + * Amount of the charge to be authorized. + */ + private double amount; + public double getAmount() { + return amount; + } + + public void setAmount(double value) { + amount = value; + } + + /** + * Credit-card-specific data. In the case of a card-present transaction, track data from a swiped transaction is the most commonly used property. Required for credit card charges. + */ + private Card card; + public Card getCard() { + return card; + } + + public void setCard(Card value) { + card = value; + } + + /** + * Additional data to assist in reporting, ecommerce or moto transactions, and level 2 or level 3 processing. Includes user-defined fields and invoice-related information. + */ + private ExtendedInformation extendedInformation; + public ExtendedInformation getExtendedInformation() { + return extendedInformation; + } + + public void setExtendedInformation(ExtendedInformation value) { + extendedInformation = value; + } + + public String getUri() throws Exception { + return "api/Payments/Verify"; + } + + public HttpMethodEnum getMethod() throws Exception { + return HttpMethodEnum.POST; + } + +} diff --git a/src/main/java/SecureNetRestApiSDK/Api/Responses/VerifyResponse.java b/src/main/java/SecureNetRestApiSDK/Api/Responses/VerifyResponse.java new file mode 100644 index 0000000..b670c20 --- /dev/null +++ b/src/main/java/SecureNetRestApiSDK/Api/Responses/VerifyResponse.java @@ -0,0 +1,16 @@ +package SecureNetRestApiSDK.Api.Responses; + +import SecureNetRestApiSDK.Api.Models.Transaction; + +public class VerifyResponse extends SecureNetResponse +{ + private Transaction transaction; + public Transaction getTransaction() { + return transaction; + } + + public void setTransaction(Transaction value) { + transaction = value; + } + +} diff --git a/src/test/java/test/HelperTest.java b/src/test/java/test/HelperTest.java index 6c14d8e..74a3b46 100644 --- a/src/test/java/test/HelperTest.java +++ b/src/test/java/test/HelperTest.java @@ -1,9 +1,14 @@ package test; +import SecureNetRestApiSDK.Api.Models.*; +import SecureNetRestApiSDK.Api.Requests.*; import org.junit.Before; import java.io.IOException; import java.io.InputStream; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.List; import java.util.Properties; public class HelperTest { @@ -17,6 +22,8 @@ public class HelperTest { private String _requestDynamicMCC; private String _responseDynamicMCC; + + public HelperTest() throws IOException { InputStream stream = this.getClass().getResourceAsStream("/config.properties"); config = new Properties(); @@ -48,4 +55,174 @@ public String getResponseDynamicMCC() { return _responseDynamicMCC; } + + public String getCATIndicator(){ + PosCardholderActivatedTerminal catIndicator = PosCardholderActivatedTerminal.TransponderTransactio; + return catIndicator.getCATIndicatorValue(); + } + + public AuthorizeRequest getAnAuthorizeRequiest(boolean containCATIndicator){ + AuthorizeRequest request = new AuthorizeRequest(); + request.setCard(getCard()); + request.setAmount(20d); + request.setDeveloperApplication(getDeveloperApplication()); + request.setExtendedInformation(getExtendedInformation(containCATIndicator)); + return request; + } + + public PriorAuthCaptureRequest getAPriorAuthCaptureRequest(int transactionId,boolean includeTip){ + PriorAuthCaptureRequest request = new PriorAuthCaptureRequest(); + request.setAmount(20d); + request.setTransactionId(transactionId); + request.setDeveloperApplication(getDeveloperApplication()); + if(includeTip){ + ExtendedInformation extendedInfo = new ExtendedInformation(); + ServiceData serviceData = new ServiceData(); + serviceData.setGratuityAmount(1.75); + extendedInfo.setServiceData(serviceData); + request.setExtendedInformation(extendedInfo); + } + return request; + } + + public ChargeRequest getAChargeRequest(boolean containCATIndicator){ + ChargeRequest request = new ChargeRequest(); + request.setAmount(20d); + request.setCard(getCard()); + request.setDeveloperApplication(getDeveloperApplication()); + request.setExtendedInformation(getExtendedInformation(containCATIndicator)); + return request; + } + + + + public CreditRequest getACreditRequest(boolean containCATIndicator){ + CreditRequest request = new CreditRequest(); + request.setCard(getCard()); + request.setAmount(1.05d); + request.setDeveloperApplication(getDeveloperApplication()); + request.setExtendedInformation(getExtendedInformation(containCATIndicator)); + return request; + } + + public RefundRequest getARefundRequest(int transactionId){ + RefundRequest request = new RefundRequest(); + request.setDeveloperApplication(getDeveloperApplication()); + request.setTransactionId(transactionId); + return request; + } + + public VoidRequest getAVoidRequest(int transactionId){ + VoidRequest request = new VoidRequest(); + request.setTransactionId(transactionId); + request.setDeveloperApplication(getDeveloperApplication()); + return request; + } + + public VerifyRequest getAVerifyRequest(boolean containCATIndicator){ + VerifyRequest request = new VerifyRequest(); + request.setCard(getCard()); + request.setAmount(1.05d); + request.setDeveloperApplication(getDeveloperApplication()); + request.setExtendedInformation(getExtendedInformation(containCATIndicator)); + return request; + } + + public TransactionSearchRequest getATransactionSearchRequiest() throws ParseException { + TransactionSearchRequest request = new TransactionSearchRequest(); + request.setDeveloperApplication(getDeveloperApplication()); + request.setAmount(20d); + + SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); + + request.setStartDate(formatter.parse("02/01/2016")); + request.setEndDate(formatter.parse("05/31/2017")); + return request; + } + + public TransactionRetrieveRequest getATransactionRetrieveRequest(){ + TransactionRetrieveRequest request = new TransactionRetrieveRequest(); + request.setDeveloperApplication(getDeveloperApplication()); + return request; + } + + public TransactionUpdateRequest getATransactionUpdateRequest(){ + TransactionUpdateRequest request = new TransactionUpdateRequest(); + request.setDeveloperApplication(getDeveloperApplication()); + return request; + } + + public BatchCloseRequest getABachCloseRequest(){ + BatchCloseRequest request = new BatchCloseRequest(); + request.setDeveloperApplication(getDeveloperApplication()); + return request; + } + + public BatchRetrieveRequest getABatchRetrieveRequest(){ + BatchRetrieveRequest request = new BatchRetrieveRequest(); + request.setDeveloperApplication(getDeveloperApplication()); + return request; + } + + public BatchCurrentRequest getABatchCurrentRequest(){ + BatchCurrentRequest request = new BatchCurrentRequest(); + request.setDeveloperApplication(getDeveloperApplication()); + return request; + } + + public DeveloperApplication getDeveloperApplication() { + DeveloperApplication devApp = new DeveloperApplication(); + devApp.setDeveloperId(Integer.parseInt(config.getProperty("developerId"))); + devApp.setVersion(config.getProperty("versionId")); + return devApp; + } + + public Card getCard(){ + Card card = new Card(); + card.setAddress(getAddress()); + card.setCvv("123"); + card.setExpirationDate("07/2018"); + card.setNumber("4111111111111111"); + return card; + } + + public Check getCheck() { + Check check = new Check(); + check.setFirstName("Bruce"); + check.setLastName("Wayne"); + check.setRoutingNumber("222371863"); + check.setAccountNumber("123456"); + return check; + } + + public ExtendedInformation getExtendedInformation(boolean containCATIndicator) { + ExtendedInformation extendedInfo = new ExtendedInformation(); + extendedInfo.setSoftDescriptor(getRequestSoftDescriptor()); + extendedInfo.setDynamicMCC(getRequestDynamicMCC()); + if(containCATIndicator){ + AdditionalTerminalInfo additionalTerminalInfo = new AdditionalTerminalInfo(); + additionalTerminalInfo.setCATIndicator(getCATIndicator()); + extendedInfo.setAdditionalTerminalInfo(additionalTerminalInfo); + } + return extendedInfo; + } + + public Address getAddress() { + Address address = new Address(); + address.setCity("Austin"); + address.setCountry("US"); + address.setLine1("123 Main St."); + address.setState("TX"); + address.setZip("78759"); + return address; + } + + public Transaction getTransactionFromTransactionList(int transactionId, List transactionList) { + for (Transaction transaction : transactionList) { + if (transaction.getTransactionId() == transactionId) { + return transaction; + } + } + return null; + } } \ No newline at end of file diff --git a/src/test/java/test/PosCardholderActivatedTerminal.java b/src/test/java/test/PosCardholderActivatedTerminal.java new file mode 100644 index 0000000..4a2adc7 --- /dev/null +++ b/src/test/java/test/PosCardholderActivatedTerminal.java @@ -0,0 +1,24 @@ +package test; + +public enum PosCardholderActivatedTerminal +{ + NotCatTransaction(0), + AtmWithPin(1), + SelfServiceTerminal(2), + LimitedAmountTerminal(3), + InFlightCommerce(4), + ElectronicCommerce(6), + TransponderTransactio(7); + + private final int catIndicatorValue; + + PosCardholderActivatedTerminal(int CATValue){ + catIndicatorValue = CATValue; + } + + +public String getCATIndicatorValue(){ + return String.valueOf(catIndicatorValue); + } +} + diff --git a/src/test/java/test/controllers/BatchesControllerTest.java b/src/test/java/test/controllers/BatchesControllerTest.java index 511cb97..db19e0a 100755 --- a/src/test/java/test/controllers/BatchesControllerTest.java +++ b/src/test/java/test/controllers/BatchesControllerTest.java @@ -6,6 +6,10 @@ import java.io.InputStream; import java.util.Properties; +import SecureNetRestApiSDK.Api.Controllers.PaymentsController; +import SecureNetRestApiSDK.Api.Models.Transaction; +import SecureNetRestApiSDK.Api.Requests.ChargeRequest; +import SecureNetRestApiSDK.Api.Responses.ChargeResponse; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -19,81 +23,126 @@ import SecureNetRestApiSDK.Api.Responses.BatchCloseResponse; import SecureNetRestApiSDK.Api.Responses.BatchCurrentResponse; import SecureNetRestApiSDK.Api.Responses.BatchRetrieveResponse; +import test.HelperTest; -public class BatchesControllerTest -{ - - Properties config ; - - @Before - public void before() throws Exception{ - InputStream stream = this.getClass().getResourceAsStream("/config.properties"); - config = new Properties(); - config.load(stream); - } - - /** - * Successful response returned from a Settlement Close Batch request. - * https://apidocs.securenet.com/docs/settlement.html?lang=csharp#closebatch - */ - @Test +public class BatchesControllerTest { + + Properties config; + HelperTest helper; + + @Before + public void before() throws Exception { + InputStream stream = this.getClass().getResourceAsStream("/config.properties"); + config = new Properties(); + config.load(stream); + helper = new HelperTest(); + } + + /** + * Successful response returned from a Settlement Close Batch request. + * https://apidocs.securenet.com/docs/settlement.html?lang=csharp#closebatch + */ + @Test public void settlementclosebatchrequestreturnssuccessfully() throws Exception { - getBatchCloseResponse(); - } - - /** - * Successful response returned from a Settlement Retrieve Closed Batch request. - * https://apidocs.securenet.com/docs/settlement.html?lang=csharp#retrievebatch - */ - @Test + boolean containCATIndicator = false; + createTransaction(containCATIndicator); + getBatchCloseResponse(); + } + + /** + * Successful response returned from a Settlement Close Batch request Include CAT field. + * https://apidocs.securenet.com/docs/settlement.html?lang=csharp#closebatch + */ + @Test + public void settlementclosebatchrequestWithCATIndicatorreturnssuccessfully() throws Exception { + boolean containCATIndicator = true; + int transactionId = createTransaction(containCATIndicator); + BatchCloseResponse closeResponse = getBatchCloseResponse(); + Transaction searchedTransaction = helper.getTransactionFromTransactionList(transactionId,closeResponse.getTransactions()); + Assert.assertEquals(searchedTransaction.getCATIndicator(),helper.getCATIndicator()); + } + + /** + * Successful response returned from a Settlement Retrieve Closed Batch request. + * https://apidocs.securenet.com/docs/settlement.html?lang=csharp#retrievebatch + */ + @Test public void settlementretrieveclosedbatchrequestreturnssuccessfully() throws Exception { // Arrange - BatchCloseResponse closeResponse = getBatchCloseResponse(); - - BatchRetrieveRequest request = new BatchRetrieveRequest(); - request.setDeveloperApplication(getDeveloperApplication()); - request.setId(Integer.valueOf(closeResponse.getBatchId())); - APIContext apiContext = new APIContext(); - BatchesController controller = new BatchesController(); + boolean containCATIndicator = false; + createTransaction(containCATIndicator); + BatchCloseResponse closeResponse = getBatchCloseResponse(); + + BatchRetrieveRequest request = helper.getABatchRetrieveRequest(); + request.setId(Integer.valueOf(closeResponse.getBatchId())); + APIContext apiContext = new APIContext(); + BatchesController controller = new BatchesController(); + // Act + BatchRetrieveResponse response = (BatchRetrieveResponse) controller.processRequest(apiContext, request, BatchRetrieveResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + + } + + /** + * Successful response returned from a Settlement Retrieve Closed Batch request Include CAT field. + * https://apidocs.securenet.com/docs/settlement.html?lang=csharp#retrievebatch + */ + @Test + public void settlementretrieveclosedbatchrequestWithCATIndicatorreturnssuccessfully() throws Exception { + // Arrange + boolean containCATIndicator = true; + int transactionId = createTransaction(containCATIndicator); + BatchCloseResponse closeResponse = getBatchCloseResponse(); + + BatchRetrieveRequest request = helper.getABatchRetrieveRequest(); + request.setId(Integer.valueOf(closeResponse.getBatchId())); + APIContext apiContext = new APIContext(); + BatchesController controller = new BatchesController(); // Act - BatchRetrieveResponse response = (BatchRetrieveResponse) controller.processRequest(apiContext,request,BatchRetrieveResponse.class); + BatchRetrieveResponse response = (BatchRetrieveResponse) controller.processRequest(apiContext, request, BatchRetrieveResponse.class); // Assert - Assert.assertTrue(response.toResponseString(), response.getSuccess()); - } - - /* + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + Transaction searchedTransaction = helper.getTransactionFromTransactionList(transactionId,response.getTransactions()); + Assert.assertEquals(searchedTransaction.getCATIndicator(),helper.getCATIndicator()); + } + + /* * Successful response returned from a Settlement Retrieve Current Batch request. - * https://apidocs.securenet.com/docs/settlement.html?lang=csharp#currentbatch + * https://apidocs.securenet.com/docs/settlement.html?lang=csharp#currentbatch */ - @Test + @Test public void settlementretrievingcurrentbatchrequestreturnssuccessfully() throws Exception { // Arrange - BatchCurrentRequest request = new BatchCurrentRequest(); - request.setDeveloperApplication(getDeveloperApplication()); - APIContext apiContext = new APIContext(); - BatchesController controller = new BatchesController(); + BatchCurrentRequest request = helper.getABatchCurrentRequest(); + APIContext apiContext = new APIContext(); + BatchesController controller = new BatchesController(); // Act - BatchCurrentResponse response = (BatchCurrentResponse) controller.processRequest(apiContext,request,BatchCurrentResponse.class); + BatchCurrentResponse response = (BatchCurrentResponse) controller.processRequest(apiContext, request, BatchCurrentResponse.class); // Assert - Assert.assertTrue(response.toResponseString(), response.getSuccess()); + Assert.assertTrue(response.toResponseString(), response.getSuccess()); } - - private BatchCloseResponse getBatchCloseResponse() throws Exception{ - BatchCloseRequest request = new BatchCloseRequest(); - request.setDeveloperApplication(getDeveloperApplication()); - APIContext apiContext = new APIContext(); - BatchesController controller = new BatchesController(); - BatchCloseResponse response = (BatchCloseResponse) controller.processRequest(apiContext,request,BatchCloseResponse.class); - Assert.assertTrue(response.toResponseString(), response.getSuccess()); - return response; - } - - private DeveloperApplication getDeveloperApplication() { - DeveloperApplication devApp = new DeveloperApplication(); - devApp.setDeveloperId(Integer.parseInt(config.getProperty("developerId"))); - devApp.setVersion(config.getProperty("versionId")); - return devApp; - } -} + private BatchCloseResponse getBatchCloseResponse() throws Exception { + BatchCloseRequest request = helper.getABachCloseRequest(); + APIContext apiContext = new APIContext(); + BatchesController controller = new BatchesController(); + BatchCloseResponse response = (BatchCloseResponse) controller.processRequest(apiContext, request, BatchCloseResponse.class); + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + return response; + } + + private int createTransaction(boolean containCATIndicator) + throws Exception { + // Arrange + ChargeRequest request = helper.getAChargeRequest(containCATIndicator); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + ChargeResponse response = (ChargeResponse) controller.processRequest(apiContext, request, ChargeResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + return response.getTransaction().getTransactionId(); + } +} \ No newline at end of file diff --git a/src/test/java/test/controllers/CustomersControllerTest.java b/src/test/java/test/controllers/CustomersControllerTest.java index 7b7b1ad..6f7efe1 100755 --- a/src/test/java/test/controllers/CustomersControllerTest.java +++ b/src/test/java/test/controllers/CustomersControllerTest.java @@ -151,11 +151,9 @@ public void secureNetVaultCreateCustomerAndPaymentAccountRequestReturnsSuccessfu public void secureNetVaultStoreAccountAfterChargeRequestReturnsSuccessfully() throws Exception { // Arrange - ChargeRequest request = new ChargeRequest(); - request.setDeveloperApplication(getDeveloperApplication()); - request.setCard(getCard()); + boolean containCATIndicator = false; + ChargeRequest request = helper.getAChargeRequest(containCATIndicator); request.setAddToVault(true); - request.setAmount(11d); APIContext apiContext = new APIContext(); CustomersController controller = new CustomersController(); // Act @@ -165,6 +163,26 @@ public void secureNetVaultStoreAccountAfterChargeRequestReturnsSuccessfully() Assert.assertTrue(response.toResponseString(),response.getSuccess()); } + /** + * Successful response returned from a Storing Acount After Charge request Include CAT field. + * https://apidocs.securenet.com/docs/vault.html?lang=csharp#storedaccount + */ + @Test + public void secureNetVaultStoreAccountAfterChargeRequestWithCATIndicatorReturnsSuccessfully() + throws Exception { + // Arrange + boolean containCATIndicator = true; + ChargeRequest request = helper.getAChargeRequest(containCATIndicator); + request.setAddToVault(true); + APIContext apiContext = new APIContext(); + CustomersController controller = new CustomersController(); + // Act + /* [UNSUPPORTED] 'var' as type is unsupported "var" */ + ChargeResponse response = (ChargeResponse) controller.processRequest(apiContext, request,ChargeResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(),response.getSuccess()); + Assert.assertEquals(response.getTransaction().getCATIndicator(),helper.getCATIndicator()); + } /** * Unit Tests for Creating a Payment Account, Creating an Installment Plan, * Updating the Installment Plan, Retrieving the Installment Plan, and @@ -257,7 +275,7 @@ private void secureNetvaultpaywithstoredvaultaccountrequestreturnssuccessfully( String customerId, String paymentMethodId) throws Exception { // Arrange ChargeRequest request = new ChargeRequest(); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); request.setPaymentVaultToken(getPaymentVaultToken(customerId,paymentMethodId)); request.setAmount(200D); request.setAddToVault(true); @@ -301,7 +319,7 @@ private void secureNetvaultupdatecustomerrequestreturnssuccessfully( UpdateCustomerRequest request = new UpdateCustomerRequest(); request.setCustomerId(customerId); request.setFirstName("new Name"); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); APIContext apiContext = new APIContext(); CustomersController controller = new CustomersController(); // Act @@ -325,8 +343,8 @@ private String secureNetvaultcreatepaymentaccountrequestreturnssuccessfully( // Arrange AddPaymentMethodRequest request = new AddPaymentMethodRequest(); request.setCustomerId(customerId); - request.setDeveloperApplication(getDeveloperApplication()); - request.setCard(getCard()); + request.setDeveloperApplication(helper.getDeveloperApplication()); + request.setCard(helper.getCard()); APIContext apiContext = new APIContext(); CustomersController controller = new CustomersController(); // Act @@ -368,10 +386,10 @@ private void secureNetvaultupdatepaymentaccountrequestreturnssuccessfully( // Arrange UpdatePaymentMethodRequest request = new UpdatePaymentMethodRequest(); request.setCustomerId(customerId); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); request.setPaymentMethodId(paymentMethodId); request.setPrimary(true); - Card card = getCard(); + Card card = helper.getCard(); card.setCvv("222"); request.setCard(card); APIContext apiContext = new APIContext(); @@ -393,7 +411,7 @@ private void secureNetvaultdeletepaymentaccountrequestreturnssuccessfully( RemovePaymentMethodRequest request = new RemovePaymentMethodRequest(); request.setCustomerId(customerId); request.setPaymentMethodId(paymentMethodId); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); APIContext apiContext = new APIContext(); CustomersController controller = new CustomersController(); // Act @@ -416,7 +434,7 @@ private String recurringbillingcreaterecurringpaymentplanrequestreturnssuccessfu // Arrange AddRecurringPaymentPlanRequest request = new AddRecurringPaymentPlanRequest(); request.setCustomerId(customerId); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); request.setPlan(getRecurringPaymentPlan(paymentMethodId)); APIContext apiContext = new APIContext(); CustomersController controller = new CustomersController(); @@ -465,7 +483,7 @@ private void recurringbillingupdaterecurringpaymentplanrequestreturnssuccessfull request.setCustomerId(customerId); request.setPlanId(planId); request.setIncludeRawObjects(true); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); request.setIncludeRequest(true); request.setPlan(getRecurringPaymentPlan(null)); APIContext apiContext = new APIContext(); @@ -491,7 +509,7 @@ private String recurringbillingcreateinstallmentplanrequestreturnssuccessfully( // Arrange AddInstallmentPaymentPlanRequest request = new AddInstallmentPaymentPlanRequest(); request.setCustomerId(customerId); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); request.setPlan(getInstallmentPlan(paymentMethodId)); APIContext apiContext = new APIContext(); CustomersController controller = new CustomersController(); @@ -556,7 +574,7 @@ private void recurringbillingupdateinstallmentplanrequestreturnssuccessfully( UpdateInstallmentPaymentPlanRequest request = new UpdateInstallmentPaymentPlanRequest(); request.setCustomerId(customerId); request.setPlanId(planId); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); request.setPlan(getInstallmentPlan(null)); APIContext apiContext = new APIContext(); CustomersController controller = new CustomersController(); @@ -580,7 +598,7 @@ private String recurringbillingcreatevariablepaymentplanrequestreturnssuccessful // Arrange AddVariablePaymentPlanRequest request = new AddVariablePaymentPlanRequest(); request.setCustomerId(customerId); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); request.setPlan(getVariablePaymentPlan(paymentMethodId)); APIContext apiContext = new APIContext(); CustomersController controller = new CustomersController(); @@ -609,7 +627,7 @@ private void recurringbillingupdatevariablepaymentplanrequestreturnssuccessfully UpdateVariablePaymentPlanRequest request = new UpdateVariablePaymentPlanRequest(); request.setCustomerId(customerId); request.setPlanId(planId); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); request.setPlan(getVariablePaymentPlan("1")); APIContext apiContext = new APIContext(); CustomersController controller = new CustomersController(); @@ -653,7 +671,7 @@ private void recurringbillingdeletepaymentplanrequestreturnssuccessfully( DeletePaymentPlanRequest request = new DeletePaymentPlanRequest(); request.setCustomerId(customerId); request.setPlanId(planId); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); APIContext apiContext = new APIContext(); CustomersController controller = new CustomersController(); // Act @@ -674,11 +692,11 @@ private VaultCustomerAndPaymentMethodRequest getVaultCustomerAndPaymentMethodReq customerRequest.setNotes("test notes"); customerRequest.setCompany("Test Company"); - customerRequest.setCard(getCard()); + customerRequest.setCard(helper.getCard()); customerRequest.setPrimary(true); - customerRequest.setAddress(getAddress()); - customerRequest.setDeveloperApplication(getDeveloperApplication()); + customerRequest.setAddress(helper.getAddress()); + customerRequest.setDeveloperApplication(helper.getDeveloperApplication()); UserDefinedField udf = new UserDefinedField(); udf.setUdfName("UDF1"); @@ -691,7 +709,7 @@ private VaultCustomerAndPaymentMethodRequest getVaultCustomerAndPaymentMethodReq private CreateCustomerRequest getCreateCustomerRequestObject() { CreateCustomerRequest customerRequest = new CreateCustomerRequest(); - customerRequest.setFirstName("Test"+String.valueOf(Math.random())); + customerRequest.setFirstName("Test" + String.valueOf(Math.random())); customerRequest.setLastName("Tester"); customerRequest.setPhoneNumber("512-122-1211"); customerRequest.setEmailAddress("some@emailaddress.com"); @@ -699,8 +717,8 @@ private CreateCustomerRequest getCreateCustomerRequestObject() { customerRequest.setNotes("test notes"); customerRequest.setCompany("Test Company"); - customerRequest.setAddress(getAddress()); - customerRequest.setDeveloperApplication(getDeveloperApplication()); + customerRequest.setAddress(helper.getAddress()); + customerRequest.setDeveloperApplication(helper.getDeveloperApplication()); UserDefinedField udf = new UserDefinedField(); udf.setUdfName("UDF1"); @@ -711,31 +729,6 @@ private CreateCustomerRequest getCreateCustomerRequestObject() { return customerRequest; } - private Address getAddress() { - Address address = new Address(); - address.setCity("Austin"); - address.setCountry("US"); - address.setLine1("123 Main St."); - address.setState("TX"); - address.setZip("78759"); - return address; - } - - private DeveloperApplication getDeveloperApplication() { - DeveloperApplication devApp = new DeveloperApplication(); - devApp.setDeveloperId(Integer.parseInt(config.getProperty("developerId"))); - devApp.setVersion(config.getProperty("versionId")); - return devApp; - } - - private Card getCard(){ - Card card = new Card(); - card.setAddress(getAddress()); - card.setCvv("123"); - card.setExpirationDate("07/2018"); - card.setNumber("4111111111111111"); - return card; - } private PaymentVaultToken getPaymentVaultToken(String customerId, String paymentMethodId) { PaymentVaultToken paymentVaultToken = new PaymentVaultToken(); diff --git a/src/test/java/test/controllers/PaymentsControllerTest.java b/src/test/java/test/controllers/PaymentsControllerTest.java index 92b3cad..12282dc 100755 --- a/src/test/java/test/controllers/PaymentsControllerTest.java +++ b/src/test/java/test/controllers/PaymentsControllerTest.java @@ -7,6 +7,8 @@ import java.io.InputStream; import java.util.Properties; +import SecureNetRestApiSDK.Api.Requests.*; +import SecureNetRestApiSDK.Api.Responses.*; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -19,18 +21,6 @@ import SecureNetRestApiSDK.Api.Models.Check; import SecureNetRestApiSDK.Api.Models.DeveloperApplication; import SecureNetRestApiSDK.Api.Models.ExtendedInformation; -import SecureNetRestApiSDK.Api.Requests.AuthorizeRequest; -import SecureNetRestApiSDK.Api.Requests.ChargeRequest; -import SecureNetRestApiSDK.Api.Requests.CreditRequest; -import SecureNetRestApiSDK.Api.Requests.PriorAuthCaptureRequest; -import SecureNetRestApiSDK.Api.Requests.RefundRequest; -import SecureNetRestApiSDK.Api.Requests.VoidRequest; -import SecureNetRestApiSDK.Api.Responses.AuthorizeResponse; -import SecureNetRestApiSDK.Api.Responses.ChargeResponse; -import SecureNetRestApiSDK.Api.Responses.CreditResponse; -import SecureNetRestApiSDK.Api.Responses.PriorAuthCaptureResponse; -import SecureNetRestApiSDK.Api.Responses.RefundResponse; -import SecureNetRestApiSDK.Api.Responses.VoidResponse; import test.HelperTest; public class PaymentsControllerTest { @@ -55,10 +45,8 @@ public void creditcardpresentauthorizationOnlyandpriorAuthCapturerequestsreturns throws Exception { // Arrange int transactionId = creditcardpresentauthorizationOnlyrequestreturnssuccessfully(); - PriorAuthCaptureRequest request = new PriorAuthCaptureRequest(); - request.setAmount(20d); - request.setTransactionId(transactionId); - request.setDeveloperApplication(getDeveloperApplication()); + boolean includeTip = false; + PriorAuthCaptureRequest request = helper.getAPriorAuthCaptureRequest(transactionId,includeTip); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -76,12 +64,9 @@ public void creditcardpresentauthorizationOnlyandpriorAuthCapturerequestsreturns private int creditcardpresentauthorizationOnlyrequestreturnssuccessfully() throws Exception { // Arrange - AuthorizeRequest request = new AuthorizeRequest(); - request.setCard(getCard()); + boolean containCATIndicator = false; + AuthorizeRequest request = helper.getAnAuthorizeRequiest(containCATIndicator); request.setAddToVault(true); - request.setAmount(20d); - request.setDeveloperApplication(getDeveloperApplication()); - request.setExtendedInformation(getExtendedInformation()); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -93,6 +78,49 @@ private int creditcardpresentauthorizationOnlyrequestreturnssuccessfully() return response.getTransaction().getTransactionId(); } + /** + * Unit Tests for an AuthorizationOnly request and a subsequent + * PriorAuthCapture request including CAT field. Tests combined in one method to pass the + * required transaction identifier and guaranteee the order of operation. + */ + @Test + public void creditcardpresentauthorizationOnlyandpriorAuthCapturerequestsWithCATIndicatorreturnssuccessfully() + throws Exception { + // Arrange + int transactionId = creditcardpresentauthorizationOnlyrequestWithCATIndicatorreturnssuccessfully(); + boolean includeTip = false; + PriorAuthCaptureRequest request = helper.getAPriorAuthCaptureRequest(transactionId,includeTip); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + PriorAuthCaptureResponse response = (PriorAuthCaptureResponse) controller.processRequest(apiContext, request, PriorAuthCaptureResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + Assert.assertEquals(response.getTransaction().getCATIndicator(), helper.getCATIndicator()); + } + + /** + * Successful response returned from a Credit Card Present Authorization including CAT field + * Only request. + * https://apidocs.securenet.com/docs/creditcardpresent.html?lang + * =JSON#authonly + */ + private int creditcardpresentauthorizationOnlyrequestWithCATIndicatorreturnssuccessfully() + throws Exception { + // Arrange + boolean containCATIndicator = true; + AuthorizeRequest request = helper.getAnAuthorizeRequiest(containCATIndicator); + request.setAddToVault(true); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + AuthorizeResponse response = (AuthorizeResponse) controller.processRequest(apiContext, request,AuthorizeResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + Assert.assertEquals(response.getTransaction().getCATIndicator(), helper.getCATIndicator()); + return response.getTransaction().getTransactionId(); + } + /** * Successful response returned from a Credit Card Present Charge request. @@ -103,12 +131,9 @@ private int creditcardpresentauthorizationOnlyrequestreturnssuccessfully() public void creditcardpresentchargerequestreturnssuccessfully() throws Exception { // Arrange - ChargeRequest request = new ChargeRequest(); + boolean containCATIndicator = false; + ChargeRequest request = helper.getAChargeRequest(containCATIndicator); request.setAddToVault(true); - request.setAmount(20d); - request.setCard(getCard()); - request.setDeveloperApplication(getDeveloperApplication()); - request.setExtendedInformation(getExtendedInformation()); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -119,6 +144,27 @@ public void creditcardpresentchargerequestreturnssuccessfully() Assert.assertEquals(response.getTransaction().getDynamicMCC(), helper.getResponseDynamicMCC()); } + /** + * Successful response returned from a Credit Card Present Charge request including CAT field. + * https + * ://apidocs.securenet.com/docs/creditcardpresent.html?lang=JSON#charge + */ + @Test + public void creditcardpresentchargerequestWitchCATIndicatorreturnssuccessfully() + throws Exception { + // Arrange + boolean containCATIndicator = true; + ChargeRequest request = helper.getAChargeRequest(containCATIndicator); + request.setAddToVault(true); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + ChargeResponse response = (ChargeResponse) controller.processRequest(apiContext, request,ChargeResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + Assert.assertEquals(response.getTransaction().getCATIndicator(), helper.getCATIndicator()); + } + /** * Unit Tests for an IncludeTip AuthorizationOnly request and a subsequent * PriorAuthCapture request. Tests combined in one method to pass the @@ -129,10 +175,8 @@ public void creditcardpresentincludeTipauthorizationOnlyandpriorAuthCapturereque throws Exception { // Arrange int transactionId = creditcardpresentincludeTipauthorizationOnlyrequestreturnssuccessfully(); - PriorAuthCaptureRequest request = new PriorAuthCaptureRequest(); - request.setAmount(20d); - request.setTransactionId(transactionId); - request.setDeveloperApplication(getDeveloperApplication()); + boolean includeTip = true; + PriorAuthCaptureRequest request = helper.getAPriorAuthCaptureRequest(transactionId,includeTip); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -150,11 +194,9 @@ public void creditcardpresentincludeTipauthorizationOnlyandpriorAuthCapturereque private int creditcardpresentincludeTipauthorizationOnlyrequestreturnssuccessfully() throws Exception { // Arrange - AuthorizeRequest request = new AuthorizeRequest(); - request.setCard(getCard()); - request.setAmount(20d); - request.setDeveloperApplication(getDeveloperApplication()); - request.setExtendedInformation(getExtendedInformation()); + boolean containCATIndicator = false; + AuthorizeRequest request =helper.getAnAuthorizeRequiest(containCATIndicator); + request.setAddToVault(true); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -163,7 +205,49 @@ private int creditcardpresentincludeTipauthorizationOnlyrequestreturnssuccessful Assert.assertTrue(response.toResponseString(), response.getSuccess()); Assert.assertEquals(response.getTransaction().getSoftDescriptor(), helper.getResponseSoftDescriptor()); Assert.assertEquals(response.getTransaction().getDynamicMCC(), helper.getResponseDynamicMCC()); + return response.getTransaction().getTransactionId(); + } + /** + * Unit Tests for an IncludeTip AuthorizationOnly request and a subsequent + * PriorAuthCapture request Include CAT field. Tests combined in one method to pass the + * required transaction identifier and guaranteee the order of operation. + */ + @Test + public void creditcardpresentincludeTipauthorizationOnlyandpriorAuthCapturerequestsWithCATIndicatorreturnssuccessfully() + throws Exception { + // Arrange + int transactionId = creditcardpresentincludeTipauthorizationOnlyrequestretWithCATIndicatorurnssuccessfully(); + boolean includeTip = true; + PriorAuthCaptureRequest request = helper.getAPriorAuthCaptureRequest(transactionId,includeTip); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + PriorAuthCaptureResponse response = (PriorAuthCaptureResponse) controller.processRequest(apiContext, request,PriorAuthCaptureResponse.class); + // Assert + Assert.assertEquals(response.getTransaction().getCATIndicator(), helper.getCATIndicator()); + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + } + + /** + * Successful response returned from a Credit Card Present Include Tip + * AuthorizationOnly request Include CAT field. + * https://apidocs.securenet.com/docs/creditcardpresent + * .html?lang=JSON#includetip + */ + private int creditcardpresentincludeTipauthorizationOnlyrequestretWithCATIndicatorurnssuccessfully() + throws Exception { + // Arrange + boolean containCATIndicator = true; + AuthorizeRequest request =helper.getAnAuthorizeRequiest(containCATIndicator); + request.setAddToVault(true); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + AuthorizeResponse response = (AuthorizeResponse) controller.processRequest(apiContext, request,AuthorizeResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + Assert.assertEquals(response.getTransaction().getCATIndicator(), helper.getCATIndicator()); return response.getTransaction().getTransactionId(); } @@ -178,11 +262,8 @@ private int creditcardpresentincludeTipauthorizationOnlyrequestreturnssuccessful public void creditcardpresentchargerequestincludingaddressreturnssuccessfully() throws Exception { // Arrange - ChargeRequest request = new ChargeRequest(); - request.setCard(getCard()); - request.setDeveloperApplication(getDeveloperApplication()); - request.setAmount(20d); - request.setExtendedInformation(getExtendedInformation()); + boolean containCATIndicator = false; + ChargeRequest request = helper.getAChargeRequest(containCATIndicator); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -193,6 +274,70 @@ public void creditcardpresentchargerequestincludingaddressreturnssuccessfully() Assert.assertEquals(response.getTransaction().getDynamicMCC(), helper.getResponseDynamicMCC()); } + /** + * Successful response returned from a Credit Card Present Charge request + * that includes the address and CAT field. + * https://apidocs.securenet.com/docs/creditcardpresent + * .html?lang=JSON#includeaddress + */ + @Test + public void creditcardpresentchargerequestincludingaddressWithCATIndicatorreturnssuccessfully() + throws Exception { + // Arrange + boolean containCATIndicator = true; + ChargeRequest request = helper.getAChargeRequest(containCATIndicator); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + ChargeResponse response = (ChargeResponse) controller.processRequest(apiContext, request,ChargeResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + Assert.assertEquals(response.getTransaction().getCATIndicator(), helper.getCATIndicator()); + } + + /** + * Successful response returned from a Verify request including CAT field + * Only request. + * https://apidocs.securenet.com/docs/creditcardpresent.html?lang + * =json#verify + */ + @Test + public void creditcardpresentverifyrequestreturnssuccessfully() + throws Exception { + // Arrange + boolean containCATIndicator = false; + VerifyRequest request = helper.getAVerifyRequest(containCATIndicator); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + VerifyResponse response = (VerifyResponse) controller.processRequest(apiContext, request,VerifyResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + Assert.assertEquals(response.getTransaction().getSoftDescriptor(), helper.getResponseSoftDescriptor()); + Assert.assertEquals(response.getTransaction().getDynamicMCC(), helper.getResponseDynamicMCC()); + } + + /** + * Successful response returned from a Verify request including CAT field + * Only request. + * https://apidocs.securenet.com/docs/creditcardpresent.html?lang + * =json#verify + */ + @Test + public void creditcardpresentverifyrequestWithCATIndicatorreturnssuccessfully() + throws Exception { + // Arrange + boolean containCATIndicator = true; + VerifyRequest request = helper.getAVerifyRequest(containCATIndicator); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + VerifyResponse response = (VerifyResponse) controller.processRequest(apiContext, request,VerifyResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + Assert.assertEquals(response.getTransaction().getCATIndicator(), helper.getCATIndicator()); + } + /** * Unit Tests for an AuthorizationOnly request and a subsequent * PriorAuthCapture request. Tests combined in one method to pass the @@ -205,7 +350,7 @@ public void creditcardnotpresentauthorizationOnlyandpriorAuthCapturerequestsretu int transactionId = creditcardnotpresentauthorizationOnlyrequestreturnssuccessfully(); PriorAuthCaptureRequest request = new PriorAuthCaptureRequest(); request.setAmount(10d); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); request.setTransactionId(transactionId); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); @@ -225,11 +370,11 @@ private int creditcardnotpresentauthorizationOnlyrequestreturnssuccessfully() throws Exception { // Arrange AuthorizeRequest request = new AuthorizeRequest(); - request.setDeveloperApplication(getDeveloperApplication()); - request.setCard(getCard()); + request.setDeveloperApplication(helper.getDeveloperApplication()); + request.setCard(helper.getCard()); request.setAddToVault(true); request.setAmount(20d); - request.setExtendedInformation(getExtendedInformation()); + request.setExtendedInformation(helper.getExtendedInformation(false)); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -254,11 +399,11 @@ public void creditcardnotpresentchargeauthorizationandcapturerequestreturnssucce throws Exception { // Arrange ChargeRequest request = new ChargeRequest(); - request.setCard(getCard()); + request.setCard(helper.getCard()); request.setAddToVault(true); request.setAmount(100d); - request.setDeveloperApplication(getDeveloperApplication()); - ExtendedInformation extendedInfo = getExtendedInformation(); + request.setDeveloperApplication(helper.getDeveloperApplication()); + ExtendedInformation extendedInfo = helper.getExtendedInformation(false); extendedInfo.setTypeOfGoods("PHYSICAL"); request.setExtendedInformation(extendedInfo); APIContext apiContext = new APIContext(); @@ -281,10 +426,10 @@ public void creditcardnotpresentincludeaddresrequestreturnssuccessfully() throws Exception { // Arrange ChargeRequest request = new ChargeRequest(); - request.setCard(getCard()); + request.setCard(helper.getCard()); request.setAmount(80d); - request.setDeveloperApplication(getDeveloperApplication()); - ExtendedInformation extendedInfo = getExtendedInformation(); + request.setDeveloperApplication(helper.getDeveloperApplication()); + ExtendedInformation extendedInfo = helper.getExtendedInformation(false); extendedInfo.setTypeOfGoods("PHYSICAL"); request.setExtendedInformation(extendedInfo); APIContext apiContext = new APIContext(); @@ -306,10 +451,10 @@ private void creditcardnotpresentchargeusingtokenizationrequestreturnssuccessful String token) throws Exception { // Arrange ChargeRequest request = new ChargeRequest(); - request.setCard(getCard()); + request.setCard(helper.getCard()); request.setAmount(80d); - request.setDeveloperApplication(getDeveloperApplication()); - ExtendedInformation extendedInfo = getExtendedInformation(); + request.setDeveloperApplication(helper.getDeveloperApplication()); + ExtendedInformation extendedInfo = helper.getExtendedInformation(false); extendedInfo.setTypeOfGoods("PHYSICAL"); request.setExtendedInformation(extendedInfo); APIContext apiContext = new APIContext(); @@ -331,9 +476,9 @@ public void aCHpaybycheckchargerequestreturnssuccessfully() throws Exception { // Arrange ChargeRequest request = new ChargeRequest(); - request.setCheck(getCheck()); + request.setCheck(helper.getCheck()); request.setAmount(100d); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -361,14 +506,14 @@ public void aCHchargeaccountusingPOSrequestreturnssuccessfully() additionalInfo.setTerminalState("TX"); extendedInfo.setAdditionalTerminalInfo(additionalInfo); - Check check = getCheck(); + Check check = helper.getCheck(); check.setCheckType("POINT_OF_SALE"); check.setVerification("NONE"); request.setCheck(check); request.setExtendedInformation(extendedInfo); request.setAmount(11d); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -390,12 +535,12 @@ public void aCHaddbillingaddresschargerequestreturnssuccessfully() // Arrange ChargeRequest request = new ChargeRequest(); - Check check = getCheck(); - check.setAddress(getAddress()); + Check check = helper.getCheck(); + check.setAddress(helper.getAddress()); request.setCheck(check); request.setAmount(11d); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -415,12 +560,12 @@ public void aCHpayingbycheckwithverificationchargerequestreturnssuccessfully() // Arrange ChargeRequest request = new ChargeRequest(); - Check check = getCheck(); + Check check = helper.getCheck(); check.setVerification("ACH_PROVIDER"); request.setCheck(check); request.setAmount(11d); - request.setDeveloperApplication(getDeveloperApplication()); + request.setDeveloperApplication(helper.getDeveloperApplication()); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -437,11 +582,8 @@ public void aCHpayingbycheckwithverificationchargerequestreturnssuccessfully() public void creditscreditanaccountrequestreturnssuccessfully() throws Exception { // Arrange - CreditRequest request = new CreditRequest(); - request.setCard(getCard()); - request.setAmount(1.05d); - request.setDeveloperApplication(getDeveloperApplication()); - request.setExtendedInformation(getExtendedInformation()); + boolean containCATIndicator = false; + CreditRequest request = helper.getACreditRequest(containCATIndicator); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -452,6 +594,26 @@ public void creditscreditanaccountrequestreturnssuccessfully() Assert.assertEquals(response.getTransaction().getDynamicMCC(), helper.getResponseDynamicMCC()); } + /** + * Successful response returned from a Credit An Account request Include CAT field. + * https://apidocs.securenet.com/docs/credits.html?lang=csharp + */ + @Test + public void creditscreditanaccountrequestWithCATIndicatorreturnssuccessfully() + throws Exception { + // Arrange + boolean containCATIndicator = true; + CreditRequest request = helper.getACreditRequest(containCATIndicator); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + CreditResponse response = (CreditResponse) controller.processRequest(apiContext, request,CreditResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + Assert.assertEquals(response.getTransaction().getCATIndicator(), helper.getCATIndicator()); + } + + /** * Unit Tests for a Charge request and a subsequent Refund request. Tests * combined in one method to pass the required transaction identifier and @@ -461,9 +623,7 @@ public void creditscreditanaccountrequestreturnssuccessfully() public void refundsChargeandrefundrequestsreturnssuccessfully() throws Exception { int transactionId = refundschargerequestreturnssuccessfully(); - RefundRequest request = new RefundRequest(); - request.setDeveloperApplication(getDeveloperApplication()); - request.setTransactionId(transactionId); + RefundRequest request = helper.getARefundRequest(transactionId); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -479,11 +639,8 @@ public void refundsChargeandrefundrequestsreturnssuccessfully() */ private int refundschargerequestreturnssuccessfully() throws Exception { // Arrange - ChargeRequest request = new ChargeRequest(); - request.setCard(getCard()); - request.setAmount(10d); - request.setDeveloperApplication(getDeveloperApplication()); - request.setExtendedInformation(getExtendedInformation()); + boolean containCATIndicator = false; + ChargeRequest request = helper.getAChargeRequest(containCATIndicator); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -496,6 +653,45 @@ private int refundschargerequestreturnssuccessfully() throws Exception { return response.getTransaction().getTransactionId(); } + /** + * Unit Tests for a Charge request and a subsequent Refund request Include CAT field. Tests + * combined in one method to pass the required transaction identifier and + * guaranteee the order of operation. + */ + @Test + public void refundsChargeandrefundrequestWithCATIndicatorsreturnssuccessfully() + throws Exception { + int transactionId = refundschargerequestWithCATIndicatorreturnssuccessfully(); + RefundRequest request = helper.getARefundRequest(transactionId); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + RefundResponse response = (RefundResponse) controller.processRequest(apiContext, request,RefundResponse.class); + // Assert + Assert.assertEquals(response.getTransaction().getCATIndicator(), helper.getCATIndicator()); + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + } + + /** + * Successful response returned from a Credit Card Present Charge request Include CAT field. + * https + * ://apidocs.securenet.com/docs/creditcardpresent.html?lang=JSON#charge + */ + private int refundschargerequestWithCATIndicatorreturnssuccessfully() throws Exception { + // Arrange + boolean containCATIndicator = true; + ChargeRequest request = helper.getAChargeRequest(containCATIndicator); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + ChargeResponse response = (ChargeResponse) controller.processRequest(apiContext, request,ChargeResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + Assert.assertEquals(response.getTransaction().getCATIndicator(), helper.getCATIndicator()); + + return response.getTransaction().getTransactionId(); + } + /** * Unit Tests for a Chrage request and a subsequent Void request. Tests * combined in one method to pass the required transaction identifier and @@ -506,9 +702,7 @@ public void voidschargeandvoidrequestsreturnssuccessfully() throws Exception { // Arrange int transactionId = voidschargerequestreturnssuccessfully(); - VoidRequest request = new VoidRequest(); - request.setTransactionId(transactionId); - request.setDeveloperApplication(getDeveloperApplication()); + VoidRequest request = helper.getAVoidRequest(transactionId); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -524,11 +718,8 @@ public void voidschargeandvoidrequestsreturnssuccessfully() */ private int voidschargerequestreturnssuccessfully() throws Exception { // Arrange - ChargeRequest request = new ChargeRequest(); - request.setCard(getCard()); - request.setAmount(10d); - request.setDeveloperApplication(getDeveloperApplication()); - request.setExtendedInformation(getExtendedInformation()); + boolean containCATIndicator = false; + ChargeRequest request = helper.getAChargeRequest(containCATIndicator); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -537,50 +728,91 @@ private int voidschargerequestreturnssuccessfully() throws Exception { Assert.assertTrue(response.toResponseString(), response.getSuccess()); Assert.assertEquals(response.getTransaction().getSoftDescriptor(), helper.getResponseSoftDescriptor()); Assert.assertEquals(response.getTransaction().getDynamicMCC(), helper.getResponseDynamicMCC()); - return response.getTransaction().getTransactionId(); } - - private Address getAddress() { - Address address = new Address(); - address.setCity("Austin"); - address.setCountry("US"); - address.setLine1("123 Main St."); - address.setState("TX"); - address.setZip("78759"); - return address; + /** + * Unit Tests for a Chrage request and a subsequent Void request Include CAT field. Tests + * combined in one method to pass the required transaction identifier and + * guaranteee the order of operation. + */ + @Test + public void voidschargeandvoidrequestsWithCATIndicatorreturnssuccessfully() + throws Exception { + // Arrange + int transactionId = voidschargerequestWithCATIndicatorreturnssuccessfully(); + VoidRequest request = helper.getAVoidRequest(transactionId); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + VoidResponse response = (VoidResponse) controller.processRequest(apiContext, request,VoidResponse.class); + // Assert + Assert.assertEquals(response.getTransaction().getCATIndicator(), helper.getCATIndicator()); + Assert.assertTrue(response.toResponseString(), response.getSuccess()); } - private DeveloperApplication getDeveloperApplication() { - DeveloperApplication devApp = new DeveloperApplication(); - devApp.setDeveloperId(Integer.parseInt(config.getProperty("developerId"))); - devApp.setVersion(config.getProperty("versionId")); - return devApp; - } - - private Card getCard(){ - Card card = new Card(); - card.setAddress(getAddress()); - card.setCvv("123"); - card.setExpirationDate("07/2018"); - card.setNumber("4111111111111111"); - return card; - } - - private Check getCheck() { - Check check = new Check(); - check.setFirstName("Bruce"); - check.setLastName("Wayne"); - check.setRoutingNumber("222371863"); - check.setAccountNumber("123456"); - return check; + /** + * Successful response returned from a Credit Card Present Charge request Include CAT field. + * Successful response returned from a Credit Card Present Charge request Include CAT field. + * https + * ://apidocs.securenet.com/docs/creditcardpresent.html?lang=JSON#charge + */ + private int voidschargerequestWithCATIndicatorreturnssuccessfully() throws Exception { + // Arrange + boolean containCATIndicator = true; + ChargeRequest request = helper.getAChargeRequest(containCATIndicator); + APIContext apiContext = new APIContext(); + PaymentsController controller = new PaymentsController(); + // Act + ChargeResponse response = (ChargeResponse) controller.processRequest(apiContext, request,ChargeResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + Assert.assertEquals(response.getTransaction().getCATIndicator(), helper.getCATIndicator()); + return response.getTransaction().getTransactionId(); } - private ExtendedInformation getExtendedInformation() { - ExtendedInformation extendedInfo = new ExtendedInformation(); - extendedInfo.setSoftDescriptor(helper.getRequestSoftDescriptor()); - extendedInfo.setDynamicMCC(helper.getRequestDynamicMCC()); - return extendedInfo; - } +// private Address getAddress() { +// Address address = new Address(); +// address.setCity("Austin"); +// address.setCountry("US"); +// address.setLine1("123 Main St."); +// address.setState("TX"); +// address.setZip("78759"); +// return address; +// } +// +// private DeveloperApplication getDeveloperApplication() { +// DeveloperApplication devApp = new DeveloperApplication(); +// devApp.setDeveloperId(Integer.parseInt(config.getProperty("developerId"))); +// devApp.setVersion(config.getProperty("versionId")); +// return devApp; +// } +// +// private Card getCard(){ +// Card card = new Card(); +// card.setAddress(getAddress()); +// card.setCvv("123"); +// card.setExpirationDate("07/2018"); +// card.setNumber("4111111111111111"); +// return card; +// } +// +// private Check getCheck() { +// Check check = new Check(); +// check.setFirstName("Bruce"); +// check.setLastName("Wayne"); +// check.setRoutingNumber("222371863"); +// check.setAccountNumber("123456"); +// return check; +// } +// +// private ExtendedInformation getExtendedInformation() { +// ExtendedInformation extendedInfo = new ExtendedInformation(); +// extendedInfo.setSoftDescriptor(helper.getRequestSoftDescriptor()); +// extendedInfo.setDynamicMCC(helper.getRequestDynamicMCC()); +// AdditionalTerminalInfo additionalInfo = new AdditionalTerminalInfo(); +// additionalInfo.setCATIndicator(helper.getRequestCATIndicator()); +// extendedInfo.setAdditionalTerminalInfo(additionalInfo); +// return extendedInfo; +// } } diff --git a/src/test/java/test/controllers/TransactionsControllerTest.java b/src/test/java/test/controllers/TransactionsControllerTest.java index 08dc5fe..05c2223 100755 --- a/src/test/java/test/controllers/TransactionsControllerTest.java +++ b/src/test/java/test/controllers/TransactionsControllerTest.java @@ -4,8 +4,11 @@ package test.controllers; import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.List; import java.util.Properties; +import SecureNetRestApiSDK.Api.Models.Transaction; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -24,107 +27,124 @@ import SecureNetRestApiSDK.Api.Responses.TransactionRetrieveResponse; import SecureNetRestApiSDK.Api.Responses.TransactionSearchResponse; import SecureNetRestApiSDK.Api.Responses.TransactionUpdateResponse; +import test.HelperTest; public class TransactionsControllerTest { Properties config ; + HelperTest helper; @Before public void before() throws Exception{ InputStream stream = this.getClass().getResourceAsStream("/config.properties"); config = new Properties(); config.load(stream); + helper = new HelperTest(); } - /** + /** * Successful response returned from a Search Transaction request. - * https://apidocs.securenet.com/docs/transactions.html?lang=csharp#search + * https://apidocs.securenet.com/docs/transactions.html?lang=csharp#search */ @Test public void transactionreportingandmanagementsearchtransactionrequestreturnssuccessfully() throws Exception { // Arramge - TransactionSearchRequest request = new TransactionSearchRequest(); - request.setDeveloperApplication(getDeveloperApplication()); - request.setTransactionId(createTransaction()); - APIContext apiContext = new APIContext(); - TransactionsController controller = new TransactionsController(); + TransactionSearchRequest request = helper.getATransactionSearchRequiest(); + boolean containCATIndicator = false; + request.setTransactionId(createTransaction(containCATIndicator)); + APIContext apiContext = new APIContext(); + TransactionsController controller = new TransactionsController(); // Act TransactionSearchResponse response = (TransactionSearchResponse) controller.processRequest(apiContext,request,TransactionSearchResponse.class); // Assert Assert.assertTrue(response.toResponseString(), response.getSuccess()); } + /** + * Successful response returned from a Search Transaction request Include CAT field. + * https://apidocs.securenet.com/docs/transactions.html?lang=csharp#search + */ + @Test + public void transactionreportingandmanagementsearchtransactionrequestWithCATIndicatorreturnssuccessfully() throws Exception { + // Arramge + TransactionSearchRequest request = helper.getATransactionSearchRequiest(); + boolean containCATIndicator = true; + request.setTransactionId(createTransaction(containCATIndicator)); + APIContext apiContext = new APIContext(); + TransactionsController controller = new TransactionsController(); + // Act + TransactionSearchResponse response = (TransactionSearchResponse) controller.processRequest(apiContext,request,TransactionSearchResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + List transactions = response.getTransactions(); + for(Transaction transaction : transactions){ + Assert.assertEquals(transaction.getCATIndicator(),helper.getCATIndicator()); + } + } + /** * Successful response returned from a Retrieve Transaction request. - * https://apidocs.securenet.com/docs/transactions.html?lang=csharp#retrieve + * https://apidocs.securenet.com/docs/transactions.html?lang=csharp#retrieve */ @Test public void transactionreportingandmanagementretrievetransactionrequestreturnssuccessfully() throws Exception { // Arrange - TransactionRetrieveRequest request = new TransactionRetrieveRequest(); - request.setDeveloperApplication(getDeveloperApplication()); - request.setTransactionId(createTransaction()); - APIContext apiContext = new APIContext(); - TransactionsController controller = new TransactionsController(); + TransactionRetrieveRequest request = helper.getATransactionRetrieveRequest(); + boolean containCATIndicator = false; + request.setTransactionId(createTransaction(containCATIndicator)); + APIContext apiContext = new APIContext(); + TransactionsController controller = new TransactionsController(); // Act TransactionRetrieveResponse response = (TransactionRetrieveResponse) controller.processRequest(apiContext,request,TransactionRetrieveResponse.class); // Assert Assert.assertTrue(response.toResponseString(), response.getSuccess()); } + /** + * Successful response returned from a Retrieve Transaction request Include CAT field. + * https://apidocs.securenet.com/docs/transactions.html?lang=csharp#retrieve + */ + @Test + public void transactionreportingandmanagementretrievetransactionrequestWithCATIndicatorreturnssuccessfully() throws Exception { + // Arrange + TransactionRetrieveRequest request = helper.getATransactionRetrieveRequest(); + boolean containCATIndicator = true; + request.setTransactionId(createTransaction(containCATIndicator)); + APIContext apiContext = new APIContext(); + TransactionsController controller = new TransactionsController(); + // Act + TransactionRetrieveResponse response = (TransactionRetrieveResponse) controller.processRequest(apiContext,request,TransactionRetrieveResponse.class); + // Assert + Assert.assertTrue(response.toResponseString(), response.getSuccess()); + List transactions = response.getTransactions(); + for(Transaction transaction : transactions){ + Assert.assertEquals(transaction.getCATIndicator(),helper.getCATIndicator()); + } + } + /** * Successful response returned from an Update Transaction request. - * https://apidocs.securenet.com/docs/transactions.html?lang=csharp#update + * https://apidocs.securenet.com/docs/transactions.html?lang=csharp#update */ @Test public void transactionreportingandmanagementupdatetransactionrequestreturnssuccessfully() throws Exception { // Arrange - TransactionUpdateRequest request = new TransactionUpdateRequest(); - request.setDeveloperApplication(getDeveloperApplication()); - request.setReferenceTransactionId(createTransaction()); - APIContext apiContext = new APIContext(); - TransactionsController controller = new TransactionsController(); + TransactionUpdateRequest request = helper.getATransactionUpdateRequest(); + boolean containCATIndicator = false; + request.setReferenceTransactionId(createTransaction(containCATIndicator)); + APIContext apiContext = new APIContext(); + TransactionsController controller = new TransactionsController(); // Act TransactionUpdateResponse response = (TransactionUpdateResponse) controller.processRequest(apiContext,request,TransactionUpdateResponse.class); // Assert Assert.assertTrue(response.toResponseString(), response.getSuccess()); } - - private DeveloperApplication getDeveloperApplication() { - DeveloperApplication devApp = new DeveloperApplication(); - devApp.setDeveloperId(Integer.parseInt(config.getProperty("developerId"))); - devApp.setVersion(config.getProperty("versionId")); - return devApp; - } - - private Card getCard(){ - Card card = new Card(); - card.setAddress(getAddress()); - card.setCvv("123"); - card.setExpirationDate("07/2018"); - card.setNumber("4111111111111111"); - return card; - } - - private Address getAddress() { - Address address = new Address(); - address.setCity("Austin"); - address.setCountry("US"); - address.setLine1("123 Main St."); - address.setState("TX"); - address.setZip("78759"); - return address; - } - - private int createTransaction() + + private int createTransaction(boolean containCATIndicator) throws Exception { // Arrange - AuthorizeRequest request = new AuthorizeRequest(); - request.setCard(getCard()); - request.setAddToVault(true); - request.setAmount(20d); - request.setDeveloperApplication(getDeveloperApplication()); + AuthorizeRequest request = helper.getAnAuthorizeRequiest(containCATIndicator); APIContext apiContext = new APIContext(); PaymentsController controller = new PaymentsController(); // Act @@ -132,7 +152,7 @@ private int createTransaction() // Assert Assert.assertTrue(response.toResponseString(), response.getSuccess()); return response.getTransaction().getTransactionId(); - } + } }