Closed knit-pay closed 1 year ago
The 2nd $gateway->start( $payment )
you're referring to, is intentional for gateways using the form method. For these gateways, the start()
method doesn't do much except for setting the action URL of the form.
In $gateway->get_output_fields( $payment )
you then build the parameters to be submitted through a form to the action URL. If you need to call an API endpoint to be able to construct the form fields, you should do that here — in $gateway->get_output_fields( $payment )
.
For examples of gateways using the form method type, see:
If the response of your gateway API endpoint call contains an URL to which you need to redirect the user, you need to change the method to HTTP redirect in the gateway constructor:
$this->set_method( self::METHOD_HTTP_REDIRECT );
@rvdsteege Sometimes API calls throw errors. If I call it in get_output_fields, we will not be able to show these error messages on the frontend checkout page. If we throw errors from the start function, it gets displayed on the checkout page. Secondly, action_url and other details are already saved even after the first call of the start function. Why do we have to call the start function again? Is there any specific reason for the same? https://github.com/pronamic/wp-pay-core/blob/0c4296428a2f31f542113cd81424c5ddd9f4a5d4/src/Plugin.php#L1213
@rvdsteege Do you need more information from my end on this?
@remcotolsma thoughts?
@rvdsteege and @remcotolsma Thanks for understanding the issue and fixing it.
Hello Team
$gateway->start( $payment );
function getting called twice.While initiating payment. https://github.com/pronamic/wp-pay-core/blob/0c4296428a2f31f542113cd81424c5ddd9f4a5d4/src/Plugin.php#L1196
While performing redirection in many extensions https://github.com/pronamic/wp-pay-core/blob/0c4296428a2f31f542113cd81424c5ddd9f4a5d4/src/Plugin.php#L607
In some gateways, API request needs to be called in
start
function. Due to this twice call of start function. API calls and many other operations are getting executed twice, which is causing conflict in many cases.In my opinion, we should remove this second execution. If you think second execution is required for some gateways, kindly change the below code. https://github.com/pronamic/wp-pay-core/blob/0c4296428a2f31f542113cd81424c5ddd9f4a5d4/src/Admin/AdminModule.php#L834
to
So that while testing a gateway from the configuration page, we can get a similar flow.