Skip to content

Conversation

@vuckro
Copy link
Contributor

@vuckro vuckro commented Aug 7, 2025

Fixes "Bad request - Invalid parameter(s): gateway_customer_id" error when creating memberships via POST API.

Gateway customer IDs are typically strings rather than integers in most payment gateways (Stripe, PayPal, etc.). This change aligns the membership-create schema with the membership-update schema which was already corrected.

Changes:

  • inc/api/schemas/membership-create.php: Change gateway_customer_id type from 'integer' to 'string'

This resolves API validation errors when integrating with external tools like N8N for membership creation workflows.

@vuckro vuckro marked this pull request as ready for review August 7, 2025 18:03
@vuckro vuckro closed this Aug 9, 2025
@vuckro vuckro deleted the fix/api/membership-create branch August 9, 2025 12:43
@vuckro vuckro restored the fix/api/membership-create branch August 9, 2025 12:43
@vuckro vuckro reopened this Aug 9, 2025
@vuckro vuckro closed this Aug 9, 2025
@vuckro vuckro deleted the fix/api/membership-create branch August 9, 2025 12:50
@vuckro vuckro restored the fix/api/membership-create branch August 9, 2025 12:51
@vuckro vuckro reopened this Aug 9, 2025
vuckro added a commit to vuckro/multisite-ultimate that referenced this pull request Aug 9, 2025
…t `line_items` arrays are converted to `Line_Item` objects

## Summary
This PR complements [Multisite-Ultimate#149](Multisite-Ultimate#149) by fixing an additional case where payments created via the API store `line_items` as arrays instead of `WP_Ultimo\Checkout\Line_Item` objects.

Without this conversion, certain admin views, hooks, or calculations may fail or produce inconsistent results.

## Context
- PR Multisite-Ultimate#149 addressed object handling for customer/site data during API operations.
- However, for payments created via API, `line_items` can still be saved as **plain arrays** in meta.
- When `Payment::get_line_items()` is called, these arrays cause:
  - PHP warnings/notices when object methods are accessed.
  - Incorrect totals or missing data in the admin payment view.
  - Hook/filter incompatibility for extensions expecting `Line_Item` objects.

## Changes
- **File:** `inc/models/class-payment.php`
- **Method:** `get_line_items()`
- **Added logic**:
  - Map each `line_item` array into a proper `WP_Ultimo\Checkout\Line_Item` instance.
  - Leave items already in object form untouched.
  - Apply `array_filter` to remove any empty/null entries.

## Impact
- **Backward compatible** – works for both legacy object-based storage and array-based storage from API-created payments.
- Fixes admin display and ensures consistent hook behavior.
- No database schema changes.

## Testing
1. Create a payment via the API where `line_items` are stored as arrays.
2. Load the payment in the admin panel – items should now display correctly, without warnings in logs/Query Monitor.
3. Hooks and calculations relying on `Line_Item` objects should now run without errors.

## Review Notes
- Defensive conversion (`is_array($item)`) to avoid touching already valid objects.
- Safe, isolated change with no side effects beyond `get_line_items()` behavior.
vuckro added a commit to vuckro/multisite-ultimate that referenced this pull request Aug 9, 2025
…ership-create schema Multisite-Ultimate#149 (#18)

* Fix gateway_customer_id type from integer to string in membership-update schema

The API returns "Bad request - Invalid parameter(s): gateway_customer_id" because
the schema defines gateway_customer_id as integer type instead of string.

Gateway customer IDs are typically strings rather than integers in most payment
gateways, so this change fixes API validation errors when passing gateway customer IDs.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix Line Items deserialization in admin interface

Resolves critical error in admin interface when displaying payment line items.

The issue occurred because line_items were stored as serialized PHP arrays
in the database but were not properly converted back to Line_Item objects
when retrieved. This caused fatal errors when admin pages tried to call
methods like get_product() on array data instead of Line_Item objects.

Changes:
- Modified Payment::get_line_items() to automatically convert arrays to Line_Item objects
- Added proper type checking and conversion in the deserialization process
- Ensures backward compatibility with existing stored data

Fixes admin interface crashes in payment line items display.

* Update membership-create.php

* Update class-payment.php

---------

Co-authored-by: Claude <noreply@anthropic.com>
vuckro added a commit to vuckro/multisite-ultimate that referenced this pull request Aug 9, 2025
* Fix API validation: Change gateway_customer_id type to string in membership-create schema Multisite-Ultimate#149 (#18)

* Fix gateway_customer_id type from integer to string in membership-update schema

The API returns "Bad request - Invalid parameter(s): gateway_customer_id" because
the schema defines gateway_customer_id as integer type instead of string.

Gateway customer IDs are typically strings rather than integers in most payment
gateways, so this change fixes API validation errors when passing gateway customer IDs.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix Line Items deserialization in admin interface

Resolves critical error in admin interface when displaying payment line items.

The issue occurred because line_items were stored as serialized PHP arrays
in the database but were not properly converted back to Line_Item objects
when retrieved. This caused fatal errors when admin pages tried to call
methods like get_product() on array data instead of Line_Item objects.

Changes:
- Modified Payment::get_line_items() to automatically convert arrays to Line_Item objects
- Added proper type checking and conversion in the deserialization process
- Ensures backward compatibility with existing stored data

Fixes admin interface crashes in payment line items display.

* Update membership-create.php

* Update class-payment.php

---------

Co-authored-by: Claude <noreply@anthropic.com>

* Revert "Fix API validation: Change gateway_customer_id type to string in memb…"

This reverts commit 8eadf9b.

---------

Co-authored-by: Claude <noreply@anthropic.com>
vuckro added a commit to vuckro/multisite-ultimate that referenced this pull request Aug 9, 2025
…t line_items arrays are converted to Line_Item objects Multisite-Ultimate#158 (#20)

* Fix gateway_customer_id type from integer to string in membership-update schema

The API returns "Bad request - Invalid parameter(s): gateway_customer_id" because
the schema defines gateway_customer_id as integer type instead of string.

Gateway customer IDs are typically strings rather than integers in most payment
gateways, so this change fixes API validation errors when passing gateway customer IDs.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix Line Items deserialization in admin interface

Resolves critical error in admin interface when displaying payment line items.

The issue occurred because line_items were stored as serialized PHP arrays
in the database but were not properly converted back to Line_Item objects
when retrieved. This caused fatal errors when admin pages tried to call
methods like get_product() on array data instead of Line_Item objects.

Changes:
- Modified Payment::get_line_items() to automatically convert arrays to Line_Item objects
- Added proper type checking and conversion in the deserialization process
- Ensures backward compatibility with existing stored data

Fixes admin interface crashes in payment line items display.

* Update membership-create.php

* Update class-payment.php

---------

Co-authored-by: Claude <noreply@anthropic.com>
…tring

- Change gateway_customer_id type from 'integer' to 'string' in membership-create schema
- This fixes API validation issues when gateway customer IDs are strings (common with payment gateways)
@vuckro vuckro force-pushed the fix/api/membership-create branch from bf25262 to 830db66 Compare August 9, 2025 17:46
Copy link
Collaborator

@superdav42 superdav42 left a comment

Choose a reason for hiding this comment

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

I thought I already merged this is, but I guess not.

@superdav42 superdav42 merged commit 4fd13cc into Multisite-Ultimate:main Aug 13, 2025
18 checks passed
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