Online Payment Module Architecture: Difference between revisions

Jump to navigation Jump to search
m
Tag: 2017 source edit
Tag: 2017 source edit
 
(5 intermediate revisions by the same user not shown)
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 56: Line 59:
$validpaymentmethod = array();
$validpaymentmethod = array();


if (array_key_exists("paymentmethod", $parameters) && (empty($parameters["paymentmethod"]) || $parameters["paymentmethod"] == 'mypaymentcode') && isModEnabled('mymodule')) {
if (array_key_exists("paymentmethod", $parameters) && (empty($parameters["paymentmethod"]) || $parameters["paymentmethod"] == 'mypaymentcode') && isModEnabled('mymodulename')) {
$validpaymentmethod['mypaymentcode'] = 'valid';
$validpaymentmethod['mypaymentcode'] = 'valid';
}
}
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 79: Line 85:
$error = "";
$error = "";


if (array_key_exists("paymentmethod", $parameters) && (empty($parameters["paymentmethod"]) || $parameters["paymentmethod"] == 'mypaymentcode') && isModEnabled('payplugdolicloud')) {
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>';
}
}
Line 99: Line 105:
If you want you can also implement the hook '''checkStatus''' to retrieve information from your payment platform to show information on the payment page.
If you want you can also implement the hook '''checkStatus''' to retrieve information from your payment platform to show information on the payment page.


=> Once done, you can already test your module integration by checking that a new entry to pay appear on the payment page.
=> Once done, you can already test your module integration by checking that a new entry to pay appears on the newpayment page.


=Step 2 - User choose the payment mode=
=Step 2 - User choose the payment mode=
Line 122: Line 128:
For all of this, you must implement the hook '''doPayment''' in the context 'newpayment'.
For all of this, you must implement the hook '''doPayment''' in the context 'newpayment'.


If you need to embed you own form, the content must returned by the hook, for example:  
If you need to embed you own HTML form, the content must be returned by the hook into ->resPrint, for example:  
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
this->resPrint = '<script>my javascript</script><form><input type="text" name="credit card num"></form>';
this->resPrint = '<script>my javascript</script><form><input type="text" name="credit card num"></form>';
Line 146: Line 152:


=Step 4 - Fallback on result page=
=Step 4 - Fallback on result page=
When payment is complete, the use finally reach the page paymentok.php or paymentko.php.
When payment is complete, the user finally reach the page '''/public/payment/paymentok.php''' or '''/public/payment/paymentko.php'''.
The page paymentko will just return a message to explain the payment has failed. The page paymentok, will use the parameter fulltag and variables saved into session to make complementary actions like (registering the payment in the application, closing the invoice, sending an email...). The paymentok/ko page can retrieve information from:
The page paymentko.php will just return a message to explain the payment has failed. The page paymentok.php, will use the parameter '''fulltag''' and variables saved into session to make complementary actions (like validating remotely the payment, registering the payment in the Dolibarr application, closing the invoice, sending emails...). The paymentok/ko page can retrieve information from:


*Parameter "fulltag" AG (this parameter was defined into the public/payment/newpayment.php page). With this parameter, the page paymentok.php will be able to make all complementary action like closing invoice or order or recording a subscription for a membership subscription, and more...
*Parameter "fulltag" AG (this parameter was defined into the public/payment/newpayment.php page). With this parameter, the page paymentok.php will be able to make all complementary action like closing invoice or order or recording a subscription for a membership subscription, and more...
Line 156: Line 162:
*$_SESSION['ipaddress']
*$_SESSION['ipaddress']
*$_SESSION['errormessage']  An error message to show
*$_SESSION['errormessage']  An error message to show


=Other features=
=Other features=
To complete...
To complete...

Navigation menu