Wallogit.com
2017 © Pedro Peláez
Merchant integration helper in PHP
This library is merely a Merchant integration helper in PHP, (*1)
Requirements: PHP 5.3 because of namespaces., (*2)
Add a composer.json file to your project:, (*3)
{
"require": {
"paygate/payhost-helper": "1.0.2"
}
}
Then provided you have composer installed, you can run the following command:, (*4)
$ composer.phar install
That will fetch the library and its dependencies inside your vendor folder. Then you can add the following to your .php files in order to use the library, (*5)
require_once __DIR__.'/vendor/autoload.php';
Then you need to use the relevant classes, for example:, (*6)
use PayGate\PayHost\Helper;
We start by mapping all our front end html inputs to their respective sections in the PayHost wsdl:, (*7)
$inputMap = array();
The values in the array should be the html input names on the form, while the keys remain untouched as these are what the Helper class looks for., (*8)
For an example of the array contents, look at the public $inputMap property in Helper.php., (*9)
Initiate the Helper class, passing in the input map array:, (*10)
$Helper = new Helper($inputMap);
At the moment, all the sanitizing of the inputs received from the form is not being done by the helper. One could use PHP's filter_var_array to create a new array containing the sanitized values., (*11)
We'll call this new array $filteredPost for now., (*12)
Then call setWebPaymentRequestMessage or setCardPaymentRequestMessage depending on your needs, and pass in the array created before:, (*13)
$SinglePaymentRequest = $Helper->setWebPaymentRequestMessage($filteredPost);
Once the request object has been built, create valid XML from it by calling:, (*14)
$xml = Helper::generateValidXmlFromObj($SinglePaymentRequest, 'SinglePaymentRequest');
We now have a valid XML to pass to PHP's SoapClient., (*15)
eg., (*16)
$SoapClient = new SoapClient("https://www.secure.paygate.co.za/payhost/process.trans?wsdl", array('trace' => 1)); //point to WSDL and set trace value to debug
try {
/*
* Send SOAP request
*/
$result = $SoapClient->__soapCall('SinglePayment', array(
new SoapVar($xml, XSD_ANYXML)
));
} catch (SoapFault $sf){
/*
* handle errors
*/
$err = $sf->getMessage();
}