SagePay Reporting & Admin API with PHP
This entry was posted by Colin at 19:18 on January 27, 2011 and is filed under PHP. It is tagged with ecommerce, php, & sagepay.
Ever since using SafePay (formerly ProTX) and integrating the transaction results into my own systems, I've really wanted to be able to display The 3rd Man results as well. Up to recently, the only way to get this information was to log in to the main SagePay interface, which is a pain when you have everything else you need in your ecommerce backend.
With the introduction of the Reporting & Admin API this becomes possible. In fact, everything you can do by logging into the SagePay admin, has been opened up programatically.
There's not yet any official (or otherwise) PHP code to make accessing it as simple as it should be, so I decided to make a class to handle it. It turned out to be really simple.
- The constructor sets up the vendor, user, and password, and sets live or test system.
- The xmlise() method takes the command and additional arguments, and constructs the XML
- The __call() method handles any other method call, passing it on to the API as a command.
This makes obtaining the 3rd Man data as easy as:
$adminapi = new SagePayAdminApi('vendor', 'username', 'password');
$transaction = $adminapi->getTransactionDetail(array('vendortxcode' => '12345678'));
echo "Third Man Status: {$transaction->t3maction} ({$transaction->t3mscore})\n";
You can download the class from its GitHub repository.
blog comments powered by Disqus