|
| 1 | +# Migrating from Legacy Authorize.Net APIs |
| 2 | + |
| 3 | +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). |
| 4 | + |
| 5 | +**For details on the deprecation and replacement of legacy Authorize.Net APIs, visit https://developer.authorize.net/api/upgrade_guide/.** |
| 6 | + |
| 7 | +## Full list of classes that are no longer supported |
| 8 | +| Class | New Feature | Sample Codes directory | |
| 9 | +|-------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------| |
| 10 | +| AIM (net/authorize/aim) | [PaymentTransactions](https://developer.authorize.net/api/reference/index.html#payment-transactions) | [sample-code-java/PaymentTransactions](https://github.com/AuthorizeNet/sample-code-java/tree/master/src/main/java/net/authorize/sample/PaymentTransactions) | |
| 11 | +| ARB (net/authorize/arb) | [RecurringBilling](https://developer.authorize.net/api/reference/index.html#recurring-billing) | [sample-code-java/Recurring Billing](https://github.com/AuthorizeNet/sample-code-java/tree/master/src/main/java/net/authorize/sample/RecurringBilling) | |
| 12 | +| CIM (net/authorize/cim) | [CustomerProfiles](https://developer.authorize.net/api/reference/index.html#customer-profiles) | [sample-code-java/CustomerProfiles](https://github.com/AuthorizeNet/sample-code-java/tree/master/src/main/java/net/authorize/sample/CustomerProfiles) | |
| 13 | +| SIM (net/authorize/sim) | [Accept Hosted](https://developer.authorize.net/content/developer/en_us/api/reference/features/accept_hosted.html) | - | |
| 14 | +| Reporting (net/authorize/reporting) | [TransactionReporting](https://developer.authorize.net/api/reference/index.html#transaction-reporting) | [sample-code-java/TransactionReporting](https://github.com/AuthorizeNet/sample-code-java/tree/master/src/main/java/net/authorize/sample/TransactionReporting) | |
| 15 | + |
| 16 | +## Example |
| 17 | +#### Old AuthorizeNetAIM example: |
| 18 | + ```java |
| 19 | +import net.authorize.DeviceType; |
| 20 | +import net.authorize.Environment; |
| 21 | +import net.authorize.MarketType; |
| 22 | +import net.authorize.Merchant; |
| 23 | +import net.authorize.TransactionType; |
| 24 | + |
| 25 | +import net.authorize.aim.Transaction; |
| 26 | +import net.authorize.aim.cardpresent.Result; |
| 27 | + |
| 28 | +import net.authorize.data.creditcard.CardType; |
| 29 | +import net.authorize.data.creditcard.CreditCard; |
| 30 | + |
| 31 | +public class ChargeCreditCard{ |
| 32 | + |
| 33 | + //AIM |
| 34 | + public static void main(String[] args) { |
| 35 | + CreditCard creditCard = CreditCard.createCreditCard(); |
| 36 | + creditCard.setCardType(CardType.VISA); |
| 37 | + creditCard.setCreditCardNumber("4111111111111111"); |
| 38 | + creditCard.setExpirationMonth("12"); |
| 39 | + creditCard.setExpirationYear("2020"); |
| 40 | + |
| 41 | + merchant = Merchant.createMerchant(Environment.SANDBOX, apiLoginID, transactionKey); |
| 42 | + merchant.setDeviceType(DeviceType.VIRTUAL_TERMINAL); |
| 43 | + merchant.setMarketType(MarketType.RETAIL); |
| 44 | + |
| 45 | + // create transaction |
| 46 | + Transaction authCaptureTransaction = merchant.createAIMTransaction( |
| 47 | + TransactionType.AUTH_CAPTURE, totalAmount); |
| 48 | + authCaptureTransaction.setCreditCard(creditCard); |
| 49 | + |
| 50 | + Result<Transaction> result = (Result<Transaction>) merchant.postTransaction(authCaptureTransaction); |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | +#### Corresponding new model code (charge-credit-card): |
| 55 | + ```java |
| 56 | +import java.math.BigDecimal; |
| 57 | +import java.math.RoundingMode; |
| 58 | + |
| 59 | +import net.authorize.Environment; |
| 60 | +import net.authorize.api.contract.v1.*; |
| 61 | +import net.authorize.api.controller.CreateTransactionController; |
| 62 | +import net.authorize.api.controller.base.ApiOperationBase; |
| 63 | + |
| 64 | +public class ChargeCreditCard { |
| 65 | + |
| 66 | + // Run this sample from command line with: |
| 67 | + // java -jar target/ChargeCreditCard-jar-with-dependencies.jar |
| 68 | + // |
| 69 | + public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) { |
| 70 | + |
| 71 | + // Set the request to operate in either the sandbox or production environment |
| 72 | + ApiOperationBase.setEnvironment(Environment.SANDBOX); |
| 73 | + |
| 74 | + // Create object with merchant authentication details |
| 75 | + MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ; |
| 76 | + merchantAuthenticationType.setName(apiLoginId); |
| 77 | + merchantAuthenticationType.setTransactionKey(transactionKey); |
| 78 | + |
| 79 | + // Populate the payment data |
| 80 | + PaymentType paymentType = new PaymentType(); |
| 81 | + CreditCardType creditCard = new CreditCardType(); |
| 82 | + creditCard.setCardNumber("4242424242424242"); |
| 83 | + creditCard.setExpirationDate("0822"); |
| 84 | + paymentType.setCreditCard(creditCard); |
| 85 | + |
| 86 | + // Create the payment transaction object |
| 87 | + TransactionRequestType txnRequest = new TransactionRequestType(); |
| 88 | + txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value()); |
| 89 | + txnRequest.setPayment(paymentType); |
| 90 | + txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING)); |
| 91 | + |
| 92 | + // Create the API request and set the parameters for this specific request |
| 93 | + CreateTransactionRequest apiRequest = new CreateTransactionRequest(); |
| 94 | + apiRequest.setMerchantAuthentication(merchantAuthenticationType); |
| 95 | + apiRequest.setTransactionRequest(txnRequest); |
| 96 | + |
| 97 | + // Call the controller |
| 98 | + CreateTransactionController controller = new CreateTransactionController(apiRequest); |
| 99 | + controller.execute(); |
| 100 | + |
| 101 | + // Get the response |
| 102 | + CreateTransactionResponse response = new CreateTransactionResponse(); |
| 103 | + response = controller.getApiResponse(); |
| 104 | + |
| 105 | + return response; |
| 106 | + } |
| 107 | +} |
| 108 | +``` |
0 commit comments