Online Payment Module Architecture: Difference between revisions

m
Tag: 2017 source edit
Tag: 2017 source edit
Line 45: Line 45:
The parameter are used by the page to find the amount to ask for the payment from the object information retrieved in URL.  
The parameter are used by the page to find the amount to ask for the payment from the object information retrieved in URL.  


Then the page search the list of all available payment modes by calling '''getValidOnlinePaymentMethods()'''. Any payment module must first complete this list with its own ID. For this, the module must implement the hook '''getValidOnlinePaymentMethods''' of the context '''newpayment'''.  
Then the page search the list of all available payment modes by calling the function '''getValidOnlinePaymentMethods()'''. This functions is calling all the hooks named '''getValidPayment''' of external modules.
This means you must declare this in your module descriptor (See the page [[Module development]] for more information on how to make a new virgin module with its module descriptor file):
 
So any payment module must first complete this list with its own ID. For this, the module must implement the hook '''getValidPayment''' of the context '''newpayment'''.  
This means you must add this in the hook file (See the page [[Module development]] for more information on how to make a new virgin module with its hook file):
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
$hookmanager->resarray = array('mypaymentcode' => 'valid');
public function getValidPayment($parameters, &$object, &$action, $hookmanager)
{
global $langs;
 
$error = 0; // Error counter
$error = "";
 
if (array_key_exists("paymentmethod", $parameters) && (empty($parameters["paymentmethod"]) || $parameters["paymentmethod"] == 'payplug') && isModEnabled('payplugdolicloud')) {
$validpaymentmethod['mypaymentcode'] = 'valid';
}
 
if (!$error) {
$this->results["validpaymentmethod"] = $validpaymentmethod;
return 0;
} else {
$this->errors[] = $error;
return -1;
}
}
</syntaxhighlight>
</syntaxhighlight>