You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-75Lines changed: 60 additions & 75 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,19 +9,46 @@ Authorize.Net PHP SDK
9
9
## License
10
10
Proprietary, see the provided `license.md`.
11
11
12
-
## Requirements
13
12
14
-
- PHP 5.5+
13
+
## Requirements
14
+
- PHP 5.6+
15
15
- cURL PHP Extension
16
16
- JSON PHP Extension
17
17
- 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)
20
21
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.
22
24
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:
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:
Alternatively, we provide a custom `SPL` autoloader:
68
+
Alternatively, we provide a custom `SPL` autoloader for you to reference from within your PHP file:
42
69
```php
43
70
require 'path/to/anet_php_sdk/autoload.php';
44
71
```
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
+
45
77
46
78
## 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/).
49
81
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.
51
83
52
84
...
53
85
```php
54
86
use net\authorize\api\contract\v1 as AnetAPI;
55
87
```
56
88
...
89
+
57
90
```php
58
91
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
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.
71
104
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)
### 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`
83
105
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:
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:
The SDK generates a log with masking for sensitive data like credit card, expiration dates. The provided levels for logging are
142
123
`debug`, `info`, `warn`, `error`. Add ````use \net\authorize\util\LogFactory;````. Logger can be initialized using `$logger = LogFactory::getLog(get_class($this));`
143
124
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.
144
125
126
+
145
127
### Usage Examples
146
128
- Logging a string message `$logger->debug("Sending 'XML' Request type");`
147
129
- Logging xml strings `$logger->debug($xmlRequest);`
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*).
152
135
- For each element of the `sensitiveTags` array,
@@ -160,8 +143,8 @@ A local copy of [AuthorizedNetSensitiveTagsConfig.json](/lib/net/authorize/util/
160
143
**<aname="regex-note">Note</a>:**
161
144
**For any regex, no starting or ending '/' or any other delimiter should be defined. The '/' delimiter and unicode flag is added in the code.**
162
145
163
-
## Testing
164
146
147
+
## Testing
165
148
Integration tests for the AuthorizeNet SDK are in the `tests` directory. These tests
166
149
are mainly for SDK development. However, you can also browse through them to find
167
150
more usage examples for the various APIs.
@@ -172,7 +155,8 @@ more usage examples for the various APIs.
172
155
- Run `vendor/bin/phpunit` to run the test suite.
173
156
174
157
*You'll probably want to disable emails on your sandbox account.*
175
-
158
+
159
+
176
160
### Test Credit Card Numbers
177
161
178
162
| Card Type | Card Number |
@@ -186,6 +170,7 @@ more usage examples for the various APIs.
186
170
187
171
*Set the expiration date to anytime in the future.*
188
172
173
+
189
174
## PHPDoc
190
175
191
176
Add PhpDocumentor to your composer.json and run `composer update --dev`:
0 commit comments