Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* text=auto eol=lf
*.php diff=php
/tests export-ignore
/scripts export-ignore
/SPEC_VERSION export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.github export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
test:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4', '8.5']
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0

- uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2 (2.40.0)
with:
php-version: ${{ matrix.php }}
extensions: json, hash, mbstring
coverage: none
tools: composer:v2

- name: Validate composer.json
run: composer validate --strict

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Dependency advisories
run: composer audit

- name: Vectors match selcom-spec at SPEC_VERSION
run: bash scripts/check-spec.sh

- name: Static analysis (PHPStan, max level)
run: composer analyse

- name: Tests (spec vectors, unit tests; the sandbox test is skipped)
run: composer test

- name: Build (the package archive)
run: composer archive --format=zip --dir=build
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/vendor/
/composer.lock
.phpunit.cache/
.phpunit.result.cache
/build/
.idea/
.vscode/
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Changelog

All notable changes to this project are documented in this file. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project follows [Semantic Versioning](https://semver.org/).

## [Unreleased]

## [0.1.0] - 2026-11-21

First release.

### Added

- Configuration with an explicit environment (no default), credentials held outside the objects that use them (the API key prints its last 4 characters), per-profile timeouts, and an optional second credential set for checkout.
- A pure request signer (flattening, value text, `Signed-Fields`, query string or JSON body) with a pluggable digest signer and HS256.
- A replaceable `Transport` interface and a PSR-18 default using `php-http/discovery` for the factories and a Guzzle client per timeout profile, or your own client (a per-profile closure, or a ready client with `clientManagesTimeouts: true`). Payments and writes use a fresh connection and are never retried. `NOT_SENT` / `UNKNOWN_OUTCOME` classification from cURL request-byte counters, error numbers and connect-phase messages.
- A client with typed request and result objects for the 16 v1 operations: checkout, utility payments, wallet cash-in and vendor balance. Amounts accept an int, a digit string or an integral float.
- The five typed statuses (`SUCCESS`, `PENDING`, `AMBIGUOUS`, `FAILED`, `NOT_FOUND`) with the raw HTTP status and body.
- A webhook verifier following selcom-spec v0.2.1 (`order_id` and `transid` signed, no `&` in signed names or values, bounded number handling, replay entries kept until max(now, signed time) + window), a replay store interface, `ReplayStoreException` for store failures (answer 5xx), and payload parsing with strict amount parsing.
- A redaction helper for logs.
- Secret parameters marked `#[\SensitiveParameter]`; masked output for `var_dump`, `print_r`, `var_export` and array casts.
- Tests that run every case, reject, response scenario and webhook sample of selcom-spec v0.2.1 (copy in `tests/vectors`, recorded in `SPEC_VERSION`, refreshed by `scripts/refresh-spec.sh`, checked by `scripts/check-spec.sh`), plus an opt-in sandbox test.
- GitHub Actions CI on PHP 8.2, 8.3, 8.4 and 8.5: `composer validate --strict`, `composer audit`, vectors match the spec, PHPStan (max level, strict rules), tests and a package build. Actions are pinned to commit SHAs.

[Unreleased]: https://github.com/selcom-developers/selcom-php/compare/v0.1.0...HEAD
[0.1.0]: https://github.com/selcom-developers/selcom-php/releases/tag/v0.1.0
40 changes: 40 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Contributing

Thanks for helping. This is a community client for the Selcom API gateway, and it is **not affiliated with Selcom Paytech Ltd.**

## Ground rules

- **The spec is the source of truth.** Signing, result codes, retries and webhooks are defined in [selcom-spec](https://github.com/selcom-developers/selcom-spec). If this client and the spec disagree, the client is wrong, or the spec needs a fix that every client then picks up: open the spec change first.
- **Clean room.** Write your own code. Do not copy from Selcom's official clients or from other Selcom libraries. Reading them to understand behaviour is fine.
- **No secrets and no real data.** Tests use made-up values only: phones `2557000000xx`, IDs like `ORD-1001` and `TXN-...`, keys like `test-key-0001`, or the sample values printed in Selcom's public documentation. Never commit credentials, customer data or details of any merchant's integration.
- **No automatic retry of payments or writes.** This is a hard rule.

## Development

Requires PHP 8.2 or later and Composer.

```
composer install
composer test # PHPUnit
composer analyse # PHPStan, max level
```

Both must pass on PHP 8.2 to 8.5 (CI runs the matrix). Keep the public API small and stable: the classes listed in the README's "Public API" section follow semantic versioning.

## Spec vectors

The tests run the shared vectors from a copy in `tests/vectors`. To move to another spec tag:

```
scripts/refresh-spec.sh v0.2.0
```

This rewrites `tests/vectors` and `SPEC_VERSION`. Never edit the vectors by hand.

## Pull requests

- One concern per pull request. Add or update tests, and add a line under "Unreleased" in `CHANGELOG.md`.
- Describe the behaviour change and, where the language makes a spec rule awkward, how you handled it.
- Releases, tags and publishing are done by the maintainers.

By contributing you agree that your work is licensed under the Apache License 2.0.
Loading