# Licensing seam (Freemius-ready, stubbed)

This directory defines the **licensing seam** for
**Business Central Connector**. It is a deliberately thin abstraction that
lets a future **Pro / Freemius add-on** introduce paid plans **without changing
this free, GPL repository**.

> **No paid gating lives here.** This repo is the free, GPL, WordPress.org-ready
> plugin. The default gateway reports the `free` plan and grants nothing. The
> Freemius SDK is **intentionally NOT bundled** in this repository (it is not
> GPL-compatible to ship in this free repo).

---

## The contract: `Licensing`

`Synfynal\BusinessCentralConnector\Contracts\Licensing` is the interface the rest of the plugin
depends on. Code that needs to know "is this allowed?" asks the gateway — it
never talks to Freemius (or any vendor) directly. A representative shape:

```php
namespace Synfynal\BusinessCentralConnector\Contracts;

interface Licensing {
    /** Machine-readable plan slug, e.g. "free". */
    public function plan(): string;

    /** Whether a named capability/feature is granted. */
    public function can( string $feature ): bool;

    /** Whether any paid plan is currently active. */
    public function is_pro(): bool;
}
```

## The default: `NullLicensing`

`Synfynal\BusinessCentralConnector\Licensing\NullLicensing` is the no-op implementation shipped in
this repo. It is the **Null Object** for the seam:

- `plan()` returns `"free"`.
- `can( $feature )` returns `false` for everything (grants nothing).
- `is_pro()` returns `false`.

Because every feature check funnels through this object, the free plugin behaves
correctly and safely on its own, with no licensing vendor present.

## How the gateway is resolved

`Plugin::instance()->boot()` resolves the active licensing gateway during boot.
It starts from `NullLicensing` and passes it through the **`bccentralconnector_licensing`**
filter so that an add-on can swap in a real implementation:

```php
// Inside Plugin::boot() (illustrative):
$licensing = apply_filters( 'bccentralconnector_licensing', new \Synfynal\BusinessCentralConnector\Licensing\NullLicensing() );
```

If no add-on is installed, the filter returns `NullLicensing` unchanged and
nothing is gated.

---

## Where a Pro add-on plugs in

A separate **Pro add-on plugin** (its own repository, where the Freemius SDK
*may* be bundled) initializes Freemius and replaces the gateway via the
`bccentralconnector_licensing` filter. The snippet below shows **where** that happens — it
is documentation only; **none of this code exists in this free repo.**

```php
<?php
/**
 * EXAMPLE — lives in the SEPARATE Pro add-on plugin, NOT in this free repo.
 *
 * The Pro add-on bundles the Freemius SDK and swaps the licensing gateway in
 * via the 'bccentralconnector_licensing' filter. The free plugin keeps using NullLicensing
 * until (and unless) such an add-on is active.
 */

// 1. Initialize the Freemius SDK. The SDK file is bundled in the ADD-ON,
//    never in the free plugin. (Pseudocode require for illustration.)
require_once __DIR__ . '/vendor/freemius/start.php'; // add-on only

$bccentralconnector_fs = fs_dynamic_init( [
    'id'         => '0000',                 // Freemius product id
    'slug'       => 'businesscentralconnector-pro',
    'type'       => 'plugin',
    'public_key' => 'pk_xxxxxxxxxxxxxxxx',
    'is_premium' => true,
    'menu'       => [ 'slug' => 'bccentralconnector-pro' ],
] );

// 2. Swap the gateway. The add-on provides a Licensing implementation backed by
//    Freemius and returns it from the filter, replacing NullLicensing.
add_filter( 'bccentralconnector_licensing', static function ( $current ) use ( $bccentralconnector_fs ) {
    // FreemiusLicensing implements Synfynal\BusinessCentralConnector\Contracts\Licensing and answers
    // plan()/can()/is_pro() using $bccentralconnector_fs (the Freemius instance).
    return new \Synfynal\BusinessCentralConnectorPro\Licensing\FreemiusLicensing( $bccentralconnector_fs );
} );

// 3. From here on, the free plugin's feature checks ($licensing->can('...'))
//    transparently consult Freemius — with zero changes to this free repo.
```

### Why it is split this way

- **GPL hygiene.** The free repo stays 100% GPL-compatible and WordPress.org
  shippable; the proprietary SDK is quarantined in the add-on.
- **One swap point.** All gating decisions route through `Licensing`, so adding
  Pro is a single filter, not a scatter of conditionals.
- **Safe default.** With no add-on, `NullLicensing` guarantees the free plugin
  is fully functional and never accidentally locks a feature.

> **Hard rules:** never bundle the Freemius SDK in this repository, never add
> paid-gated code here, and keep every dependency GPL-compatible.
