Skip to content

Fix v2.0.0 examples to use resource-based API#15

Merged
wzul merged 2 commits into
mainfrom
fix/v2-examples
May 14, 2026
Merged

Fix v2.0.0 examples to use resource-based API#15
wzul merged 2 commits into
mainfrom
fix/v2-examples

Conversation

@wzul
Copy link
Copy Markdown
Collaborator

@wzul wzul commented May 14, 2026

What does this change?

This PR updates the SDK example scripts to align with a major architectural refactor in the underlying chip-fpx library. The SDK has transitioned from a flat method structure on the main ChipApi class to a more organized, resource-grouped approach (Domain-Driven Design).

Why is this necessary?
The previous examples became obsolete and would result in "Method not found" errors because the SDK now encapsulates functionality within specific resource properties.

Key Improvements:

  • Resource Grouping: Updated all API calls to use the new nested structure (e.g., $chip->purchases->create() instead of $chip->createPurchase()). This affects purchases, clients, accounts, payment methods, public keys, statements, and webhooks.
  • PurchaseBuilder Refactor: Updated the builder pattern to use the new static create() entry point and cleaner method names (removing the with prefix).
  • Model Property Alignment: Specifically in webhook_management.php, the model properties were updated to match the latest API schema where url has been renamed to callback and event_type is now handled via title.
  • Distribution Cleanup: Added a .gitattributes file to ensure that development-related folders (/tests, /examples) and configuration files are excluded when the package is installed via Composer or exported, reducing the package footprint.

Asana / Jira / Trello task link

How to test

  1. Ensure you are using the latest version of the chip-fpx SDK.
  2. Configure your credentials in examples/config.php.
  3. Account Balance: Run php examples/api/account_balance.php and verify it returns the current balance using the new $chip->account->balance() syntax.
  4. CRUD Operations: Run php examples/api/client_crud.php and verify that clients can be created, listed, and updated via the $chip->clients resource.
  5. Purchase Creation: Execute php examples/api/create_purchase.php and examples/api/purchase_builder.php to ensure the checkout URL generation is still functional.
  6. Webhooks: Verify webhook_management.php by checking if webhooks are correctly listed and created using the new callback and title fields.
  7. Package Export: Run git archive to ensure the files listed in .gitattributes are correctly excluded.

Potential Risks & Senior Review Items

  • SDK Versioning: These examples are now strictly compatible with the refactored SDK. Users on older versions will find these examples broken.
  • Method Chaining Typoz: Senior review should double-check the pluralization of resources (e.g., purchases, clients, statements, webhooks) to ensure they match the SDK's property names exactly.
  • Payment Methods Argument: Note that paymentMethods->list('MYR') now includes a currency string. Review if this should be hardcoded or pulled from a config.
  • Webhook Model Change: Confirm the API transformation from url/event_type to callback/title is consistent with the backend API specifications.

Is this PR warrant an automatic approval?

No. While these are example files, they serve as the primary documentation for integration. A manual verification is required to ensure no typos were introduced in the method chaining and that the builder methods (like addProduct) align with the latest SDK implementation.

Images

wzul and others added 2 commits May 14, 2026 14:36
- create_purchase.php: \$chip->createPurchase() → \$chip->purchases->create()
- get_purchase.php: \$chip->getPurchase() → \$chip->purchases->get()
- payment_methods.php: \$chip->getPaymentMethods() → \$chip->paymentMethods->list('MYR')
- public_key.php: \$chip->getPublicKey() → \$chip->publicKey->get()
- webhook.php: \$chip->getPublicKey() → \$chip->publicKey->get()
- callback.php: \$chip->getPublicKey() → \$chip->publicKey->get()
- account_balance.php: \$chip->getBalance() → \$chip->account->balance()
- client_crud.php: \$chip->createClient() → \$chip->clients->create(), etc.
- statements.php: \$chip->listStatements() → \$chip->statements->list(), etc.
- webhook_management.php: \$chip->listWebhooks() → \$chip->webhooks->list(), etc.
- purchase_builder.php: fix to use actual PurchaseBuilder::create() API with real method names

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@azuddin azuddin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wzul wzul merged commit 28ebfad into main May 14, 2026
7 checks passed
@wzul wzul deleted the fix/v2-examples branch May 14, 2026 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants