I am working on a plugin with a payment system. I need to provide a return url for the payment gateway in order to receive its answers. I don't want to create a specific page but to have a kind of listener to do the treatments according to the return and redirect to a page of success or failure. So, i need some suggestions.
Thanks.
I am working on a plugin with a payment system. I need to provide a return url for the payment gateway in order to receive its answers. I don't want to create a specific page but to have a kind of listener to do the treatments according to the return and redirect to a page of success or failure. So, i need some suggestions.
Thanks.
Share Improve this question asked Aug 29, 2019 at 23:18 AlibagdadAlibagdad 31 bronze badge1 Answer
Reset to default 0You could register a rest route (ref: https://developer.wordpress/reference/functions/register_rest_route/).
In your case, something like this would do the trick:
register_rest_route( 'your-plugin/v1', '/payments/(?P<trans_id>\d+)(?:/(?P<amount>\d+))?', array(
'methods' => 'GET',
'callback' => array( $this, 'your_callback_function'),
'args' => array(
'trans_id' => array(
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
'amount' => array(
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
),
) );
Figure out all of your parameters, setup validation here and then write yourself a callback function to do the actual work.
Wordpress is moving down this path to replace the old admin-ajax api, and it's pretty easy to work with. More info: https://developer.wordpress/rest-api/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745200523a4616298.html
评论列表(0条)