# fluent-cart/1.6.1/app/Modules/PaymentMethods/StripeGateway/API/API.php

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version 1.6.1. 239 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/1.6.1/code/app/Modules/PaymentMethods/StripeGateway/API/API.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.6.1/raw/app/Modules/PaymentMethods/StripeGateway/API/API.php
- Modified: 2026-07-29T13:15:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-cart/1.6.1/code/app/Modules/PaymentMethods/StripeGateway/API/API.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Modules\PaymentMethods\StripeGateway\API;

use FluentCart\App\Modules\PaymentMethods\StripeGateway\StripeSettingsBase;
use FluentCart\Framework\Support\Arr;

class API
{
    private $createSessionUrl;

    private $apiUrl = 'https://api.stripe.com/v1/';

    public function makeRequest($path, $data = [], $apiKey = null, $method = 'GET')
    {
        if (!$apiKey) {
            $apiKey = $this->getApiKey();
        }

        return $this->remoteRequest($path, $data, $apiKey, $method);
    }

    public function getStripeObject($path, $data = [], $mode = 'current')
    {
        $apiKey = (new StripeSettingsBase())->getApiKey($mode);

        return $this->remoteRequest($path, $data, $apiKey, 'GET');
    }

    public function createStripeObject($path, $data = [], $mode = 'current', $headers = [])
    {
        $apiKey = (new StripeSettingsBase())->getApiKey($mode);
        return $this->remoteRequest($path, $data, $apiKey, 'POST', $headers);
    }

    public function deleteStripeObject($path, $data = [], $mode = 'current')
    {
        $apiKey = (new StripeSettingsBase())->getApiKey($mode);
        return $this->remoteRequest($path, $data, $apiKey, 'DELETE');
    }

    public function remoteRequest($path, $data, $apiKey, $method, $extraHeaders = [])
    {
        $stripeApiKey = $apiKey;

        // Never fire a request with an empty Authorization header — Stripe replies
        // with the cryptic "You did not provide an API key" error. This happens when
        // the secret key for the requested mode is not configured (e.g. a store in
        // test mode charging a live-mode order, or unconfigured keys). Fail early
        // with an actionable message instead.
        if (empty($stripeApiKey)) {
            return new \WP_Error(
                'stripe_missing_api_key',
                __('Stripe API key is not configured for this payment mode. Please add your Stripe keys in Payment Settings.', 'fluent-cart')
            );
        }

        $apiVersion = '2025-02-24.acacia';
        $sessionHeaders = array(
            'Authorization'  => 'Bearer ' . $stripeApiKey,
            'Content-Type'   => 'application/x-www-form-urlencoded',
            'Stripe-Version' => $apiVersion
        );

        // Per-request headers (e.g. Idempotency-Key for off-session renewal charges)
        if ($extraHeaders && is_array($extraHeaders)) {
            $sessionHeaders = array_merge($sessionHeaders, $extraHeaders);
        }

        $url = $this->apiUrl . $path;

        if ($method === 'GET' && is_array($data) && !empty($data)) {
            $url .= '?' . http_build_query($data);
            $requestData = array(
                'headers' => $sessionHeaders,
                'method'  => $method,
            );
        } else {
            $requestData = array(
                'headers' => $sessionHeaders,
                'body'    => is_array($data) ? http_build_query($data) : $data,
                'method'  => $method,
            );
        }

        $sessionResponse = wp_remote_request($url, $requestData);

        if (is_wp_error($sessionResponse)) {
            return $sessionResponse;
        }

        $sessionResponseData = wp_remote_retrieve_body($sessionResponse);
        $responseBodyArray = json_decode($sessionResponseData, true);

        $statusCode = wp_remote_retrieve_response_code($sessionResponse);

        if ($statusCode >= 300) {

            $message = Arr::get($responseBodyArray, 'detail');
            if (!$message) {
                $message = Arr::get($responseBodyArray, 'error.message');
            }
            if (!$message) {
                $message = __('Unknown Stripe API request error', 'fluent-cart');
            }

            return new \WP_Error('api_error', $message, $responseBodyArray);
        }

        return $responseBodyArray;
    }

    public function verifyIPN()
    {
        $rawPayload = @file_get_contents('php://input');

        $data = $rawPayload ? json_decode($rawPayload) : null;

        if (empty($data) && !empty($_POST)) {
            $postArray = stripslashes_deep($_POST);
            $data = json_decode(wp_json_encode($postArray));
        }

        if (!$data || empty($data->id)) {
            return new \WP_Error('invalid_data', __('Invalid or empty payload received from Stripe', 'fluent-cart'));
        }

        return $data;
    }

    public function getEvent($eventId)
    {
        $api = $this->getApi();
        return $api::request([], 'events/' . $eventId, 'GET');
    }

    public function getApi()
    {
        $api = new ApiRequest();
        $api::set_secret_key((new StripeSettingsBase())->getApiKey());
        return $api;
    }

    public function getApiKey($mode = 'current')
    {
        return (new StripeSettingsBase())->getApiKey($mode);
    }

    public function addWebhookEndpoint()
    {
        // get all the webhook endpoints first

    }

    public function getWebhookEndpoints()
    {
        return $this->getStripeObject('webhooks');
    }

    public function getActivatedPaymentMethodsConfigs($mode = 'live')
    {
        $apiKey = (new StripeSettingsBase())->getApiKey($mode);

        if (!$apiKey) {
            return [];
        }

        $clientId = 'ca_TDs9okG0Jy8gY5GWbwmsDWHmIpOlyIoc';
        if ($mode == 'test') {
            $clientId = 'ca_TDs9NGCHtEcklwK4EFKHe72TAxC2kQap';
        }

        $stripeGateways = (new \FluentCart\App\Modules\PaymentMethods\StripeGateway\API\API)->makeRequest('payment_method_configurations', [
            'application' => $clientId,
        ], $apiKey);

        if (is_wp_error($stripeGateways) || empty($stripeGateways['data'])) {
            return [];
        }

        $gateway = Arr::first($stripeGateways['data']);

        $stripeGateways = [
            'acss_debit'        => 'ACSS Debit',
            'affirm'            => 'Affirm',
            'afterpay_clearpay' => 'Afterpay / Clearpay',
            'alipay'            => 'Alipay',
            'amazon_pay'        => 'Amazon Pay',
            'apple_pay'         => 'Apple Pay',
            'bacs_debit'        => 'BACS Debit',
            'bancontact'        => 'Bancontact',
            'blik'              => 'BLIK',
            'card'              => 'Credit/Debit Card',
            'cartes_bancaires'  => 'Cartes Bancaires',
            'cashapp'           => 'Cash App',
            'crypto'            => 'Cryptocurrency',
            'eps'               => 'EPS',
            'giropay'           => 'Giropay',
            'google_pay'        => 'Google Pay',
            'ideal'             => 'iDEAL',
            'kakao_pay'         => 'Kakao Pay',
            'klarna'            => 'Klarna',
            'kr_card'           => 'Korea Card',
            'link'              => 'Link',
            'mb_way'            => 'MB Way',
            'multibanco'        => 'Multibanco',
            'naver_pay'         => 'Naver Pay',
            'p24'               => 'Przelewy24',
            'payco'             => 'Payco',
            'pix'               => 'Pix',
            'samsung_pay'       => 'Samsung Pay',
            'sepa_debit'        => 'SEPA Debit',
            'sofort'            => 'Sofort',
            'us_bank_account'   => 'US Bank Account',
            'wechat_pay'        => 'WeChat Pay',
            'zip'               => 'Zip'
        ];

        $allMethods = Arr::only($gateway, array_keys($stripeGateways));

        $activatedMethods = array_filter($allMethods, function ($method) {
            return !!Arr::get($method, 'available');
        });

        $stripeGateways = Arr::only($stripeGateways, array_keys($activatedMethods));
        $settings = (new StripeSettingsBase())->settings;
        $accountId = Arr::get($settings, $mode . '_account_id');

        $liveMode = !!Arr::get($gateway, 'livemode');

        return [
            'id'                => Arr::get($gateway, 'id'),
            'activated_methods' => $stripeGateways,
            'configure_url'     => 'https://dashboard.stripe.com/' . $accountId . (!$liveMode ? '/test/' : '/') . 'settings/payment_methods/' . Arr::get($gateway, 'id'),
        ];
    }

}

```
