Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
f64bd13
Update pom.xml
sunnyrajrathod Aug 12, 2016
3dd8410
Update README.md
brianmc Aug 17, 2016
a23e620
Update README.md
brianmc Aug 17, 2016
47a46c6
Java env proxy setting eg. in Readme
kikmak42 Aug 22, 2016
c3f21e4
Added Sample Accept & AndroidPay
kikmak42 Aug 22, 2016
6dfb7e3
Merge pull request #58 from kikmak42/master
sunnyrajrathod Aug 22, 2016
a57ac03
Update and rename src/main/java/net/authorize/sample/MobileInAppTrans…
sunnyrajrathod Aug 24, 2016
a165f50
Update and rename src/main/java/net/authorize/sample/MobileInAppTrans…
sunnyrajrathod Aug 24, 2016
c2b8e0b
Update and rename src/main/java/net/authorize/sample/MobileInAppTrans…
sunnyrajrathod Aug 24, 2016
826053d
Update SampleCode.java
sunnyrajrathod Aug 24, 2016
fa8623a
Update SampleCodeList.txt
sunnyrajrathod Aug 24, 2016
e1e28cd
- updated samples to handle checks for successful transaction.
Aug 25, 2016
9e351fb
- Reverting AuthorizeCreditCard change.
Aug 25, 2016
4694a25
Adding prints for response codes and message codes.
Aug 26, 2016
2631236
- randomizing description to avoid duplicate record error.
Aug 28, 2016
fad861c
Merge pull request #59 from sunnyrajrathod/master
sunnyrajrathod Aug 28, 2016
3948f25
- Adding multi threading test.
Oct 3, 2016
efc6e24
Update TestRunner.java
sunnyrajrathod Oct 3, 2016
ca9786a
Update TestRunner.java
sunnyrajrathod Oct 3, 2016
2fb00fe
added MT Test
Oct 3, 2016
b4dd6b5
Update pom.xml
sunnyrajrathod Oct 4, 2016
9efea76
Merge branch 'master' of https://github.com/AuthorizeNet/sample-code-…
sunnyrajrathod Nov 24, 2016
e51c081
- Updating samples for q4 api.
sunnyrajrathod Nov 24, 2016
c24fac3
- Fix in GetHostedPaymentPage
sunnyrajrathod Nov 24, 2016
5495836
Update pom.xml
sunnyrajrathod Nov 24, 2016
c7b88bb
- Adding samples for new APIs.
sunnyrajrathod Nov 25, 2016
5658841
Merge branch 'master' of https://github.com/AuthorizeNet/sample-code-…
sunnyrajrathod Nov 25, 2016
6852135
Delete TestMultiThread.java
sunnyrajrathod Nov 25, 2016
c323a21
Update pom.xml
sunnyrajrathod Nov 25, 2016
3155bce
Merge pull request #60 from sunnyrajrathod/master
sunnyrajrathod Nov 25, 2016
e3543e9
Update and rename GetHostedProfilePage.java to GetAcceptCustomerProfi…
brianmc Nov 26, 2016
daff021
Update TestRunner.java
brianmc Nov 26, 2016
4fc4588
Update SampleCode.java
brianmc Nov 26, 2016
3fa891e
Update SampleCodeList.txt
brianmc Nov 26, 2016
49b7a7c
Update TestRunner.java
brianmc Nov 26, 2016
886c6c1
Updated Fraud Samples
Dec 8, 2016
7e6ed90
Updated Fraud Samples
Dec 8, 2016
d00f0b8
Delete GetHeldTransactions.java
brianmc Dec 20, 2016
e2d1281
Update ApproveOrDeclineHeldTransaction.java
brianmc Dec 29, 2016
96f6a9e
Update GetHeldTransactionList.java
brianmc Dec 29, 2016
2269877
fix the namespace for the main file
Jan 18, 2017
65db12f
Merge pull request #61 from bhav18/master
brianmc Jan 25, 2017
525ae55
Update and rename GetHostedPaymentPage.java to GetAnAcceptPaymentPage…
brianmc Jan 25, 2017
403f2e8
Update SampleCode.java
brianmc Jan 25, 2017
1318f9b
Update SampleCodeList.txt
brianmc Jan 25, 2017
9321bc0
Update TestRunner.java
brianmc Jan 25, 2017
706e182
Update AuthorizeCreditCard.java
brianmc Feb 22, 2017
191cd87
Update TestRunner.java
brianmc Feb 22, 2017
f489f39
add isPaymentToken
adavidw Mar 20, 2017
02b833f
formatting README.md
adavidw Mar 20, 2017
ecc6768
Update README.md
adavidw Mar 20, 2017
fb4c0e7
Adding GetCustomerProfileTransactionList sample code
akashshah1203 Apr 13, 2017
bc0b1fb
Merge pull request #63 from akashshah1203/master
sunnyrajrathod Apr 25, 2017
474e003
Update pom.xml
sunnyrajrathod Apr 25, 2017
68b7a70
Update SampleCodeList.txt
sunnyrajrathod Apr 25, 2017
593fdc5
Update pom.xml
sunnyrajrathod Apr 26, 2017
e626eec
Rename directory to match online API Reference
adavidw Jun 19, 2017
800dc49
create sample code for Create an Accept Payment Transaction
adavidw Jun 19, 2017
73191d9
Update SampleCodeList.txt
adavidw Jun 23, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
# Sample Java Code for Authorize.Net
[![Build Status](https://travis-ci.org/AuthorizeNet/sample-code-java.png?branch=master)]
(https://travis-ci.org/AuthorizeNet/sample-code-java)
[![Build Status](https://travis-ci.org/AuthorizeNet/sample-code-java.png?branch=master)](https://travis-ci.org/AuthorizeNet/sample-code-java)

This repository contains working code samples which demonstrate Java integration with the Authorize.Net Java SDK
The samples are organized just like our API, which you can also try out directly here: http://developer.authorize.net/api/reference


##Using the Sample Code
## Using the Sample Code

The samples are all completely independent and self-contained so you can look at them to get a gist of how the method works, you can use the snippets to try in your own sample project, or you can run each sample from the command line.

##Running the Samples
Clone this repository.
Run "mvn package" in the root directory to create the SampleCode console app.
Then run a sample directly by name:
````
## Running the Samples
1. Clone this repository.
2. Run "mvn package" in the root directory to create the SampleCode console app.
3. Then run a sample directly by name:
```
> java -jar target/SampleCode.jar [CodeSampleName]
````
```
e.g.
````
```
> java -jar target/SampleCode.jar ChargeCreditCard
````
```
Running SampleCode without a parameter will give you the list of sample names. Handy or what!

**NOTE : You can update to your Sandbox credentials in SampleCode.java**

**For using behind proxy**

Please set the JAVA environment proxy using a similar code :
```
System.setProperty("https.proxyUse", "true");
System.setProperty("https.proxyHost", "127.0.0.1");
System.setProperty("https.proxyPort", "3128");
```

*PLEASE NOTE THIS PROJECT IS CURRENTLY UNDER DEVELOPMENT*
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<properties>
<sdkVersion>1.8.8</sdkVersion>
<sdkVersion>1.9.3</sdkVersion>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>net.authorize.sample</groupId>
Expand All @@ -14,7 +14,7 @@
<dependency>
<groupId>net.authorize</groupId>
<artifactId>anet-java-sdk</artifactId>
<version>${sdkVersion}</version>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri

CustomerProfileType customerProfileType = new CustomerProfileType();
customerProfileType.setMerchantCustomerId("M_" + eMail);
customerProfileType.setDescription("Profile description here");
customerProfileType.setDescription("Profile description for " + eMail);
customerProfileType.setEmail(eMail);
customerProfileType.getPaymentProfiles().add(customerPaymentProfileType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.authorize.api.controller.GetHostedProfilePageController;
import net.authorize.api.controller.base.ApiOperationBase;

public class GetHostedProfilePage {
public class GetAcceptCustomerProfilePage {

public static ANetApiResponse run(String apiLoginId, String transactionKey, String customerProfileId) {

Expand Down Expand Up @@ -52,4 +52,4 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey, Stri
}
return response;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package net.authorize.sample.FraudManagement;

import java.math.BigDecimal;
import java.math.RoundingMode;

import net.authorize.Environment;
import net.authorize.api.contract.v1.ANetApiResponse;
import net.authorize.api.contract.v1.AfdsTransactionEnum;
import net.authorize.api.contract.v1.CreateTransactionRequest;
import net.authorize.api.contract.v1.CreateTransactionResponse;
import net.authorize.api.contract.v1.CreditCardType;
import net.authorize.api.contract.v1.HeldTransactionRequestType;
import net.authorize.api.contract.v1.MerchantAuthenticationType;
import net.authorize.api.contract.v1.MessageTypeEnum;
import net.authorize.api.contract.v1.PaymentType;
import net.authorize.api.contract.v1.TransactionRequestType;
import net.authorize.api.contract.v1.TransactionResponse;
import net.authorize.api.contract.v1.TransactionTypeEnum;
import net.authorize.api.contract.v1.UpdateHeldTransactionRequest;
import net.authorize.api.contract.v1.UpdateHeldTransactionResponse;
import net.authorize.api.controller.CreateTransactionController;
import net.authorize.api.controller.UpdateHeldTransactionController;
import net.authorize.api.controller.base.ApiOperationBase;

public class ApproveOrDeclineHeldTransaction {

public static ANetApiResponse run(String apiLoginId, String transactionKey, String transactionId) {

//Common code to set for all requests
ApiOperationBase.setEnvironment(Environment.SANDBOX);

MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);


// Create the payment transaction request
HeldTransactionRequestType txnRequest = new HeldTransactionRequestType();
txnRequest.setAction(AfdsTransactionEnum.APPROVE);
txnRequest.setRefTransId("60012148613");

// Make the API Request
UpdateHeldTransactionRequest apiRequest = new UpdateHeldTransactionRequest();
apiRequest.setHeldTransactionRequest(txnRequest);
UpdateHeldTransactionController controller = new UpdateHeldTransactionController(apiRequest);
controller.execute();


UpdateHeldTransactionResponse response = controller.getApiResponse();

if (response!=null) {
// If API Response is ok, go ahead and check the transaction response
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
TransactionResponse result = response.getTransactionResponse();
if(result.getMessages() != null){
System.out.println("Successfully updated transaction with Transaction ID: " + result.getTransId());
System.out.println("Response Code: " + result.getResponseCode());
System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
System.out.println("Auth Code: " + result.getAuthCode());
}
else {
System.out.println("Failed while updating transaction.");
if(response.getTransactionResponse().getErrors() != null){
System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
}
}
}
else {
System.out.println("Failed while updating transaction.");
if(response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null){
System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
}
else {
System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
}
}
}
else {
System.out.println("Null Response.");
}

return response;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package net.authorize.sample.FraudManagement;


import net.authorize.Environment;
import net.authorize.api.contract.v1.*;
import net.authorize.api.controller.GetSettledBatchListController;
import net.authorize.api.controller.GetUnsettledTransactionListController;
import net.authorize.api.controller.base.ApiOperationBase;

//author @krgupta
public class GetHeldTransactionList{

public static ANetApiResponse run(String apiLoginId, String transactionKey) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);

MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);

GetUnsettledTransactionListRequest getRequest = new GetUnsettledTransactionListRequest();
getRequest.setMerchantAuthentication(merchantAuthenticationType);
getRequest.setStatus(TransactionGroupStatusEnum.PENDING_APPROVAL);

Paging paging = new Paging();
paging.setLimit(100);
paging.setOffset(1);

getRequest.setPaging(paging);

TransactionListSorting sorting = new TransactionListSorting();
sorting.setOrderBy(TransactionListOrderFieldEnum.ID);
sorting.setOrderDescending(true);

getRequest.setSorting(sorting);

GetUnsettledTransactionListController controller = new GetUnsettledTransactionListController(getRequest);
controller.execute();
GetUnsettledTransactionListResponse getResponse = controller.getApiResponse();

if (getResponse!=null) {

if (getResponse.getMessages().getResultCode() == MessageTypeEnum.OK) {

System.out.println(getResponse.getMessages().getMessage().get(0).getCode());
System.out.println(getResponse.getMessages().getMessage().get(0).getText());
getResponse.getTransactions();

ArrayOfTransactionSummaryType txnList = getResponse.getTransactions();
if (txnList != null) {
System.out.println("List of Suspicious Transactions :");
for (TransactionSummaryType txn : txnList.getTransaction()) {
System.out.println(txn.getTransId());
}
}
}
else
{
System.out.println("Failed to get unsettled transaction list: " + getResponse.getMessages().getResultCode());
}
}
return getResponse;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package net.authorize.sample.MobileInappTransactions;

import java.math.BigDecimal;
import net.authorize.Environment;
import net.authorize.TransactionType;
import net.authorize.api.contract.v1.*;
import net.authorize.api.controller.CreateTransactionController;
import net.authorize.api.controller.base.ApiOperationBase;

public class CreateAnAcceptTransaction
{
public static ANetApiResponse run(String apiLoginId, String transactionKey)
{
ApiOperationBase.setEnvironment(Environment.SANDBOX);

// Giving the merchant authentication information
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
// Setting the payment
OpaqueDataType op = new OpaqueDataType();
op.setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT");
op.setDataValue("9471471570959063005001");
PaymentType paymentOne = new PaymentType();
paymentOne.setOpaqueData(op);
// Setting the transaction
TransactionRequestType transactionRequest = new TransactionRequestType();
transactionRequest.setAmount(new BigDecimal("131"));
transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
transactionRequest.setPayment(paymentOne);
// Making the api request
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
apiRequest.setTransactionRequest(transactionRequest);
// Creating the controller
CreateTransactionController controller = new CreateTransactionController(apiRequest);
controller.execute();
// Getting the response
CreateTransactionResponse response = controller.getApiResponse();

if (response!=null) {
// If API Response is ok, go ahead and check the transaction response
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
TransactionResponse result = response.getTransactionResponse();
if(result.getMessages() != null){
System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId());
System.out.println("Response Code: " + result.getResponseCode());
System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode());
System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription());
System.out.println("Auth code : " + result.getAuthCode());
}
else {
System.out.println("Failed Transaction.");
if(response.getTransactionResponse().getErrors() != null){
System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
}
}
}
else {
System.out.println("Failed Transaction.");
if(response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null){
System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode());
System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
}
else {
System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode());
System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText());
}
}
}
else {
System.out.println("Null Response.");
}

return response;
}
}
Loading