Authorize.Net no longer supports several legacy classes, including AIM, ARB and others listed below, as part of sdk-java. If you are using any of these, we recommend that you update your code to use the new Authorize.Net API classes under (net/authorize/api).
For details on the deprecation and replacement of legacy Authorize.Net APIs, visit https://developer.authorize.net/api/upgrade_guide/.
Class | New Feature | Sample Codes directory/repository |
---|---|---|
AIM (net/authorize/aim) | PaymentTransactions | sample-code-java/PaymentTransactions |
ARB (net/authorize/arb) | RecurringBilling | sample-code-java/Recurring Billing |
CIM (net/authorize/cim) | CustomerProfiles | sample-code-java/CustomerProfiles |
SIM (net/authorize/sim) | Accept Hosted | Not available |
Reporting (net/authorize/reporting) | TransactionReporting | sample-code-java/TransactionReporting |
import net.authorize.DeviceType;
import net.authorize.Environment;
import net.authorize.MarketType;
import net.authorize.Merchant;
import net.authorize.TransactionType;
import net.authorize.aim.Transaction;
import net.authorize.aim.cardpresent.Result;
import net.authorize.data.creditcard.CardType;
import net.authorize.data.creditcard.CreditCard;
public class ChargeCreditCard{
//AIM
public static void main(String[] args) {
CreditCard creditCard = CreditCard.createCreditCard();
creditCard.setCardType(CardType.VISA);
creditCard.setCreditCardNumber("4111111111111111");
creditCard.setExpirationMonth("12");
creditCard.setExpirationYear("2020");
merchant = Merchant.createMerchant(Environment.SANDBOX, apiLoginID, transactionKey);
merchant.setDeviceType(DeviceType.VIRTUAL_TERMINAL);
merchant.setMarketType(MarketType.RETAIL);
// create transaction
Transaction authCaptureTransaction = merchant.createAIMTransaction(
TransactionType.AUTH_CAPTURE, totalAmount);
authCaptureTransaction.setCreditCard(creditCard);
Result<Transaction> result = (Result<Transaction>) merchant.postTransaction(authCaptureTransaction);
}
}
import java.math.BigDecimal;
import java.math.RoundingMode;
import net.authorize.Environment;
import net.authorize.api.contract.v1.*;
import net.authorize.api.controller.CreateTransactionController;
import net.authorize.api.controller.base.ApiOperationBase;
public class ChargeCreditCard {
public static void main(String[] args) {
// Set the request to operate in either the sandbox or production environment
ApiOperationBase.setEnvironment(Environment.SANDBOX);
// Create object with merchant authentication details
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
// Populate the payment data
PaymentType paymentType = new PaymentType();
CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber("4111111111111111");
creditCard.setExpirationDate("1220");
paymentType.setCreditCard(creditCard);
// Create the payment transaction object
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
txnRequest.setPayment(paymentType);
txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
// Create the API request and set the parameters for this specific request
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
apiRequest.setMerchantAuthentication(merchantAuthenticationType);
apiRequest.setTransactionRequest(txnRequest);
// Call the controller
CreateTransactionController controller = new CreateTransactionController(apiRequest);
controller.execute();
// Get the response
CreateTransactionResponse response = new CreateTransactionResponse();
response = controller.getApiResponse();
return response;
}
}