Skip to content

Commit

Permalink
Add SPL autoloader and classmap
Browse files Browse the repository at this point in the history
  • Loading branch information
texdc committed Jun 3, 2014
1 parent fe91c35 commit b089539
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 23 deletions.
50 changes: 27 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
Authorize.Net PHP SDK
======================

To use the SDK in your app, create a composer.json file with the following require
section and run `composer update`.

```json
"require": {
"authorizenet/authorizenet": "~1.8"
}
```

## License
Proprietary, see `license.md`.
Proprietary, see the provided `license.md`.

## Requirements

- PHP 5.3+
- PHP 5.3+ *(>=5.3.10 recommended)*
- cURL PHP Extension
- JSON PHP Extension
- SimpleXML PHP Extension
- An Authorize.Net Merchant Account or Sandbox Account. You can get a
free sandbox account at http://developer.authorize.net/sandbox/

## Autoloading

[`Composer`](http://getcomposer.org) currently has a [MITM](https://github.com/composer/composer/issues/1074)
security vulnerability. However, if you wish to use it, require it's autoloader in
your script or bootstrap file:
```php
require 'vendor/autoload.php';
```
*Note: you'll need a composer.json file with the following require section and to run
`composer update`.*
```json
"require": {
"authorizenet/authorizenet": "~1.8"
}
```

Alternatively, we provide a custom `SPL` autoloader:
```php
require 'path/to/anet_php_sdk/autoload.php';
```

## Usage Examples

Expand All @@ -30,7 +42,6 @@ each API. Additional documentation is in the `docs/` folder.
### AuthorizeNetAIM.php Quick Usage Example

```php
require 'vendor/autoload.php';
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
define("AUTHORIZENET_SANDBOX", true);
Expand All @@ -47,7 +58,6 @@ if ($response->approved) {
### AuthorizeNetAIM.php Advanced Usage Example

```php
require 'vendor/autoload.php';
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
define("AUTHORIZENET_SANDBOX", true);
Expand Down Expand Up @@ -93,7 +103,6 @@ if ($response->approved) {
### AuthorizeNetARB.php Usage Example

```php
require 'vendor/autoload.php';
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
$subscription = new AuthorizeNet_Subscription;
Expand All @@ -118,7 +127,6 @@ $subscription_id = $response->getSubscriptionId();
### AuthorizeNetCIM.php Usage Example

```php
require 'vendor/autoload.php';
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
$request = new AuthorizeNetCIM;
Expand All @@ -136,7 +144,6 @@ if ($response->isOk()) {
### AuthorizeNetSIM.php Usage Example

```php
require 'vendor/autoload.php';
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
define("AUTHORIZENET_MD5_SETTING", "");
$message = new AuthorizeNetSIM;
Expand All @@ -148,7 +155,6 @@ if ($message->isAuthorizeNet()) {
### AuthorizeNetDPM.php Usage Example

```php
require 'vendor/autoload.php';
$url = "http://YOUR_DOMAIN.com/direct_post.php";
$api_login_id = 'YOUR_API_LOGIN_ID';
$transaction_key = 'YOUR_TRANSACTION_KEY';
Expand All @@ -160,7 +166,6 @@ AuthorizeNetDPM::directPostDemo($url, $api_login_id, $transaction_key, $amount,
### AuthorizeNetCP.php Usage Example

```php
require 'vendor/autoload.php';
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
define("AUTHORIZENET_MD5_SETTING", "");
Expand All @@ -175,7 +180,6 @@ $trans_id = $response->transaction_id;
### AuthorizeNetTD.php Usage Example

```php
require 'vendor/autoload.php';
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
$request = new AuthorizeNetTD;
Expand All @@ -189,12 +193,12 @@ Integration tests for the AuthorizeNet SDK are in the `tests` directory. These t
are mainly for SDK development. However, you can also browse through them to find
more usage examples for the various APIs.

- Run `composer update --dev` to load the `PHPUnit` test library.
- Copy the `phpunit.xml.dist` file to `phpunit.xml` and enter your merchant
credentials in the constant fields.
- On the command line in the root folder run:
```shell
/vendor/bin/phpunit
```
- Run `vendor/bin/phpunit` to run the test suite.

*You'll probably want to disable emails on your sandbox account.*

### Test Credit Card Numbers

Expand Down
18 changes: 18 additions & 0 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Custom SPL autoloader for the AuthorizeNet SDK
*
* @package AuthorizeNet
*/

spl_autoload_register(function($className) {
static $classMap;

if (!isset($classMap)) {
$classMap = require __DIR__ . DIRECTORY_SEPARATOR . 'classmap.php';
}

if (isset($classMap[$className])) {
include $classMap[$className];
}
});
39 changes: 39 additions & 0 deletions classmap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* A map of classname => filename for SPL autoloading.
*
* @package AuthorizeNet
*/

$libDir = __DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR;
$sharedDir = $libDir . 'shared' . DIRECTORY_SEPARATOR;

return array(
'AuthorizeNetAIM' => $libDir . 'AuthorizeNetAIM.php',
'AuthorizeNetAIM_Response' => $libDir . 'AuthorizeNetAIM.php',
'AuthorizeNetARB' => $libDir . 'AuthorizeNetARB.php',
'AuthorizeNetARB_Response' => $libDir . 'AuthorizeNetARB.php',
'AuthorizeNetAddress' => $sharedDir . 'AuthorizeNetTypes.php',
'AuthorizeNetBankAccount' => $sharedDir . 'AuthorizeNetTypes.php',
'AuthorizeNetCIM' => $libDir . 'AuthorizeNetCIM.php',
'AuthorizeNetCIM_Response' => $libDir . 'AuthorizeNetCIM.php',
'AuthorizeNetCP' => $libDir . 'AuthorizeNetCP.php',
'AuthorizeNetCP_Response' => $libDir . 'AuthorizeNetCP.php',
'AuthorizeNetCreditCard' => $sharedDir . 'AuthorizeNetTypes.php',
'AuthorizeNetCustomer' => $sharedDir . 'AuthorizeNetTypes.php',
'AuthorizeNetDPM' => $libDir . 'AuthorizeNetDPM.php',
'AuthorizeNetException' => $sharedDir . 'AuthorizeNetException.php',
'AuthorizeNetLineItem' => $sharedDir . 'AuthorizeNetTypes.php',
'AuthorizeNetPayment' => $sharedDir . 'AuthorizeNetTypes.php',
'AuthorizeNetPaymentProfile' => $sharedDir . 'AuthorizeNetTypes.php',
'AuthorizeNetRequest' => $sharedDir . 'AuthorizeNetRequest.php',
'AuthorizeNetResponse' => $sharedDir . 'AuthorizeNetResponse.php',
'AuthorizeNetSIM' => $libDir . 'AuthorizeNetSIM.php',
'AuthorizeNetSIM_Form' => $libDir . 'AuthorizeNetSIM.php',
'AuthorizeNetSOAP' => $libDir . 'AuthorizeNetSOAP.php',
'AuthorizeNetTD' => $libDir . 'AuthorizeNetTD.php',
'AuthorizeNetTD_Response' => $libDir . 'AuthorizeNetTD.php',
'AuthorizeNetTransaction' => $sharedDir . 'AuthorizeNetTypes.php',
'AuthorizeNetXMLResponse' => $sharedDir . 'AuthorizeNetXMLResponse.php',
'AuthorizeNet_Subscription' => $sharedDir . 'AuthorizeNetTypes.php',
);

0 comments on commit b089539

Please sign in to comment.