Skip to content

Expand PurchaseBuilder with all missing API fields#16

Merged
wzul merged 4 commits into
mainfrom
feature/expand-purchase-builder
May 18, 2026
Merged

Expand PurchaseBuilder with all missing API fields#16
wzul merged 4 commits into
mainfrom
feature/expand-purchase-builder

Conversation

@wzul
Copy link
Copy Markdown
Collaborator

@wzul wzul commented May 18, 2026

What does this change?

This PR brings the PurchaseBuilder into full parity with the CHIP Collect OpenAPI specification. Previously, the SDK's fluent interface was incomplete, forcing developers to manually assign values to model properties, which bypassed type safety and led to inconsistent code styles.

Key technical changes:

  • Fluent Interface Expansion: Implemented a comprehensive set of setter methods across three logical areas:
    • Top-level Purchase: Added clientId, sendReceipt, skipCapture, forceRecurring, reference, issued, due, creatorAgent, platform, tags, and paymentMethodWhitelist.
    • Purchase Details: Added methods for notes, debt, subtotalOverride, totalTaxOverride, totalDiscountOverride, totalOverride, requestClientDetails, timezone, dueStrict, emailMessage, shippingOptions, paymentMethodDetails, hasUpsellProducts, singleAttempt, and metadata.
    • Client Details: Added full address support (street, city, zip, state, country) for both billing and shipping, contact lists (cc, bcc), and corporate identity fields (legal name, registration, tax numbers, bank details).
  • Refined Product Logic: The addProduct() method signature has been extended to support optional fields (discount, tax_percent, category, total_price_override).
  • Data Normalization: Standardized the quantity field to be handled as a string. This aligns with the API's expectation for high-precision decimals and prevents floating-point rounding issues during serialization.
  • Lazy Initialization: Leveraged ensureClient() within the builder to manage nested ClientDetails objects, ensuring the fluent API remains clean without requiring the developer to instantiate nested models manually.

Asana / Jira / Trello task link

How to test

  1. Unit Testing: Execute the expanded test suite to verify all new mappings:
    vendor/bin/phpunit tests/PurchaseBuilderTest.php
  2. Coverage Verification: Ensure the following new test cases pass:
    • testTopLevelPurchaseFields: Verifies mapping of root-level properties.
    • testPurchaseDetailsFields: Verifies overrides and metadata nesting.
    • testClientDetailsFields & testNullableClientDetailsFields: Validates the ClientDetails object construction and handling of null values for optional states/bank codes.
    • testProductWithAllFields: Confirms the new optional parameters in addProduct map to the Product model correctly.
    • testClientIsCreatedOnlyOnce: Ensures the ensureClient() logic preserves state across multiple calls.

Potential Risks & Senior Review Items

  • Core Method Signature Change: addProduct() now has four additional optional parameters. While this is backward compatible for positional arguments, it may affect consumers using reflection or specific interceptors.
  • Field Mapping Accuracy: Please cross-reference the snake_case keys in PurchaseBuilder.php (e.g., total_tax_override, shipping_street_address) against the official CHIP Collect API docs to ensure no typos were introduced in the mapping logic.
  • Type Casting: quantity is now strictly cast to string. Verify that existing integrations expecting float in the resulting model object (though unlikely for a builder) are not negatively impacted.
  • Nested Object State: Review the ensureClient() pattern to confirm that calling multiple client* methods sequentially correctly modifies the same ClientDetails instance.

Is this PR warrant an automatic approval?

No. While many of the additions are boilerplate setters, the sheer volume of new fields and the modification of the addProduct signature require a manual sanity check to ensure architectural consistency and API alignment.

Images

Add fluent methods for every field defined in the CHIP Collect OpenAPI
spec that was previously only accessible via direct model assignment:

- Top-level Purchase: clientId, sendReceipt, skipCapture, forceRecurring,
  reference, issued, due, creatorAgent, platform, tags
- PurchaseDetails: notes, debt, subtotalOverride, totalTaxOverride,
  totalDiscountOverride, totalOverride, requestClientDetails, timezone,
  dueStrict, emailMessage, shippingOptions, paymentMethodDetails,
  hasUpsellProducts, singleAttempt, metadata
- ClientDetails: clientPersonalCode, clientStreetAddress, clientCountry,
  clientCity, clientZipCode, clientState, clientShippingStreetAddress,
  clientShippingCountry, clientShippingCity, clientShippingZipCode,
  clientShippingState, clientCc, clientBcc, clientLegalName,
  clientBrandName, clientRegistrationNumber, clientTaxNumber,
  clientBankAccount, clientBankCode
- Product: extend addProduct() with optional discount, taxPercent,
  category, totalPriceOverride

Also add comprehensive test coverage for all new methods.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
wzul and others added 3 commits May 18, 2026 13:01
- Remove nullable types from builder methods where model properties
  are typed as non-nullable (clientId, due, subtotalOverride,
  totalTaxOverride, totalDiscountOverride, totalOverride)
- Add array value type annotations to array-typed parameters
  (tags, clientCc, clientBcc, requestClientDetails, shippingOptions,
  paymentMethodWhitelist)
- Remove assertNull tests for properties that cannot be null per model types
- Add CHANGELOG.md entry documenting all new builder methods

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@wzul wzul merged commit ebc23ed into main May 18, 2026
8 checks passed
@wzul wzul deleted the feature/expand-purchase-builder branch May 18, 2026 05:06
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