Skip to content

Commit ed0eb47

Browse files
committed
Merge pull request #1 from djvaldez/future
Adding initial sdk version
2 parents 369917e + d675668 commit ed0eb47

8 files changed

Lines changed: 306 additions & 32 deletions

File tree

.gitignore

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,7 @@
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+

README.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,47 @@
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.
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://http://php.net/manual/en/book.soap.php) extensions must be enabled
10+
- A CyberSource merchant ID and transaction key. You will need to set these in the cybs.ini file in ````lib/conf````.
11+
12+
13+
##Installation
14+
15+
You can install the client either via [Composer](https://getcomposer.org/) or manually.
16+
17+
###Installing with Composer
18+
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:
19+
```
20+
composer.phar install
21+
```
22+
Then, to use the client, you'll need to include the Composer-generated autoload file:
23+
24+
```php
25+
require_once('/path/to/project/vendor/autoload.php');
26+
```
27+
28+
###Manual installation
29+
To use the client manually, include the CyberSource client in your project:
30+
31+
```php
32+
require_once('/path/to/project/lib/CybsSoapClient.php');
33+
```
34+
35+
36+
##Tests
37+
38+
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
39+
```
40+
composer.phar dump-autoload
41+
```
42+
43+
##Documentation
44+
45+
For more information about CyberSource services, see <http://www.cybersource.com/developers/documentation>
46+
47+
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",
10+
"license": "",
11+
"authors": [
12+
{
13+
"name": "CyberSource",
14+
"homepage": "https://github.com/CyberSource"
15+
}
16+
],
17+
"require": {
18+
"php": ">=5.2",
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: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
*
109+
* @return stdClass An object initialized with the client's merchant ID.
110+
*/
111+
public function createRequest()
112+
{
113+
$request = new stdClass();
114+
$request->merchantID = $this->merchantId;
115+
return $request;
116+
}
117+
}

lib/conf/cybs.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
merchant_id = your_merchant_id
2+
transaction_key = "your_transaction_key"
3+
wsdl = "https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.66.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>

sample.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
// Using Composer-generated autoload file.
4+
require 'vendor/autoload.php';
5+
6+
// Or, uncomment the line below if you're not using Composer autoloader.
7+
// require_once('lib/CybsSoapClient.php');
8+
9+
try {
10+
$client = new CybsSoapClient(array('trace'=>1));
11+
12+
$request = $client->createRequest();
13+
14+
// Before using this example, replace the generic value with your own.
15+
$request->merchantReferenceCode = "your_merchant_reference_code";
16+
17+
// To help us troubleshoot any problems that you may encounter,
18+
// please include the following information about your PHP application.
19+
$request->clientLibrary = "PHP";
20+
$request->clientLibraryVersion = phpversion();
21+
$request->clientEnvironment = php_uname();
22+
23+
// This section contains a sample transaction request for the authorization
24+
// service with complete billing, payment card, and purchase (two items) information.
25+
$ccAuthService = new stdClass();
26+
$ccAuthService->run = "true";
27+
$request->ccAuthService = $ccAuthService;
28+
29+
$billTo = new stdClass();
30+
$billTo->firstName = "John";
31+
$billTo->lastName = "Doe";
32+
$billTo->street1 = "1295 Charleston Road";
33+
$billTo->city = "Mountain View";
34+
$billTo->state = "CA";
35+
$billTo->postalCode = "94043";
36+
$billTo->country = "US";
37+
$billTo->email = "null@cybersource.com";
38+
$billTo->ipAddress = "10.7.111.111";
39+
$request->billTo = $billTo;
40+
41+
$card = new stdClass();
42+
$card->accountNumber = "4111111111111111";
43+
$card->expirationMonth = "12";
44+
$card->expirationYear = "2020";
45+
$request->card = $card;
46+
47+
$purchaseTotals = new stdClass();
48+
$purchaseTotals->currency = "USD";
49+
$request->purchaseTotals = $purchaseTotals;
50+
51+
$item0 = new stdClass();
52+
$item0->unitPrice = "12.34";
53+
$item0->quantity = "2";
54+
$item0->id = "0";
55+
56+
$item1 = new stdClass();
57+
$item1->unitPrice = "56.78";
58+
$item1->id = "1";
59+
60+
$request->item = array($item0, $item1);
61+
62+
$reply = $client->runTransaction($request);
63+
64+
// This section will show all the reply fields.
65+
var_dump($reply);
66+
67+
} catch (SoapFault $exception) {
68+
var_dump($exception);
69+
}
70+
71+

test/CybsSoapClientTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
class CybsSoapClientTestCase extends PHPUnit_Framework_TestCase
4+
{
5+
public function testClient()
6+
{
7+
$properties = parse_ini_file('cybs.ini');
8+
$this->assertNotEquals(false, $properties);
9+
10+
$client = new CybsSoapClient();
11+
$this->assertEquals(
12+
$properties['merchant_id'],
13+
$client->getMerchantId()
14+
);
15+
$this->assertEquals(
16+
$properties['transaction_key'],
17+
$client->getTransactionKey()
18+
);
19+
}
20+
}

0 commit comments

Comments
 (0)