Online Payment Module Architecture: Difference between revisions

m
Tag: 2017 source edit
Tag: 2017 source edit
Line 70: Line 70:
</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 use the hook '''doAddButton''' for the context "newpayment". Your hook must return such an array
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.
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
public function doAddButton($parameters, &$object, &$action, $hookmanager)
{
global $langs;
$resprints = "";
$error = "";
if (array_key_exists("paymentmethod", $parameters) && (empty($parameters["paymentmethod"]) || $parameters["paymentmethod"] == 'payplug') && isModEnabled('payplugdolicloud')) {
$resprints .= '<div class="button buttonpayment" id="div_dopayment_payplug"><span class="fa fa-credit-card"></span> <input class="" type="submit" id="dopayment_payplug" name="dopayment_payplug" value="'.$langs->trans("PayplugDoPayment").'">';
$resprints .= '<input type="hidden" name="noidempotency" value="'.GETPOST('noidempotency', 'int').'">';
$resprints .= '<input type="hidden" name="s" value="'.(GETPOST('s', 'alpha') ? GETPOST('s', 'alpha') : GETPOST('source', 'alpha')).'">';
$resprints .= '<input type="hidden" name="ref" value="'.GETPOST('ref').'">';
$resprints .= '<br>';
$resprints .= '<span class="buttonpaymentsmall">'.$langs->trans("CreditOrDebitCard").'</span>';
$resprints .= '</div>';
$resprints .= '<script>
$( document ).ready(function() {
$("#div_dopayment_payplug").click(function(){
$("#dopayment_payplug").click();
});
$("#dopayment_payplug").click(function(e){
$("#div_dopayment_payplug").css( \'cursor\', \'wait\' );
e.stopPropagation();
return true;
});
});
</script>
';
}
if (!$error) {
$this->resprints = $resprints;
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = $error;
return -1;
}
}
$this->resarray = array('mypaymentcode' => 'MyPaymentMode Label on the button')
$this->resarray = array('mypaymentcode' => 'MyPaymentMode Label on the button')
</syntaxhighlight>
</syntaxhighlight>