Before the JavaScript SDK can render the checkout iframe, your server must call POST /checkout/preparePurchase to obtain a purchaseId. The purchaseId is a short-lived token that authorises exactly one checkout session.
Minimal request
// Detect the customer's IP address
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$payload = [
'debugMode' => true, // disable in production!
'customerIpAddress' => $ip,
'customerId' => $customer->customerId, // from POST /customers
'items' => [
[
'plenigoOfferId' => 'O_6E487EBURRY35FOD0J',
'quantity' => 1,
],
],
];
$response = json_decode($client->request('POST', '/checkout/preparePurchase', [
'headers' => ['X-plenigo-token' => eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9],
'json' => $payload,
])->getBody()->getContents());
$purchaseId = $response->purchaseId;
Pass $purchaseId to the JavaScript SDK to start the checkout. See Checkout (JavaScript SDK).
Required fields
Field | Description |
|---|---|
| The customer's IP address. Used for geo-restrictions and fraud detection. |
| The Frisbii Media customer ID. Either from |
| The ID of the offer to purchase. Found in the Frisbii Media backend. |
| Number of items. Almost always |
debugMode
Set debugMode: true during development to enable additional debugging output inside the checkout iframe. Always set it to false or remove it in production.
Using a customer session instead of a customerId
If you are using Frisbii Media SSO, you can pass customerSession instead of customerId:
$payload = [
'debugMode' => true,
'customerIpAddress' => $ip,
'customerSession' => $session, // Frisbii Media SSO session token
'items' => [
[
'plenigoOfferId' => 'O_6E487EBURRY35FOD0J',
'quantity' => 1,
],
],
];
Full HTML example
Once you have the purchaseId, render the checkout on your page:
<div id="plenigoCheckout"></div>
<script src="https://static.frisbii-media-stage.com/web/v1/frisbii_media.min.js"
data-company-id="{YourCompanyId}"
data-lang="en"></script>
<script>
new plenigo.Checkout("<?php echo $purchaseId; ?>", { elementId: "plenigoCheckout" }).start();
document.addEventListener("plenigo.PurchaseSuccess", function(e) {
console.info("Event:", e.type, e.detail);
// orderId is -1 if the customer already owns the product
location.href = location.pathname + "?" + e.orderId;
});
document.addEventListener("plenigo.WebAnalyticsLoad", function(e) {
console.group("ANALYTICS");
console.info("Event:", e);
console.groupEnd();
});
</script>