Download the PHP package puntjes/php-sdk without Composer

On this page you can find all versions of the php package puntjes/php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-sdk

puntjes/php-sdk

PHP client for the Puntjes loyalty API.

It works anywhere PHP 8.2 runs: a Laravel webshop, a WooCommerce plugin, a POS bridge, a cron script. It does not force an HTTP client on you.

The client is generated from the Puntjes OpenAPI spec, so it has every call the API has.

Install

The SDK talks PSR-18, so it uses the HTTP client your project already has (Guzzle, Symfony HttpClient, and so on). If you have none, add one:

Quick start

Get the credentials in Puntjes, Settings, API clients. The secret is shown once.

A call is a path and an HTTP method: ->customers()->byCustomer('42')->wallet()->get() is GET /customers/42/wallet. Every call returns a promise. End it with ->wait(), then read the data of the answer with ->getData().

A purchase at the till:

A query value goes in a request configuration:

Pass query values to createQueryParameters() by name, as above. The generated method takes its arguments in alphabetical order, so a new query value in a later release moves the others, and a call by position then sends the wrong value.

Puntjes::make() takes baseUrl (default https://puntjes.app; the API docs form https://puntjes.app/api/v1 works too), tokenStore, httpClient, requestFactory, streamFactory, maxRetries, defaultHeaders and sleeper.

Clearing a field

A setter with null does not clear a field: the client leaves a null value out of the request body. To clear a field in a PATCH (UpdateCustomerData, UpdateProductData), put the null in the additional data:

Amounts are in cents

Every money value on this API is a whole number of cents. 42.00 euro is 4200.

Retries and idempotency

A retry of a request that already moved points is how an integration pays a customer twice. So the SDK retries only what is safe.

Call Retried? Why
Any GET Yes A read changes nothing
PUT, PATCH, DELETE Yes They name the record, so a repeat gives the same result
A POST with an idempotency_key in the body Yes The API answers a repeated key with the first answer
A POST without one No A repeat could create a second customer, send a second email or spend a code twice

A retry happens only after a failure that a later try could survive: no connection, a 5xx or a 429 RATE_LIMITED. The wait doubles each time, and a Retry-After header wins. 429 PLAN_LIMIT_EXCEEDED is never retried: waiting does not clear it.

The SDK does not make an idempotency_key for you. Set one on every POST that moves points (transactions, redemptions, wallet/adjust), and on vouchers/{code}/verify and products/{sku}/reward, where a key also makes the call safe to retry. IdempotencyKey::new() gives a new random key. A key from your own data, such as 'order-'.$order->id, is better: it is the same after a restart.

Keys belong to one shop. The same key with another customer, amount or reward answers IDEMPOTENCY_KEY_CONFLICT, and nothing is written.

Pages

A list answer holds one page. Paginator::of() walks all of them, and asks for the next page only when your loop needs it:

rewards()->get() and a customer's vouchers()->get() are not paged. They answer in one call.

Wallet passes

WalletPass::apple($puntjes, $customerId) returns the Apple pass (a .pkpass file) as a stream. For Google, call ->walletPass()->get() with the query platform: google and read ->getData()->getSaveUrl().

Errors

Everything the SDK throws extends Puntjes\Exception\PuntjesException.

Exception When
AuthenticationException 401. The token is missing, unreadable, expired or revoked. The SDK already got a new token once, so the credentials are wrong or revoked. Or the client may not use client credentials
ForbiddenException 403: the shop is pending, suspended or deactivated
NotFoundException 404: no such record for this shop
ConflictException 409: a duplicate identifier, external id or SKU
ValidationException 422 VALIDATION_ERROR, with errors()
RateLimitException 429 RATE_LIMITED, with retryAfter()
PlanLimitExceededException 429 PLAN_LIMIT_EXCEEDED: the plan is used up
ServerException 5xx
ApiException Any other API error, such as 400 INVALID_JSON and the 422 refusals
TransportException No HTTP answer at all, or a body that is not JSON
ConfigurationException Bad settings, found before any request

The API answers in JSON only. A success answer with another Content-Type, or with JSON that does not parse, throws TransportException. An answer with no Content-Type is read as JSON.

A 422 can be a bad field or a business refusal like INSUFFICIENT_BALANCE. Only the bad field is a ValidationException, so catching it never hides a refusal you need to handle.

ErrorCode lists every code the API documents. For a code that is newer than your SDK, errorCode() is null and code() still gives the raw string. A new code arrives in a minor release, so a match on ErrorCode needs a default arm.

Token storage

By default a token lives in memory for one PHP process. Under PHP-FPM that means one token request per web request. It works, but a shared store is better:

TokenStore has three methods: get, put and forget. Laravel users get a cache-backed store from puntjes/laravel. A WordPress one is below.

Your own HTTP client

Timeouts, proxies and TLS belong to the HTTP client:

WordPress / WooCommerce

Two things matter when you ship this inside a plugin.

1. Scope your dependencies. A WordPress site runs all plugins in one PHP process. If two plugins bundle different versions of one library, one of them breaks. Run PHP-Scoper or Strauss over your vendor folder before you distribute it. Scope every package this SDK installs. On PHP 8.4 with the newest versions that is:

Run composer show --no-dev in your plugin to see the exact list for your PHP version.

2. Cache tokens in a transient. Without it, every page load asks for a new token:

Keep the credentials in wp_options, encrypted at rest where the host allows it, and never log the secret.

Rate limits

The limit belongs to the shop, and its size follows the shop's plan. Plans can differ, so this README gives no number. Every API client and every server of one shop share the same limit. A shop that may not use the API is limited per IP address instead.

When the API answers 429 RATE_LIMITED, the SDK waits for the Retry-After time (or backs off when there is none) and tries again, up to maxRetries, and then throws RateLimitException. It does this only for a call that is safe to repeat (see Retries and idempotency).

Changing the secret without downtime

A shop can have more than one active API client, so no maintenance window is needed:

  1. Create a new API client in the portal.
  2. Deploy the new credentials.
  3. Revoke the old client.

Tokens are cached per credential pair, so the two never mix.

Development

Contract tests

The Unit suite checks the SDK against answers its authors wrote. The Contract suite calls a real app, so a wrong guess about the wire cannot hide. It runs only against a local app, because it creates customers, transactions and redemptions:

With the variables unset, or a base URL that is not local, the suite fails. A refusal is a failure, never a skip, because a skipped suite is green with no call made.

The shop of the API client needs more than a fresh install gives it: a paid plan that grants every feature, the shop's own switch for customer merge, a voucher in SPIKE_VOUCHER, two card codes nobody holds in PUNTJES_LOYALTY_CARDS, and for the partner operations a partner token in PUNTJES_PARTNER_TOKEN with the connection handle the shop's admin allowed in PUNTJES_PARTNER_CONNECTION. The Puntjes repository sets all of them up for its SDK Contract check, in .github/scripts/ci-sdk-contract-seed.php and .github/scripts/ci-sdk-contract.sh. Run the suite the same way.

Every operation in spec/api.json needs a contract test that calls Live::hit(self::CLIENT, '<operationId>'). The Unit suite fails when one has none, so a regenerated client with a new operation stays red until it gets that test. Write the test on main before the Puntjes pull request that adds the operation merges: the Puntjes SDK Contract check regenerates main from that pull request's spec and runs this suite against it, so the test and the seed are proven before the spec is published. The generated class need not exist on main yet; PHPStan reads src only and the Unit suite never loads this directory. Such a test starts with Live::requireOperation('<operationId>'), so a release cut from main before the regenerate skips it instead of failing on a class that is not generated yet.

The suite also checks every answer against spec/api.json. A field the spec marks as always present fails the suite when the answer leaves it out, also when no test reads it.

Checks on a pull request

Every pull request and every push to main runs PHPUnit (Unit suite), PHPStan and Pint in three runs:

Run What it installs What it proves
PHP 8.2 · oldest allowed packages The oldest version of every package that composer.json allows The lower bounds in composer.json are true
PHP 8.2 · newest packages The newest versions that install on PHP 8.2 The package works on its lowest PHP version today
PHP 8.4 · newest packages The newest versions of everything The package works on a current PHP

The check named CI is green only when all three runs are green.

Releasing

Nobody runs a release by hand. release-please reads the conventional commits on main (feat:, fix:, feat!:) and keeps one release pull request open. That pull request holds the next version and its CHANGELOG.md entry. It merges itself when CI is green. The merge tags the version, and Packagist reads the tag.

release-please chooses the version from the commit types since the last release. A fix: raises the patch number, a feat: raises the minor number, and a feat!: or a BREAKING CHANGE: line in the body raises the major number. Nobody sets the version by hand.

Write commit titles in the conventional form, because they become the changelog.

A new Puntjes API spec reaches this repository as a regenerate pull request. The Regenerate workflow opens it on the branch regenerate/<tag> and closes the open ones for older tags. A minor or patch one merges itself when CI is green. A major one asks @cedricdhooge96 for a review and waits. The new pull request is a major too when it replaces an open major one, or when spec/SOURCE on main has a lower major version. The workflow checks out without keeping a token, so its check for an existing branch (git ls-remote origin) works only while this repository is public.

Three cases need a person:

Versions

3.x is the current line, generated from the 2.x specs of puntjes-openapi. 2.x lived one day: 3.0.0 replaced 2.0.0 on 2026-10-12. 1.x gets security fixes on the 1.x branch until 2027-04-11, 6 months after 2.0.0 reached Packagist. Moving from 1.x is described in UPGRADING.md.

Links

License

MIT.


All versions of php-sdk with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
guzzlehttp/psr7 Version ^2.0 || ^3.0
microsoft/kiota-abstractions Version ^2.2.1
microsoft/kiota-serialization-json Version ^2.2.1
microsoft/kiota-serialization-text Version ^2.2.1
php-http/discovery Version ^1.19
php-http/promise Version ^1.2
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.1 || ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package puntjes/php-sdk contains the following files

Loading the files please wait ...