Skip to content

Commit 03f9b3a

Browse files
committed
Merge pull request #81 from Vyoam/Future
Update Readme [Future]
2 parents e4bae89 + 0dbb895 commit 03f9b3a

2 files changed

Lines changed: 288 additions & 222 deletions

File tree

README.md

Lines changed: 90 additions & 222 deletions
Original file line numberDiff line numberDiff line change
@@ -42,165 +42,113 @@ 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

47+
...
4748
````php
48-
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
49-
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
49+
use net\authorize\api\contract\v1 as AnetAPI;
5050
````
51+
...
52+
````php
53+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
54+
$merchantAuthentication->setName("YOURLOGIN");
55+
$merchantAuthentication->setTransactionKey("YOURKEY");
56+
````
57+
...
58+
59+
````php
60+
$request = new AnetAPI\CreateTransactionRequest();
61+
$request->setMerchantAuthentication($merchantAuthentication);
62+
````
63+
...
5164

5265
## Usage Examples
5366

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.
67+
Apart from this README, you can find details and examples of using the SDK in the following places:
68+
- [Developer Center Reference](http://developer.authorize.net/api/reference/index.html)
69+
- [Github Sample Code Repositories](http://developer.authorize.net/api/samplecode/), [php](https://github.com/AuthorizeNet/sample-code-php)
5670

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
74-
75-
```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
71+
72+
### Quick Usage Example (with Charge Credit Card - Authorize and Capture)
73+
Note: The following is a php console application. Ensure that you can invoke the php command from command line.
74+
- Save the below code to a php file named, say, `charge-credit-card.php`
75+
- 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'` )
76+
- Update dependecies - e.g., With composer, type `composer update`
77+
- Type `php [<path to folder containing the php file>\]charge-credit-card.php`
14378

14479
```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();
80+
require 'vendor/autoload.php';
81+
use net\authorize\api\contract\v1 as AnetAPI;
82+
use net\authorize\api\controller as AnetController;
83+
define("AUTHORIZENET_LOG_FILE", "phplog");
84+
85+
// Common setup for API credentials
86+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
87+
$merchantAuthentication->setName("556KThWQ6vf2");
88+
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
89+
90+
// Create the payment data for a credit card
91+
$creditCard = new AnetAPI\CreditCardType();
92+
$creditCard->setCardNumber("4111111111111111");
93+
$creditCard->setExpirationDate("2038-12");
94+
$paymentOne = new AnetAPI\PaymentType();
95+
$paymentOne->setCreditCard($creditCard);
96+
97+
// Create a transaction
98+
$transactionRequestType = new AnetAPI\TransactionRequestType();
99+
$transactionRequestType->setTransactionType( "authCaptureTransaction");
100+
$transactionRequestType->setAmount(151.51);
101+
$transactionRequestType->setPayment($paymentOne);
102+
103+
$request = new AnetAPI\CreateTransactionRequest();
104+
$request->setMerchantAuthentication($merchantAuthentication);
105+
$request->setTransactionRequest( $transactionRequestType);
106+
$controller = new AnetController\CreateTransactionController($request);
107+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
108+
109+
if ($response != null)
110+
{
111+
$tresponse = $response->getTransactionResponse();
112+
113+
if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )
114+
{
115+
echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
116+
echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n";
117+
}
118+
else
119+
{
120+
echo "Charge Credit Card ERROR : Invalid response\n";
121+
}
156122
}
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;
123+
else
124+
{
125+
echo "Charge Credit card Null response returned";
167126
}
168127
```
169-
170-
### AuthorizeNetDPM.php Usage Example
171128

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-
```
129+
## Logging
180130

181-
### AuthorizeNetCP.php Usage Example
131+
SDK generates log with masking for sensitive data like credit card, expiration dates. The provided levels for logging are
132+
`debug`, `info`, `warn`, `error`. Add ````use \net\authorize\util\LogFactory;````. Logger can be initialized using `$logger = LogFactory::getLog(get_class($this));`
133+
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.
182134

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-
```
135+
### Usage Examples
136+
- Logging a string message `$logger->debug("Sending 'XML' Request type");`
137+
- Logging xml strings `$logger->debug($xmlRequest);`
138+
- Logging using formatting `$logger->debugFormat("Integer: %d, Float: %f, Xml-Request: %s\n", array(100, 1.29f, $xmlRequest));`
194139

195-
### AuthorizeNetTD.php Usage Example
140+
### Customizing Sensitive Tags
141+
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 sdk*).
142+
- For each element of the `sensitiveTags` array,
143+
- `tagName` field corresponds to the name of the property in object, or xml-tag that should be hidden entirely ( *XXXX* shown if no replacement specified ) or masked (e.g. showing the last 4 digits of credit card number).
144+
- `pattern`[<sup>[Note]</sup>](#regex-note) and `replacement`[<sup>[Note]</sup>](#regex-note) can be left `""`, if the default is to be used (as defined in [Log.php](/lib/net/authorize/util/Log.php)). `pattern` gives the regex to identify, while `replacement` defines the visible part.
145+
- `disableMask` can be set to *true* to allow the log to fully display that property in an object, or tag in a xml string.
146+
- `sensitiveStringRegexes`[<sup>[Note]</sup>](#regex-note) has list of credit-card regexes. So if credit-card number is not already masked, it would get entirely masked.
147+
- Take care of non-ascii characters (refer [manual](http://php.net/manual/en/regexp.reference.unicode.php)) while defining the regex, e.g. use
148+
`"pattern": "(\\p{N}+)(\\p{N}{4})"` instead of `"pattern": "(\\d+)(\\d{4})"`. Also note `\\` escape sequence is used.
196149

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-
```
150+
**<a name="regex-note">Note</a>:**
151+
**For any regex, no starting or ending '/' or any other delimiter should be defined. The '/' delimiter and unicode flag is added in the code.**
204152

205153
## Testing
206154

@@ -240,83 +188,3 @@ To autogenerate PHPDocs run:
240188
```shell
241189
vendor/bin/phpdoc -t doc/api/ -d lib
242190
```
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.
247-
248-
### 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 :
272-
273-
````php
274-
<?php
275-
require 'vendor/autoload.php';
276-
277-
use net\authorize\api\contract\v1 as AnetAPI;
278-
use net\authorize\api\controller as AnetController;
279-
280-
define("AUTHORIZENET_LOG_FILE", "phplog");
281-
282-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
283-
$merchantAuthentication->setName("5KP3u95bQpv");
284-
$merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S");
285-
$refId = 'ref' . time();
286-
287-
$op = new AnetAPI\OpaqueDataType();
288-
$op->setDataDescriptor("COMMON.APPLE.INAPP.PAYMENT");
289-
$op->setDataValue("eyJkYXRhIjoiQkRQTldTdE1tR2V3UVVXR2c0bzdFXC9qKzFjcTFUNzhxeVU4NGI2N2l0amNZSTh3UFlBT2hzaGpoWlBycWRVcjRYd1BNYmo0emNHTWR5KysxSDJWa1BPWStCT01GMjV1YjE5Y1g0bkN2a1hVVU9UakRsbEIxVGdTcjhKSFp4Z3A5ckNnc1NVZ2JCZ0tmNjBYS3V0WGY2YWpcL284WkliS25yS1E4U2gwb3VMQUtsb1VNbit2UHU0K0E3V0tycXJhdXo5SnZPUXA2dmhJcStIS2pVY1VOQ0lUUHlGaG1PRXRxK0grdzB2UmExQ0U2V2hGQk5uQ0hxenpXS2NrQlwvMG5xTFpSVFliRjBwK3Z5QmlWYVdIZWdoRVJmSHhSdGJ6cGVjelJQUHVGc2ZwSFZzNDhvUExDXC9rXC8xTU5kNDdrelwvcEhEY1JcL0R5NmFVTStsTmZvaWx5XC9RSk4rdFMzbTBIZk90SVNBUHFPbVhlbXZyNnhKQ2pDWmxDdXcwQzltWHpcL29iSHBvZnVJRVM4cjljcUdHc1VBUERwdzdnNjQybTRQendLRitIQnVZVW5lV0RCTlNEMnU2amJBRzMiLCJ2ZXJzaW9uIjoiRUNfdjEiLCJoZWFkZXIiOnsiYXBwbGljYXRpb25EYXRhIjoiOTRlZTA1OTMzNWU1ODdlNTAxY2M0YmY5MDYxM2UwODE0ZjAwYTdiMDhiYzdjNjQ4ZmQ4NjVhMmFmNmEyMmNjMiIsInRyYW5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jbCtQZjMrVTRwazEzblZEOW53UVFNQWtHQlNzT0F3SWFCUUF3RFFZSktvWklodmNOQVFFQkJRQUVnWUJhSzNFbE9zdGJIOFdvb3NlREFCZitKZ1wvMTI5SmNJYXdtN2M2VnhuN1phc05iQXEzdEF0OFB0eSt1UUNnc3NYcVprTEE3a3oyR3pNb2xOdHY5d1ltdTlVandhcjFQSFlTK0JcL29Hbm96NTkxd2phZ1hXUnowbk1vNXkzTzFLelgwZDhDUkhBVmE4OFNyVjFhNUpJaVJldjNvU3RJcXd2NXh1WmxkYWc2VHI4dz09In0=");
290-
$paymentOne = new AnetAPI\PaymentType();
291-
$paymentOne->setOpaqueData($op);
292-
293-
//create a transaction
294-
$transactionRequestType = new AnetAPI\TransactionRequestType();
295-
$transactionRequestType->setTransactionType( "authCaptureTransaction");
296-
$transactionRequestType->setAmount(151);
297-
$transactionRequestType->setPayment($paymentOne);
298-
299-
$request = new AnetAPI\CreateTransactionRequest();
300-
$request->setMerchantAuthentication($merchantAuthentication);
301-
$request->setRefId( $refId);
302-
$request->setTransactionRequest( $transactionRequestType);
303-
304-
$controller = new AnetController\CreateTransactionController($request);
305-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
306-
307-
if ($response != null)
308-
{
309-
$tresponse = $response->getTransactionResponse();
310-
311-
if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )
312-
{
313-
echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n";
314-
echo " TRANS ID : " . $tresponse->getTransId() . "\n";
315-
}
316-
}
317-
318-
?>
319-
````
320-
### Visa Checkout Examples
321-
"Check out" the Visa Checkout samples at https://github.com/AuthorizeNet/sample-code-php/tree/master/VisaCheckout
322-

0 commit comments

Comments
 (0)