Online Payment Module Architecture: Difference between revisions

Jump to navigation Jump to search
m
Tag: 2017 source edit
Tag: 2017 source edit
Line 59: Line 59:
When the user has clicked on a payment mode, the same page is called but with a parameter '''action=dopayment'''.  
When the user has clicked on a payment mode, the same page is called but with a parameter '''action=dopayment'''.  


If the payment mode needs to, some information about the payment are stored into session so it will be possible to retrieve them later when falling back on the result of payment page. Among information, the variable FULLTAG contains information on the source of payment (the mode but also the object of Dolibarr the payment may be related to). It must provided to the payment system because it is required to have it in the fallback URL used once a payment has been done (see STEP 4)
If the payment mode needs to, some information about the payment are stored into session so it will be possible to retrieve them later when falling back on the result of payment page.  


Depending on the payment mode, the page may prepare the payment on the remote system. It may be an API call or a redirect to another page.
Among information automatically saved into session, you ha:ve
* the amount into $_SESSION['FinalPaymentAmount']
* currency code
* ip address of user
You can complete with any variable of your choice. A lot of information about the payment are available into variable $FULLTAG that contains information on the source of the payment (the mode but also the object of Dolibarr the payment may be related to). It must provided to the payment system because it is required to have it in the fallback URL used once a payment has been done (see STEP 4)


Then the page show the form to enter the payment information (credit card number). The page may also choose to make a redirect to another page (on remote system) that ask this information.
Depending on the payment mode, the page may prepare the payment on the remote system. It may be an API call or a redirect to another page. Then the page should:
* show the form to allow the user payment page embedded into the dolibarr newpayment page (example with Stripe payment mode).  
* or the page may also choose to make a redirect to another page (on remote system) that ask this information (example with Paypal payment mode).


To save data of your choice in session and/or to make a redirect to the remote payment page, 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 make a redirect to an external page, do it into this hook with  
If you need to embed you own form, the content must returned by the hook it into this->resPrint.
 
If you need to make a redirect to an external page, do it into this hook with:
<syntaxhighligh lang="php">
<syntaxhighligh lang="php">
header("Location: myexternalpaymenturl?myparameters");
header("Location: myexternalpaymenturl?keyforfulltag=$FULLTAG&myotherparameters");
exit;
exit;
</syntaxhighlight>
</syntaxhighlight>
Do not return value, just do an exit after the redirect.
Do not return value, just do an exit after the redirect.


=> You can now test that after the click on your payment mode, the redirect to you home page is ok.
 
=> You can now test that after the click on your payment mode, the redirect to you home page is ok or the form is shown.


= Step 3 - Entering payment information =
= Step 3 - Entering payment information =

Navigation menu