Skip to content

Commit 0a72248

Browse files
committed
Test files for Cybs REST API Reference
1 parent 3c3f5f4 commit 0a72248

File tree

2 files changed

+202
-0
lines changed

2 files changed

+202
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package net.authorize.sample.PaymentTransactions;
2+
3+
import java.math.BigDecimal;
4+
import java.math.RoundingMode;
5+
6+
import net.authorize.Environment;
7+
import net.authorize.api.contract.v1.ANetApiResponse;
8+
import net.authorize.api.contract.v1.CreateTransactionRequest;
9+
import net.authorize.api.contract.v1.CreateTransactionResponse;
10+
import net.authorize.api.contract.v1.CreditCardType;
11+
import net.authorize.api.contract.v1.MerchantAuthenticationType;
12+
import net.authorize.api.contract.v1.MessageTypeEnum;
13+
import net.authorize.api.contract.v1.PaymentType;
14+
import net.authorize.api.contract.v1.TransactionRequestType;
15+
import net.authorize.api.contract.v1.TransactionResponse;
16+
import net.authorize.api.contract.v1.TransactionTypeEnum;
17+
import net.authorize.api.controller.CreateTransactionController;
18+
import net.authorize.api.controller.base.ApiOperationBase;
19+
20+
public class AuthorizeCreditCard {
21+
22+
//
23+
// Run this sample from command line with:
24+
// java -jar target/AuthorizeCreditCard-jar-with-dependencies.jar
25+
//
26+
public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
27+
28+
// Set the request to operate in either the sandbox or production environment
29+
ApiOperationBase.setEnvironment(Environment.SANDBOX);
30+
31+
// Create object with merchant authentication details
32+
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
33+
merchantAuthenticationType.setName(apiLoginId);
34+
merchantAuthenticationType.setTransactionKey(transactionKey);
35+
36+
// Populate the payment data
37+
PaymentType paymentType = new PaymentType();
38+
CreditCardType creditCard = new CreditCardType();
39+
creditCard.setCardNumber("4242424242424242");
40+
creditCard.setExpirationDate("0822");
41+
paymentType.setCreditCard(creditCard);
42+
43+
// Create the payment transaction object
44+
TransactionRequestType txnRequest = new TransactionRequestType();
45+
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_ONLY_TRANSACTION.value());
46+
txnRequest.setPayment(paymentType);
47+
txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
48+
49+
// Create the API request and set the parameters for this specific request
50+
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
51+
apiRequest.setMerchantAuthentication(merchantAuthenticationType);
52+
apiRequest.setTransactionRequest(txnRequest);
53+
54+
// Call the controller
55+
CreateTransactionController controller = new CreateTransactionController(apiRequest);
56+
controller.execute();
57+
58+
// Get the response
59+
CreateTransactionResponse response = new CreateTransactionResponse();
60+
response = controller.getApiResponse();
61+
62+
// Parse the response to determine results
63+
if (response!=null) {
64+
// If API Response is OK, go ahead and check the transaction response
65+
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
66+
TransactionResponse result = response.getTransactionResponse();
67+
if (result.getMessages() != null) {
68+
System.out.println("Successfully created auth-only transaction with Transaction ID: " + result.getTransId());
69+
System.out.println("Response Code: " + result.getResponseCode());
70+
System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
71+
System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
72+
System.out.println("Auth Code: " + result.getAuthCode());
73+
} else {
74+
System.out.println("Failed Transaction.");
75+
if (response.getTransactionResponse().getErrors() != null) {
76+
System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
77+
System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
78+
}
79+
}
80+
} else {
81+
System.out.println("Failed Transaction.");
82+
if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
83+
System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
84+
System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
85+
} else {
86+
System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
87+
System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
88+
}
89+
}
90+
} else {
91+
// Display the error code and message when response is null
92+
ANetApiResponse errorResponse = controller.getErrorResponse();
93+
System.out.println("Failed to get response");
94+
if (!errorResponse.getMessages().getMessage().isEmpty()) {
95+
System.out.println("Error: "+errorResponse.getMessages().getMessage().get(0).getCode()+" \n"+ errorResponse.getMessages().getMessage().get(0).getText());
96+
}
97+
}
98+
99+
return response;
100+
}
101+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package net.authorize.sample.PaymentTransactions;
2+
3+
import java.math.BigDecimal;
4+
import java.math.RoundingMode;
5+
6+
import net.authorize.Environment;
7+
import net.authorize.api.contract.v1.ANetApiResponse;
8+
import net.authorize.api.contract.v1.CreateTransactionRequest;
9+
import net.authorize.api.contract.v1.CreateTransactionResponse;
10+
import net.authorize.api.contract.v1.CreditCardType;
11+
import net.authorize.api.contract.v1.MerchantAuthenticationType;
12+
import net.authorize.api.contract.v1.MessageTypeEnum;
13+
import net.authorize.api.contract.v1.PaymentType;
14+
import net.authorize.api.contract.v1.TransactionRequestType;
15+
import net.authorize.api.contract.v1.TransactionResponse;
16+
import net.authorize.api.contract.v1.TransactionTypeEnum;
17+
import net.authorize.api.controller.CreateTransactionController;
18+
import net.authorize.api.controller.base.ApiOperationBase;
19+
20+
public class AuthorizeCreditCard {
21+
22+
//
23+
// Run this sample from command line with:
24+
// java -jar target/AuthorizeCreditCard-jar-with-dependencies.jar
25+
//
26+
public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
27+
28+
// Set the request to operate in either the sandbox or production environment
29+
ApiOperationBase.setEnvironment(Environment.SANDBOX);
30+
31+
// Create object with merchant authentication details
32+
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
33+
merchantAuthenticationType.setName(apiLoginId);
34+
merchantAuthenticationType.setTransactionKey(transactionKey);
35+
36+
// Populate the payment data
37+
PaymentType paymentType = new PaymentType();
38+
CreditCardType creditCard = new CreditCardType();
39+
creditCard.setCardNumber("4242424242424242");
40+
creditCard.setExpirationDate("0822");
41+
paymentType.setCreditCard(creditCard);
42+
43+
// Create the payment transaction object
44+
TransactionRequestType txnRequest = new TransactionRequestType();
45+
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_ONLY_TRANSACTION.value());
46+
txnRequest.setPayment(paymentType);
47+
txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
48+
49+
// Create the API request and set the parameters for this specific request
50+
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
51+
apiRequest.setMerchantAuthentication(merchantAuthenticationType);
52+
apiRequest.setTransactionRequest(txnRequest);
53+
54+
// Call the controller
55+
CreateTransactionController controller = new CreateTransactionController(apiRequest);
56+
controller.execute();
57+
58+
// Get the response
59+
CreateTransactionResponse response = new CreateTransactionResponse();
60+
response = controller.getApiResponse();
61+
62+
// Parse the response to determine results
63+
if (response!=null) {
64+
// If API Response is OK, go ahead and check the transaction response
65+
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
66+
TransactionResponse result = response.getTransactionResponse();
67+
if (result.getMessages() != null) {
68+
System.out.println("Successfully created auth-only transaction with Transaction ID: " + result.getTransId());
69+
System.out.println("Response Code: " + result.getResponseCode());
70+
System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
71+
System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
72+
System.out.println("Auth Code: " + result.getAuthCode());
73+
} else {
74+
System.out.println("Failed Transaction.");
75+
if (response.getTransactionResponse().getErrors() != null) {
76+
System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
77+
System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
78+
}
79+
}
80+
} else {
81+
System.out.println("Failed Transaction.");
82+
if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {
83+
System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
84+
System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
85+
} else {
86+
System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
87+
System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
88+
}
89+
}
90+
} else {
91+
// Display the error code and message when response is null
92+
ANetApiResponse errorResponse = controller.getErrorResponse();
93+
System.out.println("Failed to get response");
94+
if (!errorResponse.getMessages().getMessage().isEmpty()) {
95+
System.out.println("Error: "+errorResponse.getMessages().getMessage().get(0).getCode()+" \n"+ errorResponse.getMessages().getMessage().get(0).getText());
96+
}
97+
}
98+
99+
return response;
100+
}
101+
}

0 commit comments

Comments
 (0)