Documentation Index

Fetch the complete documentation index at: https://help.frisbii.com/llms.txt

Use this file to discover all available pages before exploring further.

Associating a Purchase with a Customer

Prev Next

After the platform store purchase has been validated and an inAppToken returned, the purchase exists in Frisbii Media as an anonymous record. It must be linked to a customer account before it appears in the customer's subscription history and becomes valid on other platforms.


When to associate

Associate as soon as the user is identified — either immediately after purchase (if already logged in) or after the user completes login or registration.

If the user is not yet logged in at the time of purchase:

  1. Store the inAppToken on the device (or in your session)

  2. Start a Frisbii Media login or registration flow (see SSO: Login & Registration)

  3. Once the LoginSuccess event fires and you have a customerSession, call associate


The associate endpoint

/**
 * @Route("/inapp/associate", name="InAppAssociate", methods={"POST"})
 */
public function associateInAppPurchase(Request $request): Response
{
    $content = json_decode($request->getContent(), true);
    // customerSession comes from the plenigo.LoginSuccess event on the frontend
    // inAppToken was returned when the purchase was added (steps 3–5 in the process flow)
    // @see https://api.frisbii-media.com/#tag/App-Stores/operation/associateAppStorePurchase
    $response = json_decode($client->request('POST', '/appstores/purchases/associate', [
        'headers' => ['X-plenigo-token' => eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9],
        'json'    => [
            'customerSession' => $content['customerSession'],
            'inAppToken'      => $content['inAppToken'],
        ],
    ])->getBody()->getContents(), true);
    return new JsonResponse($response);
}

After a successful associate call:

  • The purchase is linked to the customer's Frisbii Media account

  • The subscription and access rights are visible in the customer's self-service portal

  • The customer can use their subscription on all platforms (web, other apps) using their Frisbii Media login


Full login + associate flow (example)

This example shows how to tie the login and associate steps together in a single page:

<div id="plenigoLogin"></div>
<script src="https://static.frisbii-media-stage.com/web/v1/frisbii_media.min.js"
        data-company-id="{your_companyId}"
        data-lang="en"></script>
<script>
    // inAppToken was stored after the purchase was added (e.g. passed via query param or localStorage)
    var inAppToken = getInAppTokenFromStorage();
    document.addEventListener("plenigo.LoginSuccess", function(e) {
        if (e.type !== "plenigo.LoginSuccess") return false;
        var customerSession = e.detail.customerSession;
        // Send both tokens to your backend to associate the purchase
        fetch('/inapp/associate', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
                customerSession: customerSession,
                inAppToken: inAppToken
            })
        }).then(function(response) {
            return response.json();
        }).then(function(data) {
            // Association complete — redirect or show success
            location.href = '/account/subscriptions/';
        });
    });
    new plenigo.SSO({ elementId: "plenigoLogin" }).login();
</script>

What if the user already has an account?

If the user is already logged in when they make the in-app purchase, skip the login step entirely and call associate directly with the existing customerSession:

$response = json_decode($client->request('POST', '/appstores/purchases/associate', [
    'headers' => ['X-plenigo-token' => eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9],
    'json'    => [
        'customerSession' => $existingSession,
        'inAppToken'      => $inAppToken,
    ],
])->getBody()->getContents(), true);

What if the user never logs in?

If the user never logs in, the purchase remains anonymous in Frisbii Media. The inAppToken can still be used to check access on that specific device via the Frisbii Media API. However, the purchase will not appear in any customer account, and the user will lose access if they reinstall the app or switch devices.

Encourage users to create an account to protect their purchase.


API reference