1. Go to this page and download the library: Download astral-php/astral-shipping library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use AstralShipping\Models\{Address, ShippingContext};
use AstralShipping\Service\ShippingService;
// 1. Contexte : montants en CENTIMES, poids en GRAMMES
$context = new ShippingContext(
subtotalCents: 4990,
weightGrams: 1200,
destination: new Address('FR', '75001', 'Paris'),
);
// 2. Lister les offres (triées par prix)
$quotes = $shipping->quotes($context);
// 3. Valider le choix du client — le prix est TOUJOURS recalculé côté serveur
$selection = $shipping->select($context, $_POST['shipping_method'], $_POST['pickup_point_id'] ?? null, $_POST['pickup_point_label'] ?? null);
// 4. Total à encaisser (→ astral-payment)
$total = $shipping->total($context->subtotalCents, $selection);
// 5. À la création de la commande : snapshot
$shipmentDao->record($orderId, $selection);