Skip to content

Commit 58bfd5d

Browse files
committed
Merge pull request #10 from AuthorizeNet/future
Merge Future into Master
2 parents 369917e + fe6b4a7 commit 58bfd5d

11 files changed

Lines changed: 469 additions & 49 deletions

File tree

.gitignore

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
1-
# Cache and logs (Symfony2)
2-
/app/cache/*
3-
/app/logs/*
4-
!app/cache/.gitkeep
5-
!app/logs/.gitkeep
6-
7-
# Cache and logs (Symfony3)
8-
/var/cache/*
9-
/var/logs/*
10-
!var/cache/.gitkeep
11-
!var/logs/.gitkeep
12-
13-
# Parameters
14-
/app/config/parameters.yml
15-
/app/config/parameters.ini
16-
171
# Managed by Composer
18-
/app/bootstrap.php.cache
19-
/var/bootstrap.php.cache
20-
/bin/*
21-
!bin/console
22-
!bin/symfony_requirements
232
/vendor/
243

25-
# Assets and user uploads
26-
/web/bundles/
27-
/web/uploads/
28-
29-
# PHPUnit
30-
/app/phpunit.xml
31-
/phpunit.xml
32-
334
# Composer PHAR
345
/composer.phar
6+
/composer.lock
7+
8+
# CyberSource config parameters
9+
/lib/conf/cybs.ini

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: php
2+
php:
3+
- 5.6
4+
- 5.5
5+
- 5.4
6+
- 5.3
7+
before_script: composer install

LICENSE

Lines changed: 52 additions & 17 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,80 @@
1-
cybersource-sdk-php
2-
===================
1+
#CyberSource PHP Client
32

4-
This is the temporary private repo for the Cybs PHP SDK
3+
This is the PHP client for the [CyberSource SOAP Toolkit API](http://www.cybersource.com/developers/getting_started/integration_methods/soap_toolkit_api).
4+
5+
6+
##Prerequisites
7+
8+
- PHP 5.3 or above
9+
- [curl](http://php.net/manual/en/book.curl.php), [openssl](http://php.net/manual/en/book.openssl.php), [soap](http://php.net/manual/en/book.soap.php) extensions must be enabled
10+
- A CyberSource account. You can create an evaluation account [here](http://www.cybersource.com/register/).
11+
- A CyberSource transaction key. You will need to set your merchant ID and transaction key in the ````cybs.ini```` file in ````lib/conf````. Instructions on obtaining a transaction key can be found [here](http://www.cybersource.com/developers/integration_methods/simple_order_and_soap_toolkit_api/soap_api/html/wwhelp/wwhimpl/js/html/wwhelp.htm#href=Intro.04.3.html).
12+
13+
14+
##Installation
15+
16+
You can install the client either via [Composer](https://getcomposer.org/) or manually. Before installing, make sure to configure the merchant ID, transaction key, and the WSDL file URL in ````cybs.ini````. By default, the WSDL file for the client is for API version 1.109 (the latest when this package was created). Available WSDL file URLs can be browsed at the following locations:
17+
18+
- [test](https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/)
19+
- [live](https://ics2ws.ic3.com/commerce/1.x/transactionProcessor/)
20+
21+
###Installing with Composer
22+
You'll first need to make sure you have Composer installed. You can follow the instructions on the [official web site](https://getcomposer.org/download/). Once Composer is installed, you can enter the project root and run:
23+
```
24+
composer.phar install
25+
```
26+
Then, to use the client, you'll need to include the Composer-generated autoload file:
27+
28+
```php
29+
require_once('/path/to/project/vendor/autoload.php');
30+
```
31+
32+
###Manual installation
33+
To use the client manually, include the CyberSource client in your project:
34+
35+
```php
36+
require_once('/path/to/project/lib/CybsSoapClient.php');
37+
```
38+
39+
40+
##Getting Started
41+
The PHP client will generate the request message headers for you, and will contain the methods specified by the WSDL file. The main method you'll use is ````runTransaction()````. To run a transaction, you'll first need to construct a client to generate a request object, which you can populate with the necessary fields (see [documentation](http://www.cybersource.com/developers/integration_methods/simple_order_and_soap_toolkit_api/soap_api/html/wwhelp/wwhimpl/js/html/wwhelp.htm#href=Intro.04.4.html) for sample requests). The object will be converted into XML, so the properties of the object will need to correspond to the correct XML format.
42+
43+
```php
44+
$client = new CybsSoapClient();
45+
$request = $client->createRequest();
46+
47+
$card = new stdClass();
48+
$card->accountNumber = '4111111111111111';
49+
$card->expirationMonth = '12';
50+
$card->expirationYear = '2020';
51+
$request->card = $card;
52+
53+
// Populate $request here with other necessary properties
54+
55+
$reply = $client->runTransaction($request);
56+
```
57+
58+
##Running the Samples
59+
After configuring your merchant ID and transaction key in ````cybs.ini````, the samples in the ````samples```` directory can be run from the project root. For example:
60+
61+
```
62+
php samples/Sale.php
63+
```
64+
65+
The samples will output the response object for each request if successful. Note that the samples contain test data and should not be run in a live environment.
66+
67+
##Tests
68+
69+
In order to run tests, you'll need [PHPUnit](https://phpunit.de). You'll also need to use [Composer](https://getcomposer.org/) for autoloading. If you used Composer to install the client, this should already be set up. Otherwise, to use Composer for autoloading only, from the project root run
70+
```
71+
composer.phar dump-autoload
72+
```
73+
74+
If you installed PHPUnit with Composer, run the tests from the project root with the command ````vendor/bin/phpunit````.
75+
76+
##Documentation
77+
78+
For more information about CyberSource services, see <http://www.cybersource.com/developers/documentation>
79+
80+
For all other support needs, see <http://www.cybersource.com/support>

composer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "cybersource/sdk-php",
3+
"description": "CyberSource PHP SOAP client",
4+
"keywords": [
5+
"cybersource",
6+
"payments",
7+
"api"
8+
],
9+
"homepage": "https://github.com/CyberSource/cybersource-sdk-php",
10+
"license": "https://github.com/CyberSource/cybersource-sdk-php/blob/master/LICENSE",
11+
"authors": [
12+
{
13+
"name": "CyberSource",
14+
"homepage": "https://github.com/CyberSource"
15+
}
16+
],
17+
"require": {
18+
"php": ">=5.3",
19+
"ext-curl": "*",
20+
"ext-openssl": "*",
21+
"ext-soap": "*"
22+
},
23+
"require-dev": {
24+
"phpunit/phpunit": "3.7.*"
25+
},
26+
"autoload": {
27+
"classmap": ["lib/"]
28+
},
29+
"include-path": ["lib/conf/"]
30+
}

lib/CybsSoapClient.php

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
3+
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/conf');
4+
5+
/**
6+
* CybsSoapClient
7+
*
8+
* An implementation of PHP's SOAPClient class for making CyberSource requests.
9+
*/
10+
class CybsSoapClient extends SoapClient
11+
{
12+
private $merchantId;
13+
private $transactionKey;
14+
15+
function __construct($options=array())
16+
{
17+
$properties = parse_ini_file('cybs.ini');
18+
$required = array('merchant_id', 'transaction_key', 'wsdl');
19+
20+
if (!$properties) {
21+
throw new Exception('Unable to read cybs.ini.');
22+
}
23+
24+
foreach ($required as $req) {
25+
if (empty($properties[$req])) {
26+
throw new Exception($req . ' not found in cybs.ini.');
27+
}
28+
}
29+
30+
parent::__construct($properties['wsdl'], $options);
31+
$this->merchantId = $properties['merchant_id'];
32+
$this->transactionKey = $properties['transaction_key'];
33+
34+
$nameSpace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
35+
36+
$soapUsername = new SoapVar(
37+
$this->merchantId,
38+
XSD_STRING,
39+
NULL,
40+
$nameSpace,
41+
NULL,
42+
$nameSpace
43+
);
44+
45+
$soapPassword = new SoapVar(
46+
$this->transactionKey,
47+
XSD_STRING,
48+
NULL,
49+
$nameSpace,
50+
NULL,
51+
$nameSpace
52+
);
53+
54+
$auth = new stdClass();
55+
$auth->Username = $soapUsername;
56+
$auth->Password = $soapPassword;
57+
58+
$soapAuth = new SoapVar(
59+
$auth,
60+
SOAP_ENC_OBJECT,
61+
NULL, $nameSpace,
62+
'UsernameToken',
63+
$nameSpace
64+
);
65+
66+
$token = new stdClass();
67+
$token->UsernameToken = $soapAuth;
68+
69+
$soapToken = new SoapVar(
70+
$token,
71+
SOAP_ENC_OBJECT,
72+
NULL,
73+
$nameSpace,
74+
'UsernameToken',
75+
$nameSpace
76+
);
77+
78+
$security =new SoapVar(
79+
$soapToken,
80+
SOAP_ENC_OBJECT,
81+
NULL,
82+
$nameSpace,
83+
'Security',
84+
$nameSpace
85+
);
86+
87+
$header = new SoapHeader($nameSpace, 'Security', $security, true);
88+
$this->__setSoapHeaders(array($header));
89+
}
90+
91+
/**
92+
* @return string The client's merchant ID.
93+
*/
94+
public function getMerchantId()
95+
{
96+
return $this->merchantId;
97+
}
98+
99+
/**
100+
* @return string The client's transaction key.
101+
*/
102+
public function getTransactionKey()
103+
{
104+
return $this->transactionKey;
105+
}
106+
107+
/**
108+
* Returns an object initialized with basic client information.
109+
*
110+
* @param string $merchantReferenceCode Desired reference code for the request
111+
* @return stdClass An object initialized with the basic client info.
112+
*/
113+
public function createRequest($merchantReferenceCode)
114+
{
115+
$request = new stdClass();
116+
$request->merchantID = $this->merchantId;
117+
$request->merchantReferenceCode = $merchantReferenceCode;
118+
$request->clientLibrary = "CyberSource PHP 1.0.0";
119+
$request->clientLibraryVersion = phpversion();
120+
$request->clientEnvironment = php_uname();
121+
return $request;
122+
}
123+
}

lib/conf/cybs.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
merchant_id = your_merchant_id
2+
transaction_key = "your_transaction_key"
3+
4+
; Modify the URL to point to either a live or test WSDL file with the desired API version.
5+
wsdl = "https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.109.wsdl"

phpunit.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false">
12+
<testsuites>
13+
<testsuite name="CyberSource PHP client test">
14+
<directory suffix=".php">./test</directory>
15+
</testsuite>
16+
</testsuites>
17+
</phpunit>

samples/AuthFollowOnCapture.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
// This sample demonstrates how to run an authorization request followed by a
3+
// capture request.
4+
5+
// Using Composer-generated autoload file.
6+
require __DIR__ . '/../vendor/autoload.php';
7+
// Or, uncomment the line below if you're not using Composer autoloader.
8+
// require_once(__DIR__ . '/../lib/CybsSoapClient.php');
9+
10+
11+
// Before using this example, you can use your own reference code for the transaction.
12+
$referenceCode = 'your_merchant_reference_code';
13+
14+
$client = new CybsSoapClient();
15+
$request = $client->createRequest($referenceCode);
16+
17+
// This section contains a sample transaction request for the authorization
18+
// service with complete billing, payment card, and purchase (two items) information.
19+
$ccAuthService = new stdClass();
20+
$ccAuthService->run = 'true';
21+
$request->ccAuthService = $ccAuthService;
22+
23+
$billTo = new stdClass();
24+
$billTo->firstName = 'John';
25+
$billTo->lastName = 'Doe';
26+
$billTo->street1 = '1295 Charleston Road';
27+
$billTo->city = 'Mountain View';
28+
$billTo->state = 'CA';
29+
$billTo->postalCode = '94043';
30+
$billTo->country = 'US';
31+
$billTo->email = 'null@cybersource.com';
32+
$billTo->ipAddress = '10.7.111.111';
33+
$request->billTo = $billTo;
34+
35+
$card = new stdClass();
36+
$card->accountNumber = '4111111111111111';
37+
$card->expirationMonth = '12';
38+
$card->expirationYear = '2020';
39+
$request->card = $card;
40+
41+
$purchaseTotals = new stdClass();
42+
$purchaseTotals->currency = 'USD';
43+
$request->purchaseTotals = $purchaseTotals;
44+
45+
$item0 = new stdClass();
46+
$item0->unitPrice = '12.34';
47+
$item0->quantity = '2';
48+
$item0->id = '0';
49+
50+
$item1 = new stdClass();
51+
$item1->unitPrice = '56.78';
52+
$item1->id = '1';
53+
54+
$request->item = array($item0, $item1);
55+
56+
$reply = $client->runTransaction($request);
57+
58+
// This section will show all the reply fields.
59+
print("\nAUTH RESPONSE: " . print_r($reply, true));
60+
61+
if ($reply->decision != 'ACCEPT') {
62+
print("\nFailed auth request.\n");
63+
return;
64+
}
65+
66+
// Build a capture using the request ID in the response as the auth request ID
67+
$ccCaptureService = new stdClass();
68+
$ccCaptureService->run = 'true';
69+
$ccCaptureService->authRequestID = $reply->requestID;
70+
71+
$captureRequest = $client->createRequest($referenceCode);
72+
$captureRequest->ccCaptureService = $ccCaptureService;
73+
$captureRequest->item = array($item0, $item1);
74+
$captureRequest->purchaseTotals = $purchaseTotals;
75+
76+
$captureReply = $client->runTransaction($captureRequest);
77+
78+
// This section will show all the reply fields.
79+
print("\nCAPTRUE RESPONSE: " . print_r($captureReply, true));

0 commit comments

Comments
 (0)