Wallogit.com
2017 © Pedro PelĂĄez
PSIGate PHP API
PHP implementation of PSIGate XML Messenger and Account Manager API., (*1)
WARNING (2017-10-23), (*2)
Due to change in URL structure of API gateway, an incompatibility issue may arise when update to the most recent
dev-masterversion from prior to 2017-10-23 one. Version history is introduced to address the issue (my mistake not to introduce it right away). If you want to use old version, i.e. not to introduce changes in your current code, changedev-masterto0.9in your composer file. To avoid potential future compatibility, changedev-masterto the most relevant current release., (*3)
The library is a wrapper around PSIGate XML API making input and result array structures reflect structure of XML documents PSIGate gateway expects. Refer to original PSIGate documentation to understand what parameters to set and what result values to expect., (*4)
The recommended way to install the library is through Composer., (*5)
{
"require": {
"propa/psigate": "~1"
}
}
If an error occurs during request processing, an exception is thrown. Exception code is initialized with corresponding PSIGate API error code (RPA-0002, RIV-0019 etc.) and exception message with corresponding error message, refer to PSIGate API documentation for the full list of error codes and associated messages., (*6)
There are several PHP API specific errors related to unexpected response format, cURL and other situations, their exception codes are prefixed with PAPI and CURL (e.g. PAPI-0001, PAPI-0002, CURL-0001, CURL-0006 etc)., (*7)
Be aware that if exception is not thrown, it doesn't mean the operation was successful in general terms. E.g. AMMessenger::chargeImmediate() returns Invoice structure in result even though tranasaction is declined by processing gateway and credit card is not debited. There is Messenger::analyseTransactionResult() method which can be used for checking if data structure contains error information., (*8)
XML Messenger allows to process real-time credit card transactions., (*9)
<?php
$xmlm = new \PSIGate\XMLMessenger('https://realtimestaging.psigate.com/xml', 'teststore', 'psigate1234');
try {
$result = $xmlm->order(array(
'Subtotal' => '10.00',
'PaymentType' => 'CC',
'CardAction' => '0',
'CardNumber' => '4111111111111111',
'CardExpMonth' => '02',
'CardExpYear' => '16',
'CardIDNumber' => '1234',
'Item' => array(
array(
'ItemID' => 'PSI-BOOK',
'ItemDescription' => 'XML Interface Doc',
'ItemQty' => '1',
'ItemPrice' => '10.00',
'Option' => array(
'Type' => 'Electronic',
'File' => 'xml.doc',
),
),
array(
'ItemID' => 'COUPON',
'ItemDescription' => '10% discount',
'ItemQty' => '1',
'ItemPrice' => '-2.00',
),
),
));
// analyze transaction result ...
} catch (\PSIGate\Exception $e) {
// handle transaction error ...
}
Account Manager Service allows to register customer payment accounts, store customer payment information for future recurring or real-time authorization, track customersâ recurring or real-time transaction activity in the form of invoices., (*10)
<?php
$amm = new \PSIGate\AMMessenger('https://accountsstaging.psigate.com/xml', '1000001', 'teststore', 'testpass');
try {
// register a new account
$accountResult = $amm->accountRegister(array(
'Name' => 'John Smith Jr.',
'Company' => 'PSiGate Inc.',
'Address1' => '145 King St.',
'Address2' => '2300',
'City' => 'Toronto',
'Province' => 'Ontario',
'Postalcode' => 'M5H 1J8',
'Country' => 'Canada',
'Phone' => '1-905-123-4567',
'Fax' => '1-905-123-4568',
'Email' => 'support@psigate.com',
'Comments' => 'No Comment Today',
'CardInfo' => array(
'CardHolder' => 'John Smith',
'CardNumber' => '4005550000000019',
'CardExpMonth' => '08',
'CardExpYear' => '11',
),
));
// retrieve newly assigned account id
$accountId = $accountResult['AccountID'];
$cardSerialNo = $accountResult['CardInfo']['SerialNo'];
// register a charge
$chargeResult = $amm->chargeRegister(array(
'StoreID' => 'teststore',
'AccountID' => $accountId,
'SerialNo' => $cardSerialNo,
'RBName' => 'Monthly Payment',
'Interval' => 'M',
'RBTrigger' => '12',
'EndDate' => '2011.12.31',
'ItemInfo' => array(
'ProductID' => 'NEWSPAPER',
'Description' => 'TORONTO STAR',
'Quantity' => '1',
'Price' => '25',
'Tax1' => '2',
'Tax2' => '1.25',
),
));
// retrieve newly created charge id
$chargeId = $chargeResult['RBCID'];
// disable a charge
$amm->chargeDisable($chargeId);
// ...
} catch (\PSIGate\Exception $e) {
// handle error ...
}
Return values of AMMessenger methods can be split into such groups:, (*11)
There are inconsitencies between Account Manager API documentation v1.1.08 and actual API behavior. Since PHP API is a simple intermediary interface, the source of the issues is PSIGate server itself., (*12)