ntom
By: a guest | Nov 22nd, 2007 | Syntax:
PHP | Size: 6.12 KB | Hits: 1,842 | Expires: Never
<?php
'VPS_URL'=>'https://ukvpstest.protx.com/vspgateway/service/vspdirect-register.vsp',
'VPS_CALLBACK'=>'https://ukvpstest.protx.com/vspgateway/service/direct3dcallback.vsp',
'TermUrl'=>'http://www.site.com/path-to-file' /// put this as the path to your file - no trailing slash..
);
if(!isset($_GET['action']))
{
print_r('No specific action is set.. <br />');
// if you want to just set the fields with some prefilled stuff to save yourself having to
// 'add to the cart' everytime, then use the $optRequest
// see example below..
$optRequest = 'VPSProtocol=2.22&TxType=PAYMENT&Vendor=XXXXXX&VendorTxCode='.time().'m&Currency=GBP&Description= ..... etc ';
// if dont have a request pre made, then you have to do it like this
/*
$p = array(
'VPSProtocol' => '2.22',
'TxType' => 'PAYMENT',
'Vendor' => 'vps vendor name',
'VendorTxCode' => 'your vendor txt code',
'Currency' => 'GBP'
.. etc and so on..
);
*/
// as were using a prefilled request which i print_r'd earlier, im just setting $p to null.
$p = null;
_CompletePayment($p, $Vars, $optRequest);
}
else if($_GET['action'] == 'callback')
{
__VerifyCallback($_POST, $Vars);
}
else if($_GET['action'] == 'callbacktest')
{
$optRequest = '... .. ';
__VerifyCallback($p = null, $Vars, $optRequest);
}
else
{
}
function _CompletePayment(&$p, &$Vars, $optReqeust = null)
{
$request = '';
foreach($p as $k=>$v)
// print_r($request) // this $request is what im sending with the $optRequest on line 13-16
($optReqeust) ? $request = $optReqeust : '';
print_r('Attempting to connect to protx to process payment from $reqest variable on line:'.(__LINE__ - 2).'<br />');
if(!$result)
{
// An error occurred while sending a request for authorisation. The request returned: '.curl_error($c);
}
else
{
$response = _SetResponse($result);
if($response['Status'] !== 'OK')
{
if($response['Status'] != '3DAUTH')
{
// Not a 3d auth card.. perform whatever actions you like
$errors++;
print_r('Card is not \'OK\' and does not require 3D Auth, Failed payment with detail: <br />');
}
else
{
// response Status = 3DAUTH
$tpl['PaReq'] = $response['PAReq'];
$tpl['TermUrl'] = $Vars['TermUrl'].'/protxscript.php?action=callback';
$tpl['MD'] = $response['MD'];
$tpl['ACSURL'] = $response['ACSURL'];
print_r('Sucessfully connected to protx, and populating the form with the following data to send to the callback url: <br />');
echo '<form method="post" action="'.$tpl['ACSURL'].'">';
echo "\n";
echo '<input type="hidden" name="PaReq" value="'.$tpl['PaReq'].'" />';
echo "\n";
echo '<input type="hidden" name="TermUrl" value="'.$tpl['TermUrl'].'" />';
echo "\n";
echo '<input type="hidden" name="MD" value="'.$tpl['MD'].'" />';
echo "\n";
echo '<input type="submit" value="Send to server" />';
echo "\n";
echo '</form>';
}
}
else
{
// payment a sucess
}
}
}
function __VerifyCallback(&$p, &$Vars, $optRequest)
{
// you will want to pass $p as $_POST from your script /site
$request = '';
foreach($p as $k=>$v) $request .= ("{$k}=".urlencode($v)."&");
($optRequest) ? $request = $optRequest : '';
if(!$result)
{
}
else
{
$response = _SetResponse($result);
switch ($response['Status'])
{
// perform the various methods here
case 'OK':
// do somthing like check to see the 3DSecureStatus
print_r('3DSecure Status is: '.$response['3DSecureStatus'].'<br />');
break;
default:
print_r('Error: '.$response['StatusDetail'].'<br />');
break;
}
}
}
function _SetResponse($result)
{
foreach($l as $k=>$v)
{
}
return $r;
}
?>