0

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.

0

You could register a rest route (ref: https://developer.wordpress.org/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.org/rest-api/

  • Okay, Thank you. I'll try it. – Elmakos Aug 30 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.