integer-net/callback-proxy

A proxy to dispatch callback requests to multiple targets. Useful to share payment integrations with multiple (e.g. test) systems.

dev-master 2018-11-15 08:48 UTC

This package is auto-updated.

Last update: 2024-10-15 22:15:51 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

This is a service to integrate third party integrations with multiple environments, typically test systems.

It can distribute callbacks to several systems, for example:

proxy.example.com/paypal-dev/postBack

=>

dev1.example.com/paypal/postBack
dev2.example.com/paypal/postBack
dev3.example.com/paypal/postBack

The first successful response is returned. If no response was successful (HTTP status code 200), the last response is returned.

If it is used for dev systems, only the proxy must be made accessible from outside by the third party, instead of all target systems.

Installation

  1. Create project via composer
    composer create-project integer-net/callback-proxy
    
  2. Set up web server with document root in public.

Configuration

  1. Copy config.php.sample to config.php.

  2. Adjust the proxy/targets configuration, e.g.:

    'proxy' => [
        'targets' => [
            'paypal-dev' => [
                'https://dev1.example.com/paypal/',
                'https://dev2.example.com/paypal/',
            ],
        ],
    ],
    

    This example routes /paypal-dev/* to https://dev1.example.com/paypal/* and https://dev2.example.com/paypal/*.

Advanced Configuration

Instead of a plain URI string, each target can also be configured with additional options:

[
  'uri' => 'https://dev1.example.com/paypal/',
  'basic-auth' => 'username:password',
]
  • uri (required) - the base URI
  • basic-auth - HTTP basic authentication in the form "username:password"

The default dispatcher strategy is to dispatch the request to all targets and return the first successful (2xx) response.

You can choose a different strategy in config.php:

'proxy' => [
    'strategy' => \IntegerNet\CallbackProxy\DispatchStrategy\DispatchAllReturnFirstSuccess::class,
]

Available Strategies:

  • \IntegerNet\CallbackProxy\DispatchStrategy\DispatchAllReturnFirstSuccess::class - the default strategy, see above
  • \IntegerNet\CallbackProxy\DispatchStrategy\StopOnFirstSucces::class - returns the first successful (2xx) response, stops dispatching further targets

You can implement your own strategies, by implementing the \IntegerNet\CallbackProxy\DispatchStrategy interface.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

composer test

Runs unit tests, mutation tests and static analysis

php -S localhost:9000 -t public 

Starts the proxy locally on port 9000 for manual testing. Needs a valid configuration in config.php. As a generic target URI, you can use https://httpbin.org/anything/

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email fs@integer-net.de instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.