Skip to content

Commit b42b48e

Browse files
committed
Merge pull request #15 from djvaldez/requests-from-xml
Update readme for NVP and XML support. Update code comments
2 parents 516de8d + fa6e117 commit b42b48e

4 files changed

Lines changed: 50 additions & 9 deletions

File tree

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ If you want to install SDK from Packagist,add the following dependency to your a
2323

2424
##Installation
2525

26-
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:
26+
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 appropriate WSDL file URL in ````cybs.ini````. By default, the WSDL file for the client is for API version 1.120 (the latest when this package was updated). Available WSDL file URLs can be browsed at the following locations:
2727

2828
- [test](https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/)
2929
- [live](https://ics2ws.ic3.com/commerce/1.x/transactionProcessor/)
@@ -48,7 +48,10 @@ require_once('/path/to/project/lib/CybsSoapClient.php');
4848

4949

5050
##Getting Started
51-
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.
51+
The PHP client will generate the request message headers for you, and will contain the methods specified by the WSDL file.
52+
53+
###Creating a simple request
54+
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.
5255

5356
```php
5457
$client = new CybsSoapClient();
@@ -65,6 +68,37 @@ $request->card = $card;
6568
$reply = $client->runTransaction($request);
6669
```
6770

71+
###Creating a request from XML
72+
You can create a request from XML either in a file or from an XML string. The XML request format is described in the **Using XML** section [here](http://apps.cybersource.com/library/documentation/dev_guides/Simple_Order_API_Clients/Client_SDK_SO_API.pdf). Here's how to run a transaction from an XML file:
73+
74+
```php
75+
$referenceCode = 'your_merchant_reference_code';
76+
$client = new CybsSoapClient();
77+
$reply = $client->runTransactionFromFile('path/to/my.xml', $referenceCode);
78+
```
79+
80+
Or, you can create your own XML string and use that instead:
81+
82+
```php
83+
$xml = "";
84+
// Populate $xml
85+
$client = new CybsSoapClient();
86+
$client->runTransactionFromXml($xml);
87+
```
88+
89+
###Using name-value pairs
90+
In order to run transactions using name-value pairs, make sure to set the value for the WSDL for the NVP transaction processor in ````cybs.ini````. Then use the ````CybsNameValuePairClient```` as so:
91+
92+
```php
93+
$client = new CybsNameValuePairClient();
94+
$request = array();
95+
$request['ccAuthService_run'] = 'true';
96+
$request['merchantID'] = 'my_merchant_id';
97+
$request['merchantReferenceCode'] = $'my_reference_code';
98+
// Populate $request
99+
$reply = $client->runTransaction($request);
100+
```
101+
68102
##Running the Samples
69103
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:
70104

lib/CybsSoapClient.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ function __construct($options=array())
1616
parent::__construct($options, $properties);
1717
}
1818

19-
public function simpleXmlToCybsRequest($simpleXml) {
20-
19+
/**
20+
* Returns a properly formatted request object from a SimpleXMLElement.
21+
*
22+
* @param SimpleXMLElement $simpleXml Representation of an XML structure
23+
* @return stdClass A request with the data from the SimpleXMLElement.
24+
*/
25+
public function simpleXmlToCybsRequest($simpleXml)
26+
{
2127
$vars = get_object_vars($simpleXml);
2228
$request = new stdClass();
29+
2330
foreach(array_keys($vars) as $key) {
2431
$element = $vars[$key];
2532
if ($key == 'comment') {
@@ -83,7 +90,7 @@ public function runTransactionFromXml($xml, $merchantReferenceCode)
8390
}
8491

8592
/**
86-
* Runs a transaction from an XML file
93+
* Runs a transaction from an XML file.
8794
*
8895
* @param string $filePath The path to the XML file
8996
* @param string $merchantReferenceCode Desired reference code for the request

lib/conf/cybs.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ merchant_id = your_merchant_id
22
transaction_key = "your_transaction_key"
33

44
; 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"
5+
wsdl = "https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.120.wsdl"
66

77
; Modify the URL to point to either a live or test WSDL file with the desired API version for the name-value pairs transaction API.
8-
nvp_wsdl = "https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_NVP_1.120.wsdl"
8+
nvp_wsdl = "https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_NVP_1.120.wsdl"

samples/AuthFromNameValuePairs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
$request = array();
1717
$request['ccAuthService_run'] = 'true';
18-
$request['merchantID'] = 'dvaldez';
19-
$request['merchantReferenceCode'] = 'MRC-14344';
18+
$request['merchantID'] = 'your_merchant_id';
19+
$request['merchantReferenceCode'] = $referenceCode;
2020
$request['billTo_firstName'] = 'Jane';
2121
$request['billTo_lastName'] = 'Smith';
2222
$request['billTo_street1'] = '1295 Charleston Road';

0 commit comments

Comments
 (0)