Search code examples
phpapicurlopayo

Processing refund in SagePay API


I am trying to test refund processing , all parameters seems to be correct but i am getting this error

VPSProtocol=2.23 Status=ERROR StatusDetail=3046 : The VPSTxId field is missing. VPSTxId={8642C32C-8743-93A5-8C3C-3C5D24E2E845}

As per their documentation there is no field VPSTxId for refunds.

Following is the code that i have tried:

$url = 'https://test.sagepay.com/gateway/service/refund.vsp';
$params = array();
$params['VPSProtocol'] = '2.23';
$params['TxType'] = 'REFUND';
$params['Vendor'] = 'VENDORNAME';
$params['VendorTxCode'] = 'Txn-abc123';            //Sample value given by me
$params['Amount'] = '3.00';
$params['Currency'] = 'GBP';
$params['Description'] = 'Testing Refunds';
$params['RelatedVPSTxId'] = 'ADE97B30-93DB-96EA-1D5F-FE1D5BJY456E2A';     //VPSTxId of main transaction
$params['RelatedVendorTxCode'] = 'VENDOR-131210115229-184';         //VendorTxCode of main transaction
$params['RelatedSecurityKey'] = 'JQFXUICCKO';       //securitykey of main transaction
$params['RelatedTxAuthNo'] = '81068219';            //vpsauthcode of main transaction

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,urlencode(http_build_query($params)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $curlTimeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
echo $response;

What is that i am missing? Any help.

Thanks


Solution

  • I Changed my code a bit and it worked :)

    $url = 'https://test.sagepay.com/gateway/service/refund.vsp';
    $params = array();
    $params['VPSProtocol'] = urlencode('2.23');
    $params['TxType'] = urlencode('REFUND');
    $params['Vendor'] = urlencode('VENDORNAME');
    $params['VendorTxCode'] = urlencode('Txn-abc123');            //Sample value given by me
    $params['Amount'] = urlencode('3.00');
    $params['Currency'] = urlencode('GBP');
    $params['Description'] = urlencode('Testing Refunds');
    $params['RelatedVPSTxId'] = urlencode('ADE97B30-93DB-96EA-1D5F-FE1D5BJY456E2A');     //VPSTxId of main transaction
    $params['RelatedVendorTxCode'] = urlencode('VENDOR-131210115229-184');         //VendorTxCode of main transaction
    $params['RelatedSecurityKey'] = urlencode('JQFXUICCKO');       //securitykey of main transaction
    $params['RelatedTxAuthNo'] = urlencode('81068219');            //vpsa
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url );
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);  
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, $curlTimeout);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $response = curl_exec($ch);
    
    var_dump( $response );