admin管理员组

文章数量:1415673

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 badge
Add a comment  | 

1 Answer 1

Reset to default 0

You 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/

本文标签: plugin developmentCreating a return url for getting data from external api