Skip to content

Commit 60a9f66

Browse files
committed
Update README.md
Updated README for consistency with the new model of the sdk.
1 parent 8d42489 commit 60a9f66

1 file changed

Lines changed: 106 additions & 215 deletions

File tree

README.md

Lines changed: 106 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -42,233 +42,88 @@ require 'path/to/anet_php_sdk/autoload.php';
4242
To authenticate with the Authorize.Net API you will need to retrieve your API Login ID and Transaction Key from the [`Merchant Interface`](https://account.authorize.net/). You can find these details in the Settings section.
4343
If you need a sandbox account you can sign up for one really easily [`here`](https://developer.authorize.net/sandbox/).
4444

45-
Once you have your keys simply plug them into the appropriate variables as per the samples below.
45+
Once you have your keys simply plug them into the appropriate variables, as per the below code dealing with the authentication part of the flow.
4646

4747
````php
48-
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
49-
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
48+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
49+
$merchantAuthentication->setName("YOURLOGIN");
50+
$merchantAuthentication->setTransactionKey("YOURKEY");
5051
````
52+
...
53+
54+
````php
55+
$request = new AnetAPI\CreateTransactionRequest();
56+
$request->setMerchantAuthentication($merchantAuthentication);
57+
````
58+
...
5159

5260
## Usage Examples
61+
*Users of previous SDK model please note: The SDK is moving towards using a new model. This model allows us to maintain SDKs better by being more responsive to API changes. (To determine if a code is using the old model or new, a prominent difference is the usage of controllers, which is used only with the new model.) Refer the [old README](README_OLD.md) for samples of the old model.*
5362

54-
See below for basic usage examples. View the `tests/` folder for more examples of
55-
each API. Additional documentation is in the `docs/` folder.
63+
Apart from this README, you can find details and examples of using the SDK in the following places:
64+
- [Developer Center Reference](http://developer.authorize.net/api/reference/index.html)
65+
- [Github Sample Code Repositories](http://developer.authorize.net/api/samplecode/), [php](https://github.com/AuthorizeNet/sample-code-php)
5666

57-
### AuthorizeNetAIM.php Quick Usage Example
58-
59-
```php
60-
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
61-
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
62-
define("AUTHORIZENET_SANDBOX", true);
63-
$sale = new AuthorizeNetAIM;
64-
$sale->amount = "5.99";
65-
$sale->card_num = '6011000000000012';
66-
$sale->exp_date = '04/15';
67-
$response = $sale->authorizeAndCapture();
68-
if ($response->approved) {
69-
$transaction_id = $response->transaction_id;
70-
}
71-
```
72-
73-
### AuthorizeNetAIM.php Advanced Usage Example
67+
### Quick Usage Example (with Charge Credit Card - Authorize and Capture)
68+
- Save the below code to a php file named, say, `charge-credit-card.php`
69+
- Open command prompt and navigate to your sdk folder
70+
- Update dependecies - e.g., With composer, type `composer update`
71+
- Type `php [<path to folder containing the php file>\]charge-credit-card.php`
7472

7573
```php
76-
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
77-
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
78-
define("AUTHORIZENET_SANDBOX", true);
79-
$auth = new AuthorizeNetAIM;
80-
$auth->amount = "45.00";
81-
82-
// Use eCheck:
83-
$auth->setECheck(
84-
'121042882',
85-
'123456789123',
86-
'CHECKING',
87-
'Bank of Earth',
88-
'Jane Doe',
89-
'WEB'
90-
);
91-
92-
// Set multiple line items:
93-
$auth->addLineItem('item1', 'Golf tees', 'Blue tees', '2', '5.00', 'N');
94-
$auth->addLineItem('item2', 'Golf shirt', 'XL', '1', '40.00', 'N');
95-
96-
// Set Invoice Number:
97-
$auth->invoice_num = time();
98-
99-
// Set a Merchant Defined Field:
100-
$auth->setCustomField("entrance_source", "Search Engine");
101-
102-
// Authorize Only:
103-
$response = $auth->authorizeOnly();
104-
105-
if ($response->approved) {
106-
$auth_code = $response->transaction_id;
107-
108-
// Now capture:
109-
$capture = new AuthorizeNetAIM;
110-
$capture_response = $capture->priorAuthCapture($auth_code);
111-
112-
// Now void:
113-
$void = new AuthorizeNetAIM;
114-
$void_response = $void->void($capture_response->transaction_id);
115-
}
116-
```
117-
118-
### AuthorizeNetARB.php Usage Example
119-
120-
```php
121-
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
122-
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
123-
$subscription = new AuthorizeNet_Subscription;
124-
$subscription->name = "PHP Monthly Magazine";
125-
$subscription->intervalLength = "1";
126-
$subscription->intervalUnit = "months";
127-
$subscription->startDate = "2011-03-12";
128-
$subscription->totalOccurrences = "12";
129-
$subscription->amount = "12.99";
130-
$subscription->creditCardCardNumber = "6011000000000012";
131-
$subscription->creditCardExpirationDate= "2018-10";
132-
$subscription->creditCardCardCode = "123";
133-
$subscription->billToFirstName = "Rasmus";
134-
$subscription->billToLastName = "Doe";
135-
136-
// Create the subscription.
137-
$request = new AuthorizeNetARB;
138-
$response = $request->createSubscription($subscription);
139-
$subscription_id = $response->getSubscriptionId();
140-
```
141-
142-
### AuthorizeNetCIM.php Usage Example
143-
144-
```php
145-
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
146-
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
147-
$request = new AuthorizeNetCIM;
148-
// Create new customer profile
149-
$customerProfile = new AuthorizeNetCustomer;
150-
$customerProfile->description = "Description of customer";
151-
$customerProfile->merchantCustomerId = time();
152-
$customerProfile->email = "test@domain.com";
153-
$response = $request->createCustomerProfile($customerProfile);
154-
if ($response->isOk()) {
155-
$customerProfileId = $response->getCustomerProfileId();
156-
}
157-
```
158-
159-
### AuthorizeNetSIM.php Usage Example
160-
161-
```php
162-
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
163-
define("AUTHORIZENET_MD5_SETTING", "");
164-
$message = new AuthorizeNetSIM;
165-
if ($message->isAuthorizeNet()) {
166-
$transactionId = $message->transaction_id;
74+
require 'vendor/autoload.php';
75+
/* provide full path to the sdk in the above code, if you want to run it from some place other than the sdk folder
76+
e.g. if sdk is in c:\anet-sdk-php,
77+
require 'c:/anet-sdk-php/vendor/autoload.php'; */
78+
use net\authorize\api\contract\v1 as AnetAPI;
79+
use net\authorize\api\controller as AnetController;
80+
define("AUTHORIZENET_LOG_FILE", "phplog");
81+
82+
// Common setup for API credentials
83+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
84+
$merchantAuthentication->setName("556KThWQ6vf2");
85+
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
86+
87+
// Create the payment data for a credit card
88+
$creditCard = new AnetAPI\CreditCardType();
89+
$creditCard->setCardNumber( "4111111111111111" );
90+
$creditCard->setExpirationDate( "2038-12");
91+
$paymentOne = new AnetAPI\PaymentType();
92+
$paymentOne->setCreditCard($creditCard);
93+
94+
// Create a transaction
95+
$transactionRequestType = new AnetAPI\TransactionRequestType();
96+
$transactionRequestType->setTransactionType( "authCaptureTransaction");
97+
$transactionRequestType->setAmount(151.51);
98+
$transactionRequestType->setPayment($paymentOne);
99+
100+
$request = new AnetAPI\CreateTransactionRequest();
101+
$request->setMerchantAuthentication($merchantAuthentication);
102+
$request->setTransactionRequest( $transactionRequestType);
103+
$controller = new AnetController\CreateTransactionController($request);
104+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
105+
106+
if ($response != null)
107+
{
108+
$tresponse = $response->getTransactionResponse();
109+
110+
if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )
111+
{
112+
echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
113+
echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n";
114+
}
115+
else
116+
{
117+
echo "Charge Credit Card ERROR : Invalid response\n";
118+
}
167119
}
168-
```
169-
170-
### AuthorizeNetDPM.php Usage Example
171-
172-
```php
173-
$url = "http://YOUR_DOMAIN.com/direct_post.php";
174-
$api_login_id = 'YOUR_API_LOGIN_ID';
175-
$transaction_key = 'YOUR_TRANSACTION_KEY';
176-
$md5_setting = 'YOUR_MD5_SETTING'; // Your MD5 Setting
177-
$amount = "5.99";
178-
AuthorizeNetDPM::directPostDemo($url, $api_login_id, $transaction_key, $amount, $md5_setting);
179-
```
180-
181-
### AuthorizeNetCP.php Usage Example
182-
183-
```php
184-
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
185-
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
186-
define("AUTHORIZENET_MD5_SETTING", "");
187-
$sale = new AuthorizeNetCP;
188-
$sale->amount = '59.99';
189-
$sale->device_type = '4';
190-
$sale->setTrack1Data('%B4111111111111111^CARDUSER/JOHN^1803101000000000020000831000000?');
191-
$response = $sale->authorizeAndCapture();
192-
$trans_id = $response->transaction_id;
193-
```
194-
195-
### AuthorizeNetTD.php Usage Example
196-
197-
```php
198-
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
199-
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
200-
$request = new AuthorizeNetTD;
201-
$response = $request->getTransactionDetails("12345");
202-
echo $response->xml->transaction->transactionStatus;
203-
```
204-
205-
## Testing
206-
207-
Integration tests for the AuthorizeNet SDK are in the `tests` directory. These tests
208-
are mainly for SDK development. However, you can also browse through them to find
209-
more usage examples for the various APIs.
210-
211-
- Run `composer update --dev` to load the `PHPUnit` test library.
212-
- Copy the `phpunit.xml.dist` file to `phpunit.xml` and enter your merchant
213-
credentials in the constant fields.
214-
- Run `vendor/bin/phpunit` to run the test suite.
215-
216-
*You'll probably want to disable emails on your sandbox account.*
217-
218-
### Test Credit Card Numbers
219-
220-
| Card Type | Card Number |
221-
|----------------------------|------------------|
222-
| American Express Test Card | 370000000000002 |
223-
| Discover Test Card | 6011000000000012 |
224-
| Visa Test Card | 4007000000027 |
225-
| Second Visa Test Card | 4012888818888 |
226-
| JCB | 3088000000000017 |
227-
| Diners Club/ Carte Blanche | 38000000000006 |
228-
229-
*Set the expiration date to anytime in the future.*
230-
231-
## PHPDoc
232-
233-
Add PhpDocumentor to your composer.json and run `composer update --dev`:
234-
```json
235-
"require-dev": {
236-
"phpdocumentor/phpdocumentor": "*"
120+
else
121+
{
122+
echo "Charge Credit card Null response returned";
237123
}
238124
```
239-
To autogenerate PHPDocs run:
240-
```shell
241-
vendor/bin/phpdoc -t doc/api/ -d lib
242-
```
243-
244-
## New Model
245-
246-
We’re exploring a new model of maintaining the SDKs which allows us to be more responsive to API changes. This model is consistent across the different SDK languages, which is great for us, however we do not want to sacrifice your productivity by losing the inherent efficiencies in the PHP language or our object model. To this end we’re introducing the new model as purely “experimental” at this time and we would appreciate your feedback. Let us know what you really think! Here’s an example of a server side call with ApplePay data in the new model.
247125

248126
### Apple Pay Example
249-
You'll need to introduce some new dependencies into composer.json
250-
````json
251-
{
252-
253-
"require": {
254-
"php": ">=5.2.0",
255-
"ext-curl": "*",
256-
"authorizenet/authorizenet": "1.8.3",
257-
"jms/serializer": "xsd2php-dev as 0.18.0"
258-
},
259-
"require-dev": {
260-
"goetas/xsd2php": "2.*@dev",
261-
"goetas/xsd-reader": "2.*@dev"
262-
},
263-
"repositories": [{
264-
"type": "vcs",
265-
"url": "https://github.com/goetas/serializer.git"
266-
}]
267-
268-
}
269-
````
270-
271-
Here's the PHP code :
272127

273128
````php
274129
<?php
@@ -317,6 +172,42 @@ Here's the PHP code :
317172

318173
?>
319174
````
320-
### Visa Checkout Examples
321-
"Check out" the Visa Checkout samples at https://github.com/AuthorizeNet/sample-code-php/tree/master/VisaCheckout
322175

176+
## Testing
177+
178+
Integration tests for the AuthorizeNet SDK are in the `tests` directory. These tests
179+
are mainly for SDK development. However, you can also browse through them to find
180+
more usage examples for the various APIs.
181+
182+
- Run `composer update --dev` to load the `PHPUnit` test library.
183+
- Copy the `phpunit.xml.dist` file to `phpunit.xml` and enter your merchant
184+
credentials in the constant fields.
185+
- Run `vendor/bin/phpunit` to run the test suite.
186+
187+
*You'll probably want to disable emails on your sandbox account.*
188+
189+
### Test Credit Card Numbers
190+
191+
| Card Type | Card Number |
192+
|----------------------------|------------------|
193+
| American Express Test Card | 370000000000002 |
194+
| Discover Test Card | 6011000000000012 |
195+
| Visa Test Card | 4007000000027 |
196+
| Second Visa Test Card | 4012888818888 |
197+
| JCB | 3088000000000017 |
198+
| Diners Club/ Carte Blanche | 38000000000006 |
199+
200+
*Set the expiration date to anytime in the future.*
201+
202+
## PHPDoc
203+
204+
Add PhpDocumentor to your composer.json and run `composer update --dev`:
205+
```json
206+
"require-dev": {
207+
"phpdocumentor/phpdocumentor": "*"
208+
}
209+
```
210+
To autogenerate PHPDocs run:
211+
```shell
212+
vendor/bin/phpdoc -t doc/api/ -d lib
213+
```

0 commit comments

Comments
 (0)