<?php

declare(strict_types=1);

header('Content-Type: application/json; charset=utf-8');

mb_internal_encoding('UTF-8');

ini_set('default_charset', 'UTF-8');

/*
|--------------------------------------------------------------------------
| IMPORTANT
|--------------------------------------------------------------------------
| api folder is:
| /home/ppssys/evs.ppssys.com/epipos/api/
|
| private folder is:
| /home/ppssys/private/
|--------------------------------------------------------------------------
*/

require_once '../../../private/stripe_terminal_config.php';

require_once STRIPE_SDK_PATH . '/init.php';

\Stripe\Stripe::setApiKey(
    STRIPE_SECRET_KEY
);

try {

    $token =
    \Stripe\Terminal\ConnectionToken::create();

    echo json_encode([
        'secret' => $token->secret
    ]);

} catch(Exception $e){

    http_response_code(500);

    echo json_encode([
        'error' => $e->getMessage()
    ]);
}
