Skip to content

Commit 3f43da8

Browse files
authored
Create README.md
-Formatting and wording changes for clarity -Specify 5.6 as min php version -composer.json instructions are more flexible so we don't have to remember to change the readme with every release (until 2.0) -remove sample code from readme in favor of more clearly directing to the sample-code repo
1 parent ce07086 commit 3f43da8

1 file changed

Lines changed: 30 additions & 72 deletions

File tree

README.md

Lines changed: 30 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ Authorize.Net PHP SDK
99
## License
1010
Proprietary, see the provided `license.md`.
1111

12-
## Requirements
1312

14-
- PHP 5.5+
13+
## Requirements
14+
- PHP 5.6+
1515
- cURL PHP Extension
1616
- JSON PHP Extension
1717
- SimpleXML PHP Extension
1818
- An Authorize.Net Merchant Account or Sandbox Account. You can get a
1919
free sandbox account at http://developer.authorize.net/hello_world/sandbox/
2020

21+
2122
## Autoloading
22-
23-
We recommend using [`Composer`](http://getcomposer.org) *(note we never recommend you override the new secure-http default setting)*, don't forget to require its autoloader in
24-
your script or bootstrap file:
23+
We recommend using [`Composer`](http://getcomposer.org) *(note we never recommend you
24+
override the new secure-http default setting)*. Don't forget to require its autoloader
25+
in your script or bootstrap file:
2526
```php
2627
require 'vendor/autoload.php';
2728
```
@@ -31,29 +32,35 @@ require 'vendor/autoload.php';
3132
```json
3233
{
3334
"require": {
34-
"php": ">=5.5",
35+
"php": ">=5.6",
3536
"ext-curl": "*",
36-
"authorizenet/authorizenet": "1.9.3"
37+
"authorizenet/authorizenet": "~1.9"
3738
}
3839
}
3940
```
4041

41-
Alternatively, we provide a custom `SPL` autoloader:
42+
Alternatively, we provide a custom `SPL` autoloader for you to reference from within your PHP file:
4243
```php
4344
require 'path/to/anet_php_sdk/autoload.php';
4445
```
46+
This autoloader still requires the `vendor` directory and all of its dependencies to exist.
47+
However, this is a possible solution for cases where composer can't be run on a given system.
48+
You can run composer locally or on another system to build the directory, then copy the
49+
`vendor` directory to the desired system.
50+
4551

4652
## Authentication
4753
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.
48-
If you need a sandbox account you can sign up for one really easily [`here`](https://developer.authorize.net/sandbox/).
54+
If you don't currently have a production Authorize.Net account and need a sandbox account for testing, you can easily sign up for one [`here`](https://developer.authorize.net/sandbox/).
4955

50-
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.
56+
Once you have your keys simply load them into the appropriate variables in your code, as per the below sample code dealing with the authentication part of the flow.
5157

5258
...
5359
```php
5460
use net\authorize\api\contract\v1 as AnetAPI;
5561
```
5662
...
63+
5764
```php
5865
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
5966
$merchantAuthentication->setName("YOURLOGIN");
@@ -66,87 +73,36 @@ $request = new AnetAPI\CreateTransactionRequest();
6673
$request->setMerchantAuthentication($merchantAuthentication);
6774
```
6875
...
76+
You should never include your Login ID and Transaction Key directly in a PHP file that's in a publically accessible portion of your website. A better practice would be to define these in a constants file, and then reference those constants in the appropriate place in your code.
6977

70-
## Usage Examples
7178

72-
Apart from this README, you can find details and examples of using the SDK in the following places:
73-
- [Developer Center Reference](http://developer.authorize.net/api/reference/index.html)
79+
## SDK Usage Examples and Sample Code
80+
Apart from this README, we have comprehensive sample code for all common uses of our API:
7481
- [Github Sample Code Repositories](https://github.com/AuthorizeNet/sample-code-php)
75-
76-
77-
### Quick Usage Example (with Charge Credit Card - Authorize and Capture)
78-
Note: The following is a php console application. Ensure that you can invoke the php command from command line.
79-
- Save the below code to a php file named, say, `charge-credit-card.php`
80-
- Open command prompt and navigate to your SDK folder ( if want to run from a different folder, modify the `require` statement to have the full path to the SDK e.g. `require 'c:/anet-sdk-php/vendor/autoload.php'` in place of `require 'vendor/autoload.php'` )
81-
- Update dependecies - e.g., With composer, type `composer update`
82-
- Type `php [<path to folder containing the php file>\]charge-credit-card.php`
8382

84-
```php
85-
require 'vendor/autoload.php';
86-
use net\authorize\api\contract\v1 as AnetAPI;
87-
use net\authorize\api\controller as AnetController;
88-
define("AUTHORIZENET_LOG_FILE", "phplog");
89-
90-
// Common setup for API credentials
91-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
92-
$merchantAuthentication->setName("556KThWQ6vf2");
93-
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
94-
95-
// Create the payment data for a credit card
96-
$creditCard = new AnetAPI\CreditCardType();
97-
$creditCard->setCardNumber("4111111111111111");
98-
$creditCard->setExpirationDate("2038-12");
99-
$paymentOne = new AnetAPI\PaymentType();
100-
$paymentOne->setCreditCard($creditCard);
101-
102-
// Create a transaction
103-
$transactionRequestType = new AnetAPI\TransactionRequestType();
104-
$transactionRequestType->setTransactionType( "authCaptureTransaction");
105-
$transactionRequestType->setAmount(151.51);
106-
$transactionRequestType->setPayment($paymentOne);
83+
Additionally, you can find details and examples of using the SDK in our API Reference Guide:
84+
- [Developer Center API Reference](http://developer.authorize.net/api/reference/index.html)
10785

108-
$request = new AnetAPI\CreateTransactionRequest();
109-
$request->setMerchantAuthentication($merchantAuthentication);
110-
$request->setTransactionRequest( $transactionRequestType);
111-
$controller = new AnetController\CreateTransactionController($request);
112-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
11386

114-
if ($response != null)
115-
{
116-
$tresponse = $response->getTransactionResponse();
117-
118-
if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )
119-
{
120-
echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
121-
echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n";
122-
}
123-
else
124-
{
125-
echo "Charge Credit Card ERROR : Invalid response\n";
126-
}
127-
}
128-
else
129-
{
130-
echo "Charge Credit card Null response returned";
131-
}
132-
```
13387
### Setting Production Environment
134-
Replace the environment constant in the execute method. For example, in the method above:
88+
To change from the sandbox environment to the production environment, replace the environment constant in the execute method. For example, in the method above:
13589
```php
13690
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::PRODUCTION);
13791
```
13892

139-
## Logging
14093

94+
## Logging
14195
The SDK generates a log with masking for sensitive data like credit card, expiration dates. The provided levels for logging are
14296
`debug`, `info`, `warn`, `error`. Add ````use \net\authorize\util\LogFactory;````. Logger can be initialized using `$logger = LogFactory::getLog(get_class($this));`
14397
The default log file `phplog` gets generated in the current folder. The subsequent logs are appended to the same file, unless the execution folder is changed, and a new log file is generated.
14498

99+
145100
### Usage Examples
146101
- Logging a string message `$logger->debug("Sending 'XML' Request type");`
147102
- Logging xml strings `$logger->debug($xmlRequest);`
148103
- Logging using formatting `$logger->debugFormat("Integer: %d, Float: %f, Xml-Request: %s\n", array(100, 1.29f, $xmlRequest));`
149104

105+
150106
### Customizing Sensitive Tags
151107
A local copy of [AuthorizedNetSensitiveTagsConfig.json](/lib/net/authorize/util/ANetSensitiveFields.php) gets generated when code invoking the logger first gets executed. The local file can later be edited by developer to re-configure what is masked and what is visible. (*Do not edit the JSON in the SDK*).
152108
- For each element of the `sensitiveTags` array,
@@ -160,8 +116,8 @@ A local copy of [AuthorizedNetSensitiveTagsConfig.json](/lib/net/authorize/util/
160116
**<a name="regex-note">Note</a>:**
161117
**For any regex, no starting or ending '/' or any other delimiter should be defined. The '/' delimiter and unicode flag is added in the code.**
162118

163-
## Testing
164119

120+
## Testing
165121
Integration tests for the AuthorizeNet SDK are in the `tests` directory. These tests
166122
are mainly for SDK development. However, you can also browse through them to find
167123
more usage examples for the various APIs.
@@ -172,7 +128,8 @@ more usage examples for the various APIs.
172128
- Run `vendor/bin/phpunit` to run the test suite.
173129

174130
*You'll probably want to disable emails on your sandbox account.*
175-
131+
132+
176133
### Test Credit Card Numbers
177134

178135
| Card Type | Card Number |
@@ -186,6 +143,7 @@ more usage examples for the various APIs.
186143

187144
*Set the expiration date to anytime in the future.*
188145

146+
189147
## PHPDoc
190148

191149
Add PhpDocumentor to your composer.json and run `composer update --dev`:

0 commit comments

Comments
 (0)