- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 64
 
Fix API validation: Change gateway_customer_id type to string in membership-create schema #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            superdav42
  merged 1 commit into
  Multisite-Ultimate:main
from
vuckro:fix/api/membership-create
  
      
      
   
  Aug 13, 2025 
      
    
                
     Merged
            
            Fix API validation: Change gateway_customer_id type to string in membership-create schema #149
                    superdav42
  merged 1 commit into
  Multisite-Ultimate:main
from
vuckro:fix/api/membership-create
  
      
      
   
  Aug 13, 2025 
              
            Conversation
  
    
      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
    
  
  
    
    
    
  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)
bf25262    to
    830db66      
    Compare
  
    
              
                    superdav42
  
              
              approved these changes
              
                  
                    Aug 13, 2025 
                  
              
              
            
            
There was a problem hiding this 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.
  
    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.
  
    
  
    
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:
This resolves API validation errors when integrating with external tools like N8N for membership creation workflows.