<?php
/*
* IGSGateway_ClientTransaction.php is copyright � 2010. EarthWalk Software.
* Licensed under the Academic Free License version 3.0.
* Refer to the file named License provided with the source.
*/
/**
* IGSGateway_ClientStartup
*
* @author Jay Wheeler.
* @version 1.0
* @copyright � 2010. EarthWalk Software.
* @license refer to License file provided with the source.
* @package IGSGateway.
* @subpackage ClientTransaction.
*/
/*
* php5 / ZendFramework-1.7.3 implementation of the ClientTransaction object - a class
* to pass the transaction data to the Gateway, fetch the result and format it for
* output to the user.
* @package IGSGateway
* @subpackage ClientTransaction
*/
class ClientTransaction
{
/**
* process
*
* Static public class to handle the Gateway and Input/Output Form logic
* @param array $transaction = the transaction array
* @return null
*/
public static function process($transaction)
{
/**
* Zend_Config_Xml object.
* @var Zend_Config_Xml $xml
*/
$xml = IGSConfig::xml();
/**
* ClientView object.
* @var ClientView $clientView
*/
$clientView = new ClientView($xml->form->formurl);
if ((! array_key_exists('submit', $transaction)) ||
(strtolower($transaction['submit']) != 'submit'))
{
/**
* Default data associative array.
* @var array[string]string $data
*/
$data = array();
if ($xml->form->usedefaultdata)
{
$data = array('trantype' => $xml->form->defaultdata->trantype,
'reference' => $xml->form->defaultdata->reference,
'trans_id' => $xml->form->defaultdata->trans_id,
'authamount' => $xml->form->defaultdata->authamount,
'cardtype' => $xml->form->defaultdata->cardtype,
'ccnumber' => $xml->form->defaultdata->ccnumber,
'month' => $xml->form->defaultdata->month,
'year' => $xml->form->defaultdata->year,
'fulltotal' => $xml->form->defaultdata->fulltotal,
'ccname' => $xml->form->defaultdata->ccname,
'baddress' => $xml->form->defaultdata->baddress,
'baddress1' => $xml->form->defaultdata->baddress1,
'bcity' => $xml->form->defaultdata->bcity,
'bstate' => $xml->form->defaultdata->bstate,
'bzip' => $xml->form->defaultdata->bzip,
'bcountry' => $xml->form->defaultdata->bcountry,
'bphone' => $xml->form->defaultdata->bphone,
'email' => $xml->form->defaultdata->email,
);
}
if ($xml->form->merchantinclude)
{
$data['merchantvisible'] = $xml->form->merchantvisible;
$data['field_capture'] = $xml->form->merchantfields->field_capture;
$data['xsubjectnotify'] = $xml->form->merchantfields->xsubjectnotify;
$data['xheader'] = $xml->form->merchantfields->xheader;
$data['xemailflds'] = $xml->form->merchantfields->xemailflds;
}
$clientView->formatResult(ClientView::INPUTFORM, $data);
print $clientView->getBuffer();
return;
}
// *******************************************************************************
/**
* Local copy of the required gateway and option parameters from the configuration
* file plus the parameters passed-in in $transaction.
* @var array[string]string $parameters
*/
$parameters = array('uri' => $xml->gateway->url,
'username' => $xml->gateway->username,
'pw' => $xml->gateway->pw,
'upg_auth' => $xml->gateway->upg_auth,
'target_app' => $xml->gateway->target_app,
'response_mode' => $xml->options->response_mode,
'response_fmt' => $xml->options->response_fmt,
'delimited_fmt_field_delimiter' => $xml->options->delimited_fmt_field_delimiter,
'delimited_fmt_include_fields' => $xml->options->delimited_fmt_include_fields,
'delimited_fmt_value_delimiter' => $xml->options->delimited_fmt_value_delimiter,
);
if ($xml->options->test_override_errors != 0)
{
$parameters['test_override_errors'] = 1;
}
// *******************************************************************************
if (array_key_exists('bstate', $transaction) &&
(trim(strtolower($transaction['bstate'])) == ''))
{
unset($transaction['bstate']);
}
if (array_key_exists('voiceauth', $transaction))
{
$transaction['voiceauth'] = 'yes';
}
if (strtolower($transaction['trantype']) == 'sale')
{
$transaction['ordernumber'] = '';
}
// *******************************************************************************
/**
* Gateway object.
* @var Gateway $client
*/
$client = new Gateway($parameters,
array('useragent' => $xml->gateway->useragent,
'adapter' => 'Zend_Http_Client_Adapter_Socket',
));
$client->send($transaction);
if ($xml->form->rawresult == 1)
{
$response = $client->getResponse();
header($response->getHeaders());
print $response->getRawBody();
}
else
{
$clientView->formatResult(ClientView::OUTPUTFORM, array_merge($transaction, $client->getResult()));
print $clientView->getBuffer();
}
// *******************************************************************************
unset($client);
}
}