|
| 1 | +# Migrating from Legacy Authorize.Net Classes |
| 2 | + |
| 3 | +Authorize.Net no longer supports several legacy classes, including AuthorizeNetAIM.php, AuthorizenetSIM.php, and others listed below, as part of PHP-SDK. If you are using any of these, we recommend that you update your code to use the new Authorize.Net API classes. |
| 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/repository | |
| 9 | +|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------| |
| 10 | +| AuthorizeNetAIM.php | [PaymentTransactions](https://developer.authorize.net/api/reference/index.html#payment-transactions) | [sample-code-php/PaymentTransactions](https://github.com/AuthorizeNet/sample-code-php/tree/master/PaymentTransactions) | |
| 11 | +| AuthorizeNetARB.php | [RecurringBilling](https://developer.authorize.net/api/reference/index.html#recurring-billing) | [sample-code-php/RecurringBilling](https://github.com/AuthorizeNet/sample-code-php/tree/master/RecurringBilling) | |
| 12 | +| AuthorizeNetCIM.php | [CustomerProfiles](https://developer.authorize.net/api/reference/index.html#customer-profiles) | [sample-code-php/CustomerProfiles](https://github.com/AuthorizeNet/sample-code-php/tree/master/CustomerProfiles) | |
| 13 | +| Hosted CIM | [Accept Customer](https://developer.authorize.net/content/developer/en_us/api/reference/features/customer_profiles.html#Using_the_Accept_Customer_Hosted_Form) | Not available | |
| 14 | +| AuthorizeNetCP.php | [PaymentTransactions](https://developer.authorize.net/api/reference/index.html#payment-transactions) | [sample-code-php/PaymentTransactions](https://github.com/AuthorizeNet/sample-code-php/tree/master/PaymentTransactions) | |
| 15 | +| AuthorizeNetDPM.php | [Accept.JS](https://developer.authorize.net/api/reference/features/acceptjs.html) | [Sample Accept Application](https://github.com/AuthorizeNet/accept-sample-app) | |
| 16 | +| AuthorizeNetSIM.php | [Accept Hosted](https://developer.authorize.net/content/developer/en_us/api/reference/features/accept_hosted.html) | Not available | |
| 17 | +| AuthorizeNetSOAP.php | [PaymentTransactions](https://developer.authorize.net/api/reference/index.html#payment-transactions) | [sample-code-php/PaymentTransactions](https://github.com/AuthorizeNet/sample-code-php/tree/master/PaymentTransactions) | |
| 18 | +| AuthorizeNetTD.php | [TransactionReporting](https://developer.authorize.net/api/reference/index.html#transaction-reporting) | [sample-code-php/TransactionReporting/](https://github.com/AuthorizeNet/sample-code-php/tree/master/TransactionReporting) | |
| 19 | + |
| 20 | +## Example |
| 21 | +#### Old AuthorizeNetAIM example: |
| 22 | + ```php |
| 23 | +define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN"); |
| 24 | +define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY"); |
| 25 | +define("AUTHORIZENET_SANDBOX", true); |
| 26 | +$sale = new AuthorizeNetAIM; |
| 27 | +$sale->amount = "5.99"; |
| 28 | +$sale->card_num = '6011000000000012'; |
| 29 | +$sale->exp_date = '04/15'; |
| 30 | +$response = $sale->authorizeAndCapture(); |
| 31 | +if ($response->approved) { |
| 32 | + $transaction_id = $response->transaction_id; |
| 33 | +} |
| 34 | +``` |
| 35 | +#### Corresponding new model code (charge-credit-card): |
| 36 | + ```php |
| 37 | +require 'vendor/autoload.php'; |
| 38 | +use net\authorize\api\contract\v1 as AnetAPI; |
| 39 | +use net\authorize\api\controller as AnetController; |
| 40 | + |
| 41 | +define("AUTHORIZENET_LOG_FILE", "phplog"); |
| 42 | +$merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); |
| 43 | +$merchantAuthentication->setName("YOURLOGIN"); |
| 44 | +$merchantAuthentication->setTransactionKey("YOURKEY"); |
| 45 | +// Create the payment data for a credit card |
| 46 | +$creditCard = new AnetAPI\CreditCardType(); |
| 47 | +$creditCard->setCardNumber("6011000000000012"); |
| 48 | +$creditCard->setExpirationDate("2015-04"); |
| 49 | +$creditCard->setCardCode("123"); |
| 50 | + |
| 51 | +// Add the payment data to a paymentType object |
| 52 | +$paymentOne = new AnetAPI\PaymentType(); |
| 53 | +$paymentOne->setCreditCard($creditCard); |
| 54 | + |
| 55 | +$transactionRequestType = new AnetAPI\TransactionRequestType(); |
| 56 | +$transactionRequestType->setTransactionType("authCaptureTransaction"); |
| 57 | +$transactionRequestType->setAmount("5.99"); |
| 58 | +$transactionRequestType->setPayment($paymentOne); |
| 59 | + |
| 60 | +// Assemble the complete transaction request |
| 61 | +$request = new AnetAPI\CreateTransactionRequest(); |
| 62 | +$request->setMerchantAuthentication($merchantAuthentication); |
| 63 | +$request->setTransactionRequest($transactionRequestType); |
| 64 | + |
| 65 | +// Create the controller and get the response |
| 66 | +$controller = new AnetController\CreateTransactionController($request); |
| 67 | +$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); |
| 68 | + |
| 69 | +if ($response != null) { |
| 70 | +// Check to see if the API request was successfully received and acted upon |
| 71 | +if ($response->getMessages()->getResultCode() == "Ok") { |
| 72 | + // Since the API request was successful, look for a transaction response |
| 73 | + // and parse it to display the results of authorizing the card |
| 74 | + $tresponse = $response->getTransactionResponse(); |
| 75 | + |
| 76 | + if ($tresponse != null && $tresponse->getMessages() != null) { |
| 77 | + echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "\n"; |
| 78 | + echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n"; |
| 79 | + echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n"; |
| 80 | + echo " Auth Code: " . $tresponse->getAuthCode() . "\n"; |
| 81 | + echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n"; |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | +``` |
0 commit comments