Skip to main content

Replace your native checkout page with Simpler Checkout

You can use Simpler Checkout as the main checkout page for your eShop. All you need to do is build the Simpler URL and redirect the user to it when they click the Proceed to checkout button in the cart.


How to Generate the Redirect URL for Checkout

URL Structure

The generated URL should follow this format:

https://checkout.simpler.so/?app=<APP_ID>&prd=<ENCODED_PRODUCT_DATA>&cur=<CURRENCY>&lang=<LANGUAGE>

URL Parameters

  1. app: Your APP_ID.
  2. prd: URL-encoded JSON containing:
    • id: Product ID.
    • qty: Product quantity.
    • attrs: Attributes for variations (optional).
  3. cur: The currency in ISO format (e.g. EUR, USD, GBP).
  4. lang: The user's language in ISO format (e.g. en, el, fr).

Custom PHP Implementation

Function

function build_checkout_url($cart, $app_id, $endpoint = 'https://checkout.simpler.so/') {
$url = '';

try {
// Check if the cart is valid
if (!$cart || empty($cart['items'])) {
throw new Exception('Cart is empty or not available.');
}

// Initialize product array
$products_array = [];

// Iterate through cart items
foreach ($cart['items'] as $item) {
$product_data = [
'id' => (string)$item['id'], // Product ID
'qty' => (string)$item['quantity'], // Quantity
];

// Add variation attributes if available
if (!empty($item['attributes'])) {
$attrs = new stdClass();
foreach ($item['attributes'] as $key => $value) {
$attrs->{$key} = (string)$value;
}
$product_data['attrs'] = $attrs;
}

// Add product data to array
$products_array[] = $product_data;
}

// Encode product data as JSON and then URL-encode it
$products_string = urlencode(json_encode($products_array));

// Set currency and language
$currency_iso = 'EUR'; // Replace with a dynamic function if needed
$language_iso = 'en'; // Replace with a dynamic function if needed

// Build the final URL
$url = $endpoint .
'?app=' . $app_id .
'&prd=' . $products_string .
'&cur=' . $currency_iso .
'&lang=' . $language_iso ;

} catch (Exception $e) {
error_log('Error generating checkout URL: ' . $e->getMessage());
}

return $url;
}

Usage Example

$cart = [
'items' => [
[
'id' => 123,
'quantity' => 1,
'attributes' => [
'color' => 'blue',
'size' => 'L'
]
],
[
'id' => 456,
'quantity' => 2,
'attributes' => []
]
]
];

$app_id = '550e8400-e29b-41d4-a716-446655440000'; // Replace with your actual APP_ID
$checkout_url = build_checkout_url($cart, $app_id);

echo "Redirect to: " . $checkout_url;

Final Encoded Output Example

For the given $cart and $app_id, the function will return:

https://checkout.simpler.so/?app=550e8400-e29b-41d4-a716-446655440000&prd=%5B%7B%22id%22%3A%22123%22%2C%22qty%22%3A%221%22%2C%22attrs%22%3A%7B%22color%22%3A%22blue%22%2C%22size%22%3A%22L%22%7D%7D%2C%7B%22id%22%3A%22456%22%2C%22qty%22%3A%222%22%7D%5D&cur=EUR&lang=en

By implementing this function, you can seamlessly redirect users to Simpler Checkout with dynamically generated cart data.