Feature/sdk improvements#14
Merged
Merged
Conversation
- Update composer.json to require PHP ^8.0 (was >=7.2.0, which was incompatible with existing PHP 8 constructor property promotion) - Fix implicitly nullable parameter warnings in Purchase trait by using explicit nullable types (?int)
Create domain-specific exceptions that map HTTP status codes to meaningful error types: - ChipApiException (base) — exposes response body via getResponseBody() - AuthenticationException — 401 responses - NotFoundException — 404 responses - ValidationException — 422 responses with getErrors() - ClientException — other 4xx responses - ServerException — 5xx responses
Rewrite request() to catch Guzzle HTTP exceptions and throw domain-specific exceptions based on status code. Add PSR-3 logger injection for request/response observability. Support configurable request timeout via the array (defaults to 30s).
- phpstan.neon.dist: level 8 analysis for lib/ and tests/ - .php-cs-fixer.dist.php: PSR-12 + additional rules for lib/, tests/, examples/
Provide a fluent builder for constructing Purchase objects without
manually nesting ClientDetails, PurchaseDetails, and Product models.
Example:
= PurchaseBuilder::create()
->brandId('brand_123')
->currency('MYR')
->clientEmail('test@example.com')
->addProduct('Widget', 5000, 2)
->build();
- Add model mapping tests (Purchase, PaymentMethods, Webhook, ClientDetails) - Add exception handling tests for 401, 404, 422, 500 - Add logger integration test - Add timeout configuration test - Fix existing tests to pass correct types (string IDs, Purchase objects) - Add jsonResponse() helper for type-safe JSON encoding in tests
- ci.yml: run tests on PHP 8.0-8.3 matrix, static analysis, code style - pr-summary.yml: auto-generate PR descriptions via Ollama Cloud - scripts/generate_pr_summary.py: Python script to call Ollama API
- README.md: rewrite with badges, quick-start, API reference, error handling, builder usage, logging, and development commands - CONTRIBUTING.md: add contribution guidelines with test/style workflow - CLAUDE.md: update with new commands and architecture details
Resolve conflicts and incorporate upstream changes: - Add Billing API trait and models from main - Add markAsPaid method to Purchase trait - Add deleteWebhook method to Webhook trait - Add getClients method to Client trait - Add logos property to PaymentMethods model - Add .env.example and test.php from main - Keep our improvements: exceptions, logging, builder, tests, CI
- ci.yml: actions/checkout v4 → v6, actions/cache v4 → v5 - Add changelog.yml: validate CHANGELOG.md is updated on PRs touching lib/ - Add release.yml: create GitHub Releases from version tags using CHANGELOG.md - Remove test.php development script (not part of test suite, uses real credentials) - Add .env.example to .gitignore alongside existing entries
- Add ModelTest.php covering JsonSerializable and null-stripping for all models - Add ExceptionTest.php with isolated exception unit tests - Add negative webhook verification test (invalid signature returns false) - Add billing API tests covering all 11 billing endpoints - Add getClients() test - Fix PHPStan level 8 errors in billing models and traits by adding property/return types - Run php-cs-fixer across the entire codebase for consistent formatting Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- guzzlehttp/guzzle ^7.0 → ^7.9 (5 years of security fixes since 7.0) - phpunit/phpunit ^9.0 → ^9.6 (EOL branch vs maintained branch) - phpstan/phpstan ^1.10 → ^1.12 (bug fixes and improvements) Installed versions confirmed: Guzzle 7.10.0, PHPUnit 9.6.34, PHPStan 1.12.33 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- PHP ^8.0 → ^8.1 with platform.php 8.1.0 - PHPUnit ^9.6 → ^10.5 (PHP 8.1 compatible) - PHPStan ^1.12 → ^2.1 (major upgrade with better analysis) - php-cs-fixer ^3.0 → ^3.95 (unlocked from 3.4.x PHP 8.0 limitation) - CI matrix: removed PHP 8.0, updated static-analysis and code-style to 8.1 - Fixed remaining code style issues in example files All 66 tests pass, PHPStan reports 0 errors, code style clean. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Document PHP 8.1 bump, PHPUnit 10, PHPStan 2, php-cs-fixer 3.95 - Document expanded test coverage, GitHub Actions workflows - Document fixed PHPStan errors and composer.json validation Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- New traits: Account (balance, turnover), PublicKey, Statements - Expanded Client trait: get, update, partial update, delete, recurring tokens - Expanded Webhook trait: list, update, partial update - Expanded Purchase trait: resend invoice - Fixed PaymentMethod to accept optional query parameters - New models: ClientRecurringToken, ClientRecurringTokenList, CompanyStatement, CompanyStatementList, WebhookList - Added tests for all new endpoints and fixed currency to MYR Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Updated README.md, composer.json, and config.php for PHP 8.1 - Added examples for all new endpoints: Account, Statements, Client CRUD, Webhook Management, Purchase Builder - Replaced raw curl in callback/webhook/public_key examples with SDK methods - Added navigation links in index.php for all example categories Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Update PHP requirement in README from ^8.0 to ^8.1 (matching composer.json) - Add documentation for all new endpoints: Account, Statements, PublicKey, Client CRUD, Webhook list/update, resendInvoice, PurchaseBuilder - Fix CHANGELOG release date from 2025-05-13 to 2026-05-14 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Purchase: add notes, marked_as_paid, order_id, upsell_campaigns, referral_campaign_id, referral_code, referral_code_details, referral_code_generated, retain_level_details, can_retrieve, can_chargeback, can_reverse_chargeback, tags. Fix status_history to array, issued to string|null. - PurchaseDetails: add shipping_options, payment_method_details, has_upsell_products, single_attempt, metadata. - Product: add category, total_price_override. Fix quantity and tax_percent to string|null per spec. - ClientDetails: add state, shipping_state, bank_account, bank_code. - PaymentMethods: fix by_country, country_names, names to array with @phpstan-var for precise typing. - PurchaseBuilder: cast quantity to string to match model type. - ModelTest: update quantity values to strings. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
JsonMapper cannot parse array<...> syntax and treats it as a class name. Use plain @var array for JsonMapper compatibility and @phpstan-var for PHPStan level 8 precise typing. - PaymentMethods::$logos: @var array<string, mixed>|null → @var array - Purchase::$status_history: @var array<int, object> → @var array - Purchase::$upsell_campaigns: @var array<int, mixed> → @var array - PurchaseDetails::$shipping_options: @var array<int, mixed> → @var array Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This release contains breaking changes: - PHP requirement raised from >=7.2.0 to ^8.1 - Model property type changes (Product::quantity/tax_percent to string, Purchase::issued to string|null, Purchase::status_history to array) - Exception handling rewritten to throw domain-specific exceptions Changes: - CHANGELOG.md: rename 1.2.0 section to 2.0.0, update compare links - MIGRATION.md: comprehensive guide covering PHP version, exception handling, model property type changes, new constructor parameter, new features - README.md: update install version to ^2.0, add migration link - examples/composer.json: update requirement to ^2.0.0 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…v2.0.0 - Replace trait-based ChipApi with resource objects (purchases, clients, webhooks, paymentMethods, account, statements, publicKey, billing) - Add internal HTTP abstraction: ClientInterface, GuzzleClient, RetryClient - Remove netresearch/jsonmapper dependency; add fromArray() to all models - Add exponential backoff retry for 429/5xx responses - Add pagination iterators for list endpoints (clients, webhooks, statements, billing templates, billing template clients) - Create BillingResource with fromArray() on all billing models - Rewrite tests for new resource-based API - Update README, MIGRATION.md, and CHANGELOG for v2.0.0 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
azuddin
approved these changes
May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change?
This PR represents a major architectural modernization of the CHIP PHP SDK, transitioning it from a basic Guzzle wrapper to a robust, enterprise-ready SDK (v2.0.0).
The Problem:
The previous version lacked strong type safety, had limited observability, and required developers to manually handle raw HTTP response parsing and Guzzle-specific exceptions. The absence of a structured CI/CD pipeline and static analysis made the codebase prone to regressions, while the reliance on legacy PHP versions prevented the use of modern language features.
The Solution:
matchexpressions.$chip->purchases->create()instead of$chip->createPurchase()). This improves discoverability and organizes the API into logical domains (purchases,clients,webhooks,account,billing, etc.).AuthenticationException,ValidationException,NotFoundException, etc.).ValidationExceptionnow allows developers to call$e->getErrors()to retrieve granular API feedback.RetryClientdecorator using Guzzle middleware to provide exponential backoff for429(Rate Limit) and5xx(Server Error) responses.PurchaseBuilderto provide a developer-friendly API for constructing complexPurchasemodels without manual nesting of objects.netresearch/jsonmapperdependency with nativefromArray()static factories on models. Fixed property types (e.g., changingProduct::$quantityfromfloattostring|null) to accurately reflect API payloads and prevent precision issues.iterate()methods to list endpoints, allowing developers to process large datasets without manually managing page tokens.Asana / Jira / Trello task link
How to test
composer testto ensure the refactored exception mapping and new resource classes pass across PHP 8.1 through 8.4.composer phpstanto verify that all new type hints and docblocks satisfy Level 8 analysis.composer cs-checkto ensure adherence to the new PSR-12 configuration.ValidationException::getErrors()correctly parses the error payload.iterate()methods inClientsResourceorWebhooksResourceagainst an account with multiple pages of data.Potential Risks & Senior Review Items
MIGRATION.mdfor completeness.Product::$quantityandProduct::$tax_percentwere changed fromfloattostring|null. While this matches the API's string-based decimal representation, users performing direct arithmetic on these properties will now need to cast them to floats.lib/Http/RetryClient.php. Ensure the default max retries (3) and timing won't lead to excessive execution times in synchronous request cycles.ChipApiclass uses magic__getor direct instantiation for resources. Reviewlib/ChipApi.phpto ensure resource objects are handled efficiently.netresearch/jsonmapper. Confirm that the manualfromArray()implementations inlib/Model/cover all edge cases previously handled by the library.Is this PR warrant an automatic approval?
No. This is a foundational refactor that changes the error-handling contract, introduces a new major PHP requirement, and alters the core request architecture. It requires a thorough manual architectural review.
Images
Back-End or Front-End dependency tasks/PRs?