Skip to content

3.0.0 - OnPayAPI split into facade, TokenManager and ApiClient

Choose a tag to compare

@tomsommer tomsommer released this 07 Sep 17:15
· 7 commits to master since this release

OnPayAPI is split into three collaborators.

composer require tomsommer/onpay-php-sdk:^3.0

Why

OnPayAPI had accumulated five unrelated jobs: parsing options, managing the token lifecycle, sending HTTP, handing out service objects, and recording the last exchange for debugging. The tell was get() and post() — marked @internal, but necessarily public, because the four service classes call them. An @internal tag on a public method is a comment pretending to be an access modifier: nothing stopped a consumer posting arbitrary bodies straight past the typed service layer.

The shape now

  • OnPay\Auth\TokenManager reads, refreshes and stores the access token. Every write to storage goes through it, so the refresh-token carry-over and the legacy 1.x token format have one home.
  • OnPay\Http\ApiClient sends authenticated requests and maps the answers onto ApiException / TokenException / ConnectionException. It holds no per-request state, so a single instance is safe to share for the life of an application.
  • OnPayAPI is now a facade: options in, services out. It drops from ~590 lines to 271.

OnPay\Http\ApiClientInterface is the seam the service classes depend on — two verbs plus the platform string, with the exception contract written into the interface, because that is what the services lean on and what any substitute has to honour.

Breaking changes

  • OnPayAPI::get() / post() removed. Use the service objects, or getApiClient() for an endpoint they do not cover yet.
  • OnPayAPI::getLastHttpRequest() / getLastHttpResponse() removed. They forced the client to carry per-request state for debugging alone; a PSR-3 logger or PSR-18 middleware does it better and works under concurrency.
  • OnPayAPI::setHttpClient() removed. Pass the client to the constructor.
  • The four service classes take ApiClientInterface instead of OnPayAPI. Reach them through $api->transaction(), $api->subscription(), $api->payment(), $api->gateway().
  • Requires tomsommer/oauth2-onpay:^2.0, whose namespace is now TomSommer\.

If your integration only calls $api->transaction() / $api->subscription() / $api->payment() / $api->gateway() and catches the SDK exceptions, nothing in your code changes.

Also

The suite grows from 64 tests to 83: transport and token behaviour are now covered directly instead of through the facade, and the service tests mock two methods rather than the whole object. The leftover .gitlab-ci.yml from upstream is gone — it pointed at an internal registry and ran a test suite that no longer exists.