Online Payment Module Architecture: Difference between revisions

Jump to navigation Jump to search
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 the function '''getValidOnlinePaymentMethods()'''. This functions is calling all the hooks named '''getValidPayment''' of external modules.
Then the page search the list of all available payment modes by calling the function '''getValidOnlinePaymentMethods()'''. This functions calls all the hook method named '''getValidPayment''' of external modules to know which payment module is available and then calls the hook method '''doAddButton''' to get the HTML code of the button to show on the payment page for your payment system.


Note: You can have a look at the code of the PayPlug module to get sources of examples: https://github.com/DoliCloud/DoliMods/tree/master/htdocs/payplugdolicloud
== Implementing the hook getValidOnlinePaymentMethods ==
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'''.  
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):
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):
Line 70: Line 73:
</syntaxhighlight>
</syntaxhighlight>


If you built a module that declares this is its module descriptor, then the '''/public/payment/newpayment.php''' page will suggest the payment mode as a different button "Pay using MyPaymentMode". To output the HTML code of your button, you must add the hook method '''doAddButton''' for the context "newpayment" in your hook module file. Your hook must return the string with HTML code into ->resprints.
If you built a module that add this hook, then the '''/public/payment/newpayment.php''' page will know a new payment mode must be suggested.  
 
== Implementing the hook getValidOnlinePaymentMethods ==
To output the HTML code of your button, you must add the hook method '''doAddButton''' for the context "newpayment" in your hook module file. Your hook must return the string with HTML code into ->resprints.
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
public function doAddButton($parameters, &$object, &$action, $hookmanager)
public function doAddButton($parameters, &$object, &$action, $hookmanager)
Line 80: Line 86:


if (array_key_exists("paymentmethod", $parameters) && (empty($parameters["paymentmethod"]) || $parameters["paymentmethod"] == 'mypaymentcode') && isModEnabled('mymodulename')) {
if (array_key_exists("paymentmethod", $parameters) && (empty($parameters["paymentmethod"]) || $parameters["paymentmethod"] == 'mypaymentcode') && isModEnabled('mymodulename')) {
$resprints .= '<button class="buttonpaymentsmall">'.$langs->trans("CreditOrDebitCard").'</button>';
$resprints .= '<button class="buttonpaymentsmall">'.$langs->trans("Pay with mysystem").'</button>';
$resprints .= '<script>myjavascript code</script>';
$resprints .= '<script>myjavascript code</script>';
}
}

Navigation menu