// test-paypal-sdk.js
// Simple test script to verify PayPal SDK configuration

import 'dotenv/config';
import paypalClient from './config/paypal.js';
import { OrdersController } from '@paypal/paypal-server-sdk';

console.log('🧪 Testing PayPal SDK Configuration...\n');

try {
  // Initialize the client
  const client = paypalClient();
  
  console.log('✅ PayPal client initialized successfully!');
  console.log('📦 Client type:', client.constructor.name);
  console.log('🔐 Environment variables loaded:', {
    clientId: process.env.PAYPAL_CLIENT_ID ? '✓ Set' : '✗ Missing',
    clientSecret: process.env.PAYPAL_CLIENT_SECRET ? '✓ Set' : '✗ Missing',
    mode: process.env.PAYPAL_MODE || 'sandbox (default)'
  });
  
  // Test OrdersController initialization
  const ordersController = new OrdersController(client);
  console.log('✅ OrdersController initialized successfully!');
  console.log('📦 OrdersController type:', ordersController.constructor.name);
  console.log('📋 Available methods:', ['getOrder', 'createOrder', 'captureOrder', 'patchOrder', 'authorizeOrder', 'confirmOrder'].join(', '));
  
  console.log('\n✅ Migration successful! The new PayPal SDK is properly configured.');
  console.log('📝 To test payment verification, make a payment through the frontend.');
  
} catch (error) {
  console.error('❌ PayPal configuration error:', error.message);
  console.error('\n🔍 Please check:');
  console.error('   1. PAYPAL_CLIENT_ID is set in .env');
  console.error('   2. PAYPAL_CLIENT_SECRET is set in .env');
  console.error('   3. PAYPAL_MODE is set (optional, defaults to "sandbox")');
  process.exit(1);
}
