Skip to content

Commit d326e06

Browse files
authored
Merge pull request #236 from adavidw/readme
Update Readme
2 parents ce07086 + 7545948 commit d326e06

1 file changed

Lines changed: 60 additions & 75 deletions

File tree

README.md

Lines changed: 60 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,46 @@ 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
18-
- An Authorize.Net Merchant Account or Sandbox Account. You can get a
19-
free sandbox account at http://developer.authorize.net/hello_world/sandbox/
18+
- An Authorize.Net Merchant account or Sandbox account (You can get a
19+
free sandbox account at http://developer.authorize.net/hello_world/sandbox/).
20+
- TLS 1.2 capable versions of libcurl and OpenSSL (or its equivalent)
2021

21-
## Autoloading
22+
### TLS 1.2
23+
The Authorize.Net APIs only support connections using the TLS 1.2 security protocol. This PHP SDK communicates with the Authorize.Net API using `libcurl` and `OpenSSL` (or equivalent crypto library). It's important to make sure you have new enough versions of these components to support TLS 1.2. Additionally, it's very important to keep these components up to date going forward to mitigate the risk of any security flaws that may be discovered in these libraries.
2224

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:
25+
To test whether your current installation is capable of communicating to our servers using TLS 1.2, run the following PHP code and examine the output for the TLS version:
26+
```php
27+
<?php
28+
$ch = curl_init('https://apitest.authorize.net/xml/v1/request.api');
29+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
30+
curl_setopt($ch, CURLOPT_VERBOSE, true);
31+
$data = curl_exec($ch);
32+
curl_close($ch);
33+
```
34+
35+
If curl is unable to connect to our URL (as given in the previous sample), it's likely that your system is not able to connect using TLS 1.2, or does not have a supported cipher installed. To verify what TLS version your connection does support, run the following PHP code:
36+
```php
37+
<?php
38+
$ch = curl_init('https://www.howsmyssl.com/a/check');
39+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
40+
$data = curl_exec($ch);
41+
curl_close($ch);
42+
43+
$json = json_decode($data);
44+
echo "Connection uses " . $json->tls_version ."\n";
45+
```
46+
47+
48+
## Autoloading
49+
We recommend using [`Composer`](http://getcomposer.org) *(note we never recommend you
50+
override the new secure-http default setting)*. Don't forget to require its autoloader
51+
in your script or bootstrap file:
2552
```php
2653
require 'vendor/autoload.php';
2754
```
@@ -31,29 +58,35 @@ require 'vendor/autoload.php';
3158
```json
3259
{
3360
"require": {
34-
"php": ">=5.5",
61+
"php": ">=5.6",
3562
"ext-curl": "*",
36-
"authorizenet/authorizenet": "1.9.3"
63+
"authorizenet/authorizenet": "~1.9"
3764
}
3865
}
3966
```
4067

41-
Alternatively, we provide a custom `SPL` autoloader:
68+
Alternatively, we provide a custom `SPL` autoloader for you to reference from within your PHP file:
4269
```php
4370
require 'path/to/anet_php_sdk/autoload.php';
4471
```
72+
This autoloader still requires the `vendor` directory and all of its dependencies to exist.
73+
However, this is a possible solution for cases where composer can't be run on a given system.
74+
You can run composer locally or on another system to build the directory, then copy the
75+
`vendor` directory to the desired system.
76+
4577

4678
## Authentication
47-
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/).
79+
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.
80+
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/).
4981

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.
82+
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.
5183

5284
...
5385
```php
5486
use net\authorize\api\contract\v1 as AnetAPI;
5587
```
5688
...
89+
5790
```php
5891
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
5992
$merchantAuthentication->setName("YOURLOGIN");
@@ -67,86 +100,36 @@ $request->setMerchantAuthentication($merchantAuthentication);
67100
```
68101
...
69102

70-
## Usage Examples
103+
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.
71104

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)
74-
- [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`
83105

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");
106+
## SDK Usage Examples and Sample Code
107+
Apart from this README, we have comprehensive sample code for all common uses of our API:
108+
- [Github Sample Code Repositories](https://github.com/AuthorizeNet/sample-code-php)
89109

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);
110+
Additionally, you can find details and examples of using the SDK in our API Reference Guide:
111+
- [Developer Center API Reference](http://developer.authorize.net/api/reference/index.html)
107112

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);
113113

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-
```
133114
### Setting Production Environment
134-
Replace the environment constant in the execute method. For example, in the method above:
115+
To change from the sandbox environment to the production environment, replace the environment constant in the execute method. For example, in the method above:
135116
```php
136117
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::PRODUCTION);
137118
```
138119

139-
## Logging
140120

121+
## Logging
141122
The SDK generates a log with masking for sensitive data like credit card, expiration dates. The provided levels for logging are
142123
`debug`, `info`, `warn`, `error`. Add ````use \net\authorize\util\LogFactory;````. Logger can be initialized using `$logger = LogFactory::getLog(get_class($this));`
143124
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.
144125

126+
145127
### Usage Examples
146128
- Logging a string message `$logger->debug("Sending 'XML' Request type");`
147129
- Logging xml strings `$logger->debug($xmlRequest);`
148130
- Logging using formatting `$logger->debugFormat("Integer: %d, Float: %f, Xml-Request: %s\n", array(100, 1.29f, $xmlRequest));`
149131

132+
150133
### Customizing Sensitive Tags
151134
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*).
152135
- For each element of the `sensitiveTags` array,
@@ -160,8 +143,8 @@ A local copy of [AuthorizedNetSensitiveTagsConfig.json](/lib/net/authorize/util/
160143
**<a name="regex-note">Note</a>:**
161144
**For any regex, no starting or ending '/' or any other delimiter should be defined. The '/' delimiter and unicode flag is added in the code.**
162145

163-
## Testing
164146

147+
## Testing
165148
Integration tests for the AuthorizeNet SDK are in the `tests` directory. These tests
166149
are mainly for SDK development. However, you can also browse through them to find
167150
more usage examples for the various APIs.
@@ -172,7 +155,8 @@ more usage examples for the various APIs.
172155
- Run `vendor/bin/phpunit` to run the test suite.
173156

174157
*You'll probably want to disable emails on your sandbox account.*
175-
158+
159+
176160
### Test Credit Card Numbers
177161

178162
| Card Type | Card Number |
@@ -186,6 +170,7 @@ more usage examples for the various APIs.
186170

187171
*Set the expiration date to anytime in the future.*
188172

173+
189174
## PHPDoc
190175

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

0 commit comments

Comments
 (0)