<?php
require_once 'vendor/autoload.php';

// Stripe secret api key for backend
$stripe_secret_key = 'sk_test_51SM7jR5bIUG0Ff0KoLagk1XAodkE6uUCMN8Ny4FDuiCY6EUlMucMb7IjNaaJgIj3fXZLDtBtLki6DlQjhKgl1Tt600QRcF0nzg';

// Stripe publishable api key for frontend
$stripe_publishable_key = 'pk_test_51SM7jR5bIUG0Ff0K49ESuSWeR8gFB36qB086zKWOif0Gcq7QCzupehyym8MFl7sT3qBLmsy1XMM2v7ErDW7RgodL005bnmgvG4';

\Stripe\Stripe::setApiKey($stripe_secret_key);

function getStripeProducts() {
    try {
        $products = \Stripe\Product::all(['active' => true]);
        //echo '<pre>' . print_r($products, true) . '</pre>';

        $productsWithPrices = [];

        foreach($products->data as $product) {
            $productsWithPrices[] = [
                'id' => $product['id'],
                'name' => $product['name'],
                'priceId' => $product['default_price']
            ];
        }

        return $productsWithPrices;

    } catch(Exception $ex) {
        echo 'Exception: ' . $ex->getMessage() . '<br>';
        return [];
    }
}

//$stripeProducts = getStripeProducts();
//echo '<pre>' . print_r($stripeProducts, true) . '</pre>';