1. Go to this page and download the library: Download botmetria/ucp 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/ */
botmetria / ucp example snippets
use Botmetria\Ucp\Ucp;
use Botmetria\Ucp\ArrayProductProvider;
$ucp = new Ucp([
'store_name' => 'My Shop',
'store_url' => 'https://my-shop.com/',
'currency' => 'EUR',
'country' => 'MD',
'products' => new ArrayProductProvider($myItems), // or your own provider
// 'cart' => new MyCartProvider(), // optional: enables agent checkout
]);
$ucp->run(); // serves /.well-known/ucp and /ucp/v1/*; otherwise returns control
use Botmetria\Ucp\ProductProviderInterface;
use Botmetria\Ucp\CartProviderInterface;
final class MyProducts implements ProductProviderInterface
{
public function list(int $offset, int $limit, string $query = '', string $category = ''): array
{
// return canonical item arrays: id, name, url, price, currency (+optional
// description, sku, gtin, brand, category[], availability, images[]...)
}
public function get(string $id): ?array { /* one item or null */ }
}
final class MyCart implements CartProviderInterface
{
public function fill(array $items): string
{
foreach ($items as $item) {
$this->cart->add($item['id'], $item['quantity']); // your platform's cart
}
return '/checkout'; // where to send the shopper
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.