Custom service status checkers
PayBridge is able to check the availability of the payment provider. This is useful if the payment provider the adapter integrates with has a set period of downtime each day, or it provides a web service for checking its availability.
Status checking improves the robustness of PayBridge, as users cannot process payments that may fail because of payment provider downtime. It also improves user experience, as users are presented with a meaningful message as to why their payment cannot be taken.
Developing a status checker
Begin by adding new settings to JaduPayBridgeConfiguration
database table:
- [configPrefix]_status_checker_[className]
- [configPrefix]_status_checker_[fileName]
These should be set to the class name of your status checker, and filename of this class (relative to /jadu/custom/
) respectively.
The adapter class itself should extend Jadu_PayBridge_Status_IChecker
, and implement the following methods as described above.
/**
* Returns true if payment provider is available, otherwise false
* @return boolean
*/
abstract public function isAvailable();
/**
* Returns an error of textual errors, populated by isAvailable
* @return string[]
*/
abstract public function getError();
Unless customising the maintenance page, it may also be desirable to change the value of 'Maintenance message' in the 'General settings' page of PayBridge, as this is what will be displayed to the user in the event of a status check returning false
.
An example status checker
This status checker will checker return true if the time is between 23:00 and 23:30 each day.
class Jadu_Custom_MyStatusChecker
{
/**
* An array for errors
* @type string[]
*/
private $errors;
public function __construct()
{
$this->errors = array();
}
/**
* Returns true if payment provider is available, otherwise false
* @return boolean
*/
public function isAvailable()
{
$dateNow = new DateTime();
$startOfDownTime = new DateTime();
$startOfDownTime->setTime(23,00,00);
$endOfDownTime = new DateTime();
$endOfDownTime->setTime(23,30,00);
if ($dateNow > $startOfDownTime && $dateNow < $endOfDownTime) {
$this->errors[] = 'The payment provider is undergoing scheduled maintenance';
return false;
}
return true;
}
/**
* Returns an array of textual errors, populated by isAvailable
* @return string[]
*/
public function getErrors()
{
return $this->errors;
}
}
How does status checking work?
To enable status checking, first set Status checking
to On
in PayBridge > Settings. Once this is set, when status checking is required, a new object of type Jadu_PayBridge_Status_Checker
is created, which is passed the configPrefix
value of the relevant adapter.
The constructor of Jadu_PayBridge_Status_Checker
will then try to load the status checker based on this configPrefix
value. To do this, it will get the following values from JaduPayBridgeConfiguration:
- [configPrefix]_status_checker_[className]
- [configPrefix]_status_checker_[fileName]
PayBridge will require [configPrefix]_status_checker_[fileName]
and t
hen instantiate an object of type [configPrefix]_status_checker_[className]
.
PayBridge may then call two methods on this object:
isAvailable()
, which should return true or false based on the availability of the payment providergetErrors()
, which should return an array of textual errors about why status checking failed