[[toc]]
Unified payment processor providing payment gateway for any Horde module.
++ Bugs
List any tickets on http://bugs.horde.org/ that cover this issue or are relevant to it.
++ People
Duck [mailto:duck@obala.net duck@obala.net]
++ Code
http://cvs.horde.org/incubator/Horde_Payment/
++ Description
A payment processing module encapsulating all communications with various payment interfaces.
The application just pushes a payment request with the authorizationRequest API call. When a payment is processed, the payment module calls the selling application's authorizationResponse callback API method to notify it of the results. After payment processing is finished, the user will be redirected to the calling application's webroot, or to the URL provided by authorizationReturn result if the selling application provides it.
The payment module provides an administrative interface to list and search payment requests per module, amount, user status etc.
+++ Features
Built in payment methods
Cash on delivery
Proforma invoice
Known statuses
pending
revoked
successful
void
Configurable payment methods
Limit payment methods per application
Limit payment methods per amount
Virtual host support
Possibility to add a testing process request
++ Step 1: Type selection
When the user is redirected to the selling interface, he/her will be asked to select a payment module. The list will be populated with all modules available that are active, linked to application owning the transaction and in the amount value parameters. If there is only one module available, the selection screen is avoided and user is redirected directly to the next step. User can always come back and choose another method, as revoke a transaction at any time.
++ Step 2: Enter data
User is asked for additional data required by the selected module. Values are stored in database for administrative purposes. This step is automatically skipped for modules does not need additional data entered by user. (See Horde_Payment_Method::hasLocalForm())
++ Step 3: Validation
The validation process of the payment module will be called or the user will be redirected to the remote validation page if the module has it. Here is where the selling application will be called back to be notified about authorization status change. (See Horde_Payment_Method::hasRemoteValidation(), Horde_Payment_Method::process())
++ Step 4: Redirection page
The user will be redirected back to the selling application page or to the result of the authorizationReturn call.
+++ authorizationRequest() usage example
$app = $registry->getApp(); // Calling app
$transaction_id = "myID123"; // App internal unique id
$total = 500; // Total requested amount
$params = array(); // Optional: Additional payment parameters, like user details (name, address etc..)
// Check if any authorization method exits and is linked to this
$authorization_methods = $registry->call('payment/getMethods', array($app));
if ($authorization_methods instanceof PEAR_Error) {
echo sprintf(_("Authorization error. %s"), $authorization_methods->getMessage());
exit;
}
// Push an paymnet authorization request
$authorizationID = $registry->call('payment/authorizationRequest',
array($app, $transaction_id, $total, $params));
if ($authorizationID instanceof PEAR_Error) {
echo sprintf(_("Authorization error. %s"), $authorizationID->getMessage());
exit;
}
// Redirect to paymnet system
// $redirect_url = $registry->link('payment/show', array('id' => $transaction_id, 'module' => $app));
$redirect_url = $registry->link('payment/show', array('id' => $authorizationID));
header('Location:' . $redirect_url);
exit;
+++ authorizationResponse() API example
...
$_services['authorizationResponse'] = array(
'args' => array('id' => 'id', 'params' => '{urn:horde}stringArray'),
'type' => 'string'
);
....
/**
-
Handle authorization response.
-
@param string $id Invoice identification number
-
@param string $params Additional parameters
*/
function _manios_authorizationResponse($id, $params)
{
require_once dirname(__FILE__) . '/base.php';
$manios_driver = Manios_Driver::singleton();
if ($manios_driver instanceof PEAR_Error) {
return $manios_driver;
}
$transaction = $manios_driver->getTransaction($id);
if ($transaction instanceof PEAR_Error) {
return $transaction;
}
switch ($params['status_id']) {
case Horde_Payment::PENDING:
// We have noting to do
return true;
break;
case Horde_Payment::VOID:
case Horde_Payment::REVOKED:
// Cancle order
return $manios_driver->deleteTransaction($id, $transaction['advertiser_id']);
case Horde_Payment::SUCCESSFUL:
// Payment was successfully, process order
return $manios_driver->confirmTransaction($id);
default:
// Unknown
return PEAR::raiseError(_("Unknown response status"));
}
}
+++ authorizationReturn() API example
...
$_services['authorizationReturn'] = array(
'args' => array('id' => 'id'),
'type' => 'string'
);
....
/**
-
Returns authorization comeback url.
-
@param string $id Invoice identification number
*/
function _manios_authorizationReturn($id)
{
require_once dirname(__FILE__) . '/base.php';
$manios_driver = Manios_Driver::singleton();
if ($manios_driver instanceof PEAR_Error) {
return $manios_driver;
}
$transaction = $manios_driver->getTransaction($id);
if ($transaction instanceof PEAR_Error) {
return $transaction;
}
// The transaction has no campaign linked
if (empty($transaction['campaign_id'])) {
return Horde::applicationUrl('impressions/transfer.php', true);
}
// Redirect to campaign management
return Util::addParameter(Horde::applicationUrl('banners/', true), 'c', $transaction['campaign_id']);
}
++ Screenshots
Configure payment methods
[[image config.png]]
Link payment methods to application
[[image links.png]]
Search authorizations
[[image search.png]]
Add a testing process request
[[image testing.png]]
Back to the ((Projects|Project List))