# GutengGrow Blocks - Stripe Product Manager Fixes

This guide explains the fixes implemented for the GutengGrow Blocks Stripe Product Manager integration to address the three main issues:

1. Products not showing prices
2. Archived items displaying
3. Checkout not working

## Summary of Fixes Implemented

### 1. Price Display Fix

- Enhanced the price formatting function to properly handle null or zero values
- Added more robust currency formatting for a variety of currency types
- Added detailed error logging to help diagnose price display issues
- Fixed the rendering of formatted_price values in the frontend JavaScript

### 2. Archived Items Fix

- Added proper filtering to exclude archived products
- Implemented metadata checking to filter out products marked as archived
- Added detailed logging to track which products are being filtered out

### 3. Checkout Functionality Fix

- Fixed the checkout process to correctly pass product IDs and price information
- Enhanced error handling for better user feedback
- Fixed nonce verification and AJAX URL determination
- Added fallbacks to handle cases where global variables may not be available
- Streamlined currency detection and validation

### 4. Diagnostic Tools

- Created a comprehensive diagnostic tool that can help identify issues with:
  - Stripe PHP library loading
  - API key validation
  - Stripe API connectivity
  - Product retrieval
  - Hook registration

## How to Use These Fixes

1. **Update the PHP Files**:

   - Replace/update `src/stripe-product-manager/render.php` with our improved version
   - Update the handling of API keys in `admin/stripe-api.php`

2. **Update the JavaScript**:

   - Replace/update `src/stripe-product-manager/view.js` with our improved version
   - This fixes the checkout process and error handling

3. **Add the Diagnostic Tool**:
   - Copy the new `stripe-diagnostic.php` file to the plugin root
   - Access it through your browser at: `/wp-content/plugins/gutengrow-blocks/stripe-diagnostic.php`

## Testing the Integration

1. **Use the Diagnostic Tool**:

   - Open the diagnostic page to check if all components are working correctly
   - Verify Stripe library loading, API key validation, and product retrieval

2. **Test Product Display**:

   - Ensure prices are displaying correctly on the frontend
   - Confirm that archived products are not showing up

3. **Test Checkout Process**:
   - Add products to cart
   - Proceed to checkout
   - Check browser console for any errors
   - Verify the redirect to Stripe's checkout page

## Troubleshooting Common Issues

### Prices Not Showing

If prices still aren't showing:

1. Check the Stripe product configuration in your Stripe dashboard
2. Ensure each product has a default price set
3. Review the error logs for price formatting issues
4. Verify the currency settings in your Stripe account

### Archived Products Still Appearing

If archived products still appear:

1. Make sure the product is properly archived in Stripe
2. Check if the product has metadata with `archived` set to `true`
3. Verify that the product's `active` flag is set to `false` in Stripe

### Checkout Not Working

If checkout still isn't working:

1. Check the browser console for JavaScript errors
2. Verify that the AJAX URL is correct in the network tab
3. Check the WordPress error logs for PHP errors
4. Verify that the correct Stripe API keys are being used
5. Make sure nonces are being properly generated and verified

## WordPress Environment Requirements

- WordPress 5.8+
- PHP 7.2+
- Stripe PHP SDK (installed via Composer)
- SSL Certificate (required for live Stripe payments)

## Stripe API Version

This integration is tested with Stripe API version `2023-10-16`. If you're experiencing issues, check that your Stripe API version is compatible.

## Need More Help?

If you're still experiencing issues after implementing these fixes, please check:

1. WordPress error logs
2. Browser console errors
3. Stripe dashboard events
4. Run the diagnostic tool and review the results

For additional support, please contact the GutengGrow Blocks plugin developer.
